Jump to content
Acidham

Resize Image

Recommended Posts

Resize an image, selected in Finder, to a target width by respecting image ratio. 

 

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.

http://t.cn/R42PAI2

Share this post


Link to post

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

Share this post


Link to post

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.

Share this post


Link to post

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!

Share this post


Link to post

 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

Share this post


Link to post

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

Share this post


Link to post

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. 

 

Share this post


Link to post

ok that worked flawlessly with finder select, but it also didnt tell me it did anything (no pop up) thats no problem with me as long as it works!

Share this post


Link to post

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

Share this post


Link to post

Ok both ways work flawlessly now! All images resized with both ways and both kicked out the correct "resized 45 images" Great job! This is such a useful tool for a web designer!

Share this post


Link to post

Thanks for this awesome tool! Really great work!

Do you have an advice how to get it working in ForkLift3? I guess I have to "collect" the paths of the images from there... 

Share this post


Link to post

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.

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