Jump to content
Acidham

Resize Image

Recommended Posts

For anybody who wants the image file to save as a new file rather than replace the original:

  1. Open the "Process image(s)" AppleScript block in the workflow
  2. Find this line in the script:
  3. save this_image in myPath

    And insert the following to append the image filename with the target width (e.g. image.png becomes image-300.png when resized to 300px width):

    				-- append target width to file name
    				set oldDelim to AppleScript's text item delimiters
    				set AppleScript's text item delimiters to {"."}
    				set theExt to last text item of myPath
    				set AppleScript's text item delimiters to {"." & theExt}
    				set file_path_list to every text item of myPath
    				set AppleScript's text item delimiters to {"-" & target_width & "." & theExt}
    				set myPath to the file_path_list as string
    				set AppleScript's text item delimiters to oldDelim

     

 

 

Share this post


Link to post

I needed a workflow that put the resized images into a sub folder of the originals, so made the following amendments.

It can handle multiple file selections within differing directories and place the resize-x folder within the respective directory relative to the original image.

  1. Open the "Process image(s)" AppleScript block in the workflow
  2. Find the following lines in the downloadable version (Lines 27-28)
    			set myPath to this_file
    		end if

    And insert the following after it that will create a new directory next to the file being resized in the format of 'resize-{resize-width}' (resize-500, resize-1024 for example)

            -- Remove the file name from the end of the path string
            set filePath to characters 1 thru -((offset of "/" in (reverse of items of myPath as string)) + 1) of myPath as text
            set fileName to name of (info for myPath)
            -- Create a full path to the folder that we want.
            set resizeFolderName to ((filePath as text) & "/resize-" & (target_width as text) & "/") as text
    
            -- Check for the resize-x folder and create it if not present
            if folderExists(resizeFolderName) then
    			set outputFolder to resizeFolderName
            else
    			set createThisFolder to POSIX file filePath as alias
    
                tell application "Finder" to make new folder in createThisFolder with properties {name:"resize-" & target_width}
    			set outputFolder to resizeFolderName
            end if

     

  3. Change the following line (Originally on line 38, with the addition of the above, its now on line 60)
     

    save this_image in myPath

    to
     

    save this_image in outputFolder & fileName

     

  4. Add the following function to the end of the file:
     

    on folderExists(theFolder)
        tell application "Finder"
            try
                set thisFolder to the POSIX path of theFolder
                set thisFolder to (POSIX file thisFolder) as text
                -- set thisFolder to theFolder as alias
                return true
            on error err
                return false
            end try
        end tell
    end folderExists

     

Or, if you want the whole script in one thing, its on a Gist here: https://gist.github.com/danstreeter/23fe01074034832fec09c0b633522559

Edited by MrStreeter
Correct Gist link

Share this post


Link to post

Hi - this workflow working perfect with macos 10.14 but stop working on Catalina 10.15. I got always error ( can't get item 1 of {} )- anybody have any idea what is wrong ? Thnaks for any sugestions.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...