I have a droplet app created in AppleScript (code below) that will accept various image formats (either dropped onto it or via a dialog box) and spit out PNGs resized to a user-defined max pixel dimension. It is lightning fast compared to Photoshop batch processing.
Looking for some help with the (3) limitations outlined below. (My preference is to do this via scripting/commands native to MacOS; in other words, without having to install ImageMagick.)
LIMITATIONS:
Alpha Channels & Transparencies. Is there a way to discard all Alpha Channels?
If possible, would be nice if there was an option to keep transparency if present/desired. If it needs to be discarded to work, would like a WHITE background as opposed to BLACK.
The PHP code offered here by @MarkSetchell may be part of my solution, though am not advanced enough to know how to add to the code below.*
Spot Channels. Is there a way to convert/merge the Spot Channels into RGB? (A Spot Channel is a special color, for example Pantone 072 Blue, that is added to extend the gamut of the image. For these purposes, would like it merged to get a general representation in RGB.)
Crop to Edge Pixels. Would like to add a feature that could crop the image to the image edge pixels (as oppsoed to canvas), if desired, preferrably before resizing to the max dimension provied by the user.
CURRENT APPLESCRIPT CODE:
property extension_list : {"tif", "tiff", "png", "jpeg", "jpg", "pict", "psb", "pdf", "bmp", "eps", "psd", "heic"}
global current_folder
global pixel_size
--___________________________________________________________________________ drag and drop
on open these_items
log "open"
log these_items
try
tell application "Finder"
set maxpixel_size to display dialog "Enter desired maximum pixel dimension below." default answer "600" buttons {"Cancel", "Continue"} default button "Continue" with icon note
set pixel_size to (text returned of the result)
end tell
process(these_items, pixel_size)
delay 2
display notification with title "Image Conversions Complete"
on error error_message
tell me to "exit"
end try
end open
--___________________________________________________________________________ files
on process(these_items, pixel_size)
initialise()
log "process " & these_items
repeat with i from 1 to the count of these_items
set this_item to (item i of these_items)
set the item_info to info for this_item
if (alias of the item_info is false) and ¬
(the name extension of the item_info is in the extension_list) then
process_item(this_item, pixel_size)
end if
end repeat
finalise()
end process
--___________________________________________________________________________ folder
on process_folder(this_folder, pixel_size)
initialise()
set current_folder to this_folder
log "process_folder " & this_folder
set these_items to list folder this_folder without invisibles
repeat with i from 1 to the count of these_items
set this_item to alias ((this_folder as text) & (item i of these_items))
set the item_info to info for this_item
if (alias of the item_info is false) and ¬
(the name extension of the item_info is in the extension_list) then
process_item(this_item, pixel_size)
end if
end repeat
finalise()
end process_folder
on initialise()
log "initialise"
end initialise
on finalise()
log "finalise"
end finalise
--___________________________________________________________________________ sips process
on process_item(item_alias, pixel_size)
log "process_item: " & item_alias
set this_path to (item_alias) as string
set the newPNG_name to my add_extension(item_alias, "png")
try
set the_command to "sips --setProperty format png --resampleHeightWidthMax " & pixel_size & " " & quoted form of POSIX path of item_alias & " --out " & quoted form of newPNG_name
log "the_command: " & the_command
do shell script the_command
on error error_message
display dialog error_message
end try
end process_item
--____________________________________________________________________________ default behavior
try
tell application "Finder"
set the source_folder to choose folder with prompt ¬
"Pick a folder to process:"
set maxpixel_size to display dialog "What is the maximum pixel size?" default answer "600" buttons {"Continue"} default button "Continue" with icon note
set pixel_size to (text returned of the result)
end tell
process_folder(source_folder, pixel_size)
delay 2
display notification with title "Image Conversions Complete"
on error error_message
tell me to "exit"
end try
--________________________________________________________________________________ file ext
on add_extension(item_alias, new_extension)
log "add_extension"
log item_alias
set this_info to the info for item_alias
--set this_name to the name of this_info
--set this_name to (item_alias) as string
set this_name to POSIX path of item_alias
set this_extension to the name extension of this_info
if this_extension is missing value then
set the default_name to this_name
else
set the default_name to text 1 thru -((length of this_extension) + 2) of this_name
end if
return (the default_name & "." & the new_extension)
end add_extension
Any help with any of the (3) limitations above would be amazing!
Essentially what I'm looking for is a preview of the image as if it were opened in Photoshop, Illustrator, InDesign, etc. (MacOS Finder Preview doesn't preview properly either.)
Link below takes you to reference files... the original PSD with an Alpha Channel, Spot Channel, and transparency, along with 3 PNG examples that would be the desired output... one is at the same size, the other trimmed to the outermost pixels, and the other padded 10px around the image edges.
To do this in Photoshop, process is convert to RGB (especially if in CMYK for larger gamut), merge spot channels, discard Alpha Channels, trim all sides (optional), save as PNG. This "quick" method of merging the spots doesn't maintain transparencies. The script above takes care of the rest, aside from padding back a border, if desired.
- Original_Spot_Alpha.tif
- Out_flat_trim_pad.png
- Out_flat_trim.png
- Out_flat.png