-- save in Script Editor as Application
-- drag files to its icon in Finder
on open some_items
tell application "Finder"
if (exists folder "output") then
else
make new folder with properties {name:"output"}
end if
end tell
repeat with this_item in some_items
try
onex(this_item)
twox(this_item)
end try
end repeat
end open
to onex(this_item)
tell application "Image Events"
launch
set the target_width to 648
-- open the image file
set this_image to open this_item
set typ to this_image's file type
copy dimensions of this_image to {current_width, current_height}
if current_width is greater than current_height then
scale this_image to size target_width
else
-- figure out new height
-- y2 = (y1 * x2) / x1
set the new_height to (current_height * target_width) / current_width
scale this_image to size new_height
end if
-- change file name
set _filename to name of this_item
set _extension to name extension of this_item
if _extension is not "" then
set _length to (count of _filename) - (count of _extension) - 1
set _newname to text 1 thru _length of _filename
end if
tell application "Finder" to set new_item to ¬
(folder "output" as string) & _newname & "." & _extension
save this_image in new_item as typ
end tell
end onex
to twox(this_item)
tell application "Image Events"
launch
set the target_width to 1296
-- open the image file
set this_image to open this_item
set typ to this_image's file type
copy dimensions of this_image to {current_width, current_height}
if current_width is greater than current_height then
scale this_image to size target_width
else
-- figure out new height
-- y2 = (y1 * x2) / x1
set the new_height to (current_height * target_width) / current_width
scale this_image to size new_height
end if
-- change file name
set _filename to name of this_item
set _extension to name extension of this_item
if _extension is not "" then
set _length to (count of _filename) - (count of _extension) - 1
set _newname to text 1 thru _length of _filename
end if
tell application "Finder" to set new_item to ¬
(folder "output" as string) & _newname & "_2x." & _extension
save this_image in new_item as typ
end tell
end twox