Jump to content

Resize Image


Recommended Posts

  • 6 months later...

I needed a workflow to handle multiple images so I modified this one to do just that. Hope you don't mind. My code below:

on alfred_script(target_width)
  
  set theCount to 0
  set currSelection to {}

  tell application "Finder"
    set theSelection to selection
  end tell
    
  repeat with this_file in theSelection
    -- try to get a jpg or png
    try
      tell application "Finder"
        set myPath to POSIX path of (this_file as text)
      end tell
    
      tell application "Image Events"
        -- open the image file
        set this_image to open myPath
        -- get dimensions of the image
        copy dimensions of this_image to {W, H}
        -- calculate scale factor with given width and scale the image
        set scale_factor to target_width / W
        scale this_image by factor scale_factor
        save this_image in myPath
        close this_image
        -- get new image width and height for output
        set new_W to round (W * scale_factor) rounding as taught in school
        set new_H to round (H * scale_factor) rounding as taught in school
        set new_size to new_W & " x " & new_H
      end tell
        -- set the_return to (W & " x " & H & " → " & new_size) as text
        -- return the_return
        set theCount to theCount + 1
    on error errStr number errorNumber
      return "No image file found!"
    end try
  end repeat
  return ("Processed " & theCount & " images") as text
end alfred_script
Link to comment
  • 2 weeks later...
  • 4 weeks later...

Yes it works with very 3.

The original images will be overwritten with the resized version.

 

I'm trying to use this workflow, but it doesn't make any output. 

Could you let me know how to figure out the problem?

My environment is El Capitan 10.11.5 and Alfred 3.0.3.

Link to comment
  • 1 month later...
  • 5 months later...

Use this workflow frequently but has one problem, when I batch them it gets stuck sometimes and says "No Image found" then I have to open image manually and resize it before I am able to continue, keeps happening, like its getting stuck somewhere, would love to figure this out as its such a insanely helpful thing to have!

Link to comment

 Can you tell me but more when it fails?

- How many items in batch?

- any specific Filename pattern when it breaks ?

- any specific image format?

 

can you provide me with a zip containing batch items?

Edited by Acidham
Link to comment

It doesnt seem to matter, I tried big batches, small batches it eventually fails. Once I open Preview and do a manual image resize it seems to reset, then I can do a few more and it happens again. The files are all .jpg, with a naming structure from the camera. I will try some other files and see if it has anything to do with naming and let you know

Link to comment

I was able to fix a bug where last file in the list was not processed due to a newline added by Alfred.

In addition I added a file action which allows to choose files within Alfred and process with Resize Images. 

 

Version 1.1 is available on packal.org.

 

@ixium please test the new version an let me know if your issue is fixed. 

 

Link to comment

Ok just updated to 1.2, please install new version from packal.org

 

Note: There are two ways on how to trigger Resize Image:

1. Select one or more files in Finder, open Alfred and type rimage plus target width

2. Search png or jpg via Alfred and use File Action Resize Image

Link to comment

I am not using FL3 but get selection only works in Finder. You have to use Alfred for collecting images and use file action command.

 

Does FL3 support any scripts or action command from AppleScript or Bash? If yes I could take a look on how to enhance my WF.

Link to comment

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...