Jump to content

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

     

 

 

Link to comment
  • 8 months later...

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
Link to comment
  • 1 year later...
  • 2 months later...
On 11/7/2019 at 11:59 AM, naymapl said:

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.

 

I get the same issue. Any suggestions?

Link to comment

Seems to be an issue with Image Events under Catalina: https://forums.developer.apple.com/thread/124420

To fix there is a simple solution: https://darjeelingsteve.com/articles/Fixing-"Image-Events"-AppleScripts-Broken-in-macOS-10.15-Catalina.html

 

Quote

These problems appear to be caused by Image Events not having Full Disk Access permissions. Fortunately it's an easy fix.

 

First, launch System Preferences and navigate to the Security and Privacy pane. Click the Privacy tab, scroll down the menu on the left, and click on Full Disk Access. Click the + icon in the right hand box, and navigate to System > Library > Core Services. Select Image Events, and click the Open button.

 

Link to comment
  • 7 months later...
On 1/11/2020 at 10:25 AM, Acidham said:

Great! Thank you very much! Works! 👍

This should be added to the description of the workflow to make it work!

Link to comment
  • 1 month later...
On 1/11/2020 at 5:25 PM, Acidham said:

Can't find the core services folder and image event (System > Library > Core Services) in the latest macOS system (10.15.7), is there any new solution? I rely on this workflow a lot, please help… 😭🙏 Thanks very very very much!

 

1603184173187.jpg

Edited by jen
attach image
Link to comment
1 hour ago, jen said:

Can't find the core services folder and image event (System > Library > Core Services) in the latest macOS system (10.15.7), is there any new solution? I rely on this workflow a lot, please help… 😭🙏 Thanks very very very much!

 

It is there! But why are you looking up for ImageEvents.app in Alfred!? 

 

You need to add it to System Preferences → Full Disk Access and click on the + to add it. With this Finder will open

Link to comment
  • 2 weeks later...
2 hours ago, swiggy said:

 

Hi does this workflow only work with the same height and width? for example 1080 x 1080? How can change it 1080 x 580 for example?

 


Your usecase describes cropping but the workflow was build to resize an image. Therefore the answer to your question is no.

 

please also read the usage Description:

 

Usage

Select an image in Finder, open Alfred and enter rimage and enter a value for the target width, e.g. rimage 300. The image will be resized to target width by respecting ratio. Works with .jpg and .png.

Link to comment
  • 1 month later...
  • 1 year later...
50 minutes ago, Le Tien said:

Not working on Big Sur m1

 

Please be more specific rather than simply saying "not working" 

 

* What you were doing when the issue happened
* Whether you were able to replicate it a second time by performing the same action
* Include any screenshots that might help us

* For a workflow, check the workflow debugger for any error messages that could be helpful
* Include the Alfred version & build number you are using (don't say "latest" - you'll find a version number in the Update tab of Alfred's preferences)
* Include your macOS version
 
The clearer the issue report, the more likely and easily we'll be able to help you resolve it. :)
 

Link to comment
  • 3 weeks later...
On 1/11/2020 at 1:25 AM, Acidham said:

 

I'm running Monterey 12.2 and this fix worked for me. Thanks @Acidham, for making this script, I find it very useful! You could probably even update the compatibility matrix on Packal as I can confirm it works in every version up through Monterey, and maybe add the fix in the Usage section for people downloading it the first time so they're not scratching their heads as to why it's not working.

Edited by stylophile
Link to comment
14 hours ago, Acidham said:

For me, it looks like that packal is not being maintained anymore


Correct. It hasn’t been maintained for a while despite staying up. The official place to share Workflows is this forum. Nonetheless, the effect of Packal was large enough that it continues to be used and get submissions, despite features breaking.

Link to comment
  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...