Tuesday, December 10, 2019

#1 2019-11-20 06:27:34 pm

LLaBonte1
Member
From:: Beaverton, OR
Registered: 2019-11-19
Posts: 2

Adding Counting Integers to Photoshop PNG Files

I'm new to Applescript and I'm trying to write a script for Photoshop that will move the base layer of a layer mask to create high resolution PNG files of the mask with different fills.  There is actually two questions I have:

1. The PNG files I'm getting are 72 dpi but I want them to be 300 dpi

2. I haven't created a loop yet but when I run the script twice the new file just overwrites the old file.  When I add the loop, I would like the script to identify the file name and either add an integer prefix like 0000_XXX_XXX.png or XXX_XXX_0000.png so I can easily save then unique fills with a variable amount of integers in the file name to the destination.  I've tried a few scripts that I found on this site and others without success, it just keeps overwriting the original file.

here is what I have:

tell application "Adobe Photoshop 2020"
    tell current document
        set selectedLayer to "Layer 1"
        translate layer 1 delta x -0.11
    end tell
end tell
process_item("Macintosh HD:Users:llabon:desktop:Woodland_Camo_Outputs:Faded_Camo_Clipping_Mask.png")
on process_item(this_item)
    set thePath to this_item as string
    tell application "Adobe Photoshop 2020"
        set theDocument to current document
        export theDocument in thePath as save for web with options {class:save for web export options, web format:PNG, quality:300}
    end tell
end process_item

Any help would be appreciated!

Thank you in advance,
Louie


Filed under: photoshop, Export, png, File Names

Offline

 

#2 2019-11-21 09:47:01 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 768

Re: Adding Counting Integers to Photoshop PNG Files

I have not "Adobe Photoshop 2020" to test the following script. So, try yourself:

Applescript:


property aDesktop: (path to desktop folder) as string
property templateName: aDesktop & "Woodland_Camo_Outputs:Faded_Camo_Clipping_Mask"
property aNameNumber: 0

tell application "Adobe Photoshop 2020" to tell current document
set selectedLayer to "Layer 1"
translate layer 1 delta x -0.11
end tell

tell application "Finder"
repeat
set aNameNumber to aNameNumber + 1
set aNumString to formatNumber(aNumber) of me
set filePath to templateName & "_" & aNumString & ".png"
if Not (exists file filePath) then exit repeat
end repeat
end

process_item(filePath) of me

--------------------------------------------------------------------------------------

on process_item(aPath)
tell application "Adobe Photoshop 2020"
set theDocument to current document
export theDocument in aPath as save for web with options {class:save for web export options, web format:PNG, quality:300}
end tell
end process_item

on formatNumber(aNumber)
   set aNum to aNumber as string
   if aNumber < 1000 then set aNum to "0" & aNum
   if aNumber < 100 then set aNum to "0" & aNum
   if aNumber < 10 then set aNum to "0" & aNum
end formatNumber

Last edited by KniazidisR (2019-11-21 10:32:39 am)


Model: MacBook Pro
macOS Mojave -- version 10.14.4
Safari -- version 12.1
Firefox -- version 70.0

Offline

 

#3 2019-11-21 10:42:04 am

LLaBonte1
Member
From:: Beaverton, OR
Registered: 2019-11-19
Posts: 2

Re: Adding Counting Integers to Photoshop PNG Files

Thank you for the reply KniazidisR, I will give that a try.

Offline

 

#4 2019-11-21 06:24:00 pm

Marc Anthony
Member
From:: Dallas, TX
Registered: 2006-04-27
Posts: 910

Re: Adding Counting Integers to Photoshop PNG Files

Hi. There are fundamental misunderstandings. The "quality" property isn't equivalent to PPI; that value is a compression indicator that only goes up to 100 and has no applicability to PNG files. Images exported under the 'save for web' scheme will always be 72dpi, because that's the function's expected behavior. You can export at that effective size (with quality degradation).


Applescript:

tell application "Finder" to set theFiles to (choose folder)'s files as alias list --files for processing (in a folder that's not the save location)
set saveLocus to (path to desktop as text)

tell application "Adobe Photoshop CS3" to repeat with Counter from 1 to count theFiles
   open (theFiles's item Counter)
   tell document 1
       resize image resolution 300 resample method bicubic
       export it in file ((saveLocus) & ((get name) & Counter)) as save for web with options {web format:PNG} with replacing
       close without saving
   end tell
end repeat

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)