Created
November 17, 2016 00:57
-
-
Save andergmartins/922cc125145a615f9eb56cc5312af687 to your computer and use it in GitHub Desktop.
Resize files to multiple sizes and move to folders with the same name of the source file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set image_ext_list to {"jpg", "jpeg", "png"} | |
set size_list to {"64", "48", "32", "24", "16"} | |
set source_path to (choose folder "Select the folder with the base images" without invisbles) as text | |
set dest_path to (choose folder "Select the destination folder" without invisbles) as text | |
with timeout of 86400 seconds | |
tell application "Finder" | |
set image_files to (files of entire contents of (source_path as alias) whose name extension is in image_ext_list) as alias list | |
end tell | |
end timeout | |
set the target_length to 1080 | |
repeat with image_file in image_files | |
with timeout of 86400 seconds | |
tell application "Image Events" | |
-- start the Image Events application | |
launch | |
-- open the image file | |
set this_image to open image_file | |
set this_file_name to name of this_image as text | |
-- Remove the extension from file name | |
if this_file_name contains "." then set this_file_name to (text items 1 thru -5 of this_file_name) as text | |
repeat with new_size in size_list | |
set new_file_name to (this_file_name & "_" & new_size & ".png") as text | |
set new_file_name_path to (dest_path & this_file_name & ":" & new_file_name) as text | |
-- Check if the new file already exists and remove it | |
-- if exists new_file_name_path then | |
-- move new_file_name_path to trash | |
-- end if | |
scale this_image to size new_size | |
save this_image in new_file_name_path with icon | |
end repeat | |
-- purge the open image data | |
close this_image | |
end tell | |
end timeout | |
end repeat | |
display dialog "Finished" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment