The size must be set by the size of the “clipping-path-box” (or however you call the outer boundaries of a clipping path) and then I need three versions in different scaled sizes with different names.
Unfortunately the name of the clipping path is not the same in every image. So what I need is an AppleScript which:
creates a selection of the clipping path
inverts the selection and deletes the “background”
crops the image around the clipping path
resize the picture to fit into a 640 x 480 pixels
saves the image with the addition _prev
resizes the image to be exactly 100 x 100 pixels (including an expansion of the canvas)
and finaly saves this image with an added _thumb
… hmm … sounds quite easy for someone who uses a mouse and repeats all the steps manually … can anyone please give me at least a hint for the basic commands ?
The script I have below does what I think you want. See the comments for details. For the sake on the sample script, I assumed you wanted to save the prev and thumb files to the same location as the original, an as the same file type. You can change those parts as you wish.
tell application "Adobe Photoshop CS"
set background color to {class:RGB color, red:255.0, green:255.0, blue:255.0} --Ensures the the canvas will fill with white later in the script
tell current document
set docPath to file path as string --Sets filename and location as string variable
tell path item 1 to create selection --Make selection from path. This assumes there will only be one path in each file (name of the path is irrelevant)
invert selection
fill selection with contents {class:RGB color, red:255.0, green:255.0, blue:255.0} --Fills with white
deselect
trim basing trim on top left pixel --trims extra white space, resulting in the image being cropped to the exact size of the path
--Resizes to 640x480, depending on whether height or width is larger:
if height > width then
resize image height pixels 640
else
resize image width pixels 480
end if
save in (docPath & "_prev") --saves to same location with "_prev" added to name; insert other save options if you wish
--Resizes to 100 pixels; adjusts canvas as needed (resulting in a 100 px square image, regardless of orientation):
if height > width then
resize image height pixels 100
resize canvas width pixels 100
else
resize image width pixels 100
resize canvas height pixels 100
end if
save in (docPath & "_thumb") --saves to same location with "_thumb" added to name; insert other save options if you wish
end tell
end tell