Automatically generating square thumbnails from non-square images

Discussion in 'Digital Darkroom' started by steve_bright|1, Jul 12, 2006.

  1. The title just about sums it up - I have a number of images which are of
    varying aspect ratios. I want to automatically (in a Photoshop action) crop the
    ends of each image, leaving the central square. I would then resize in the
    usual manner to make a thumbnail.
    The long side of all images have the same length, but I don't think that
    really helps as the dimensions of the resultant square will be the same as the
    original short side. There's a mix of vertical and horizontal orientations.
    I've been pondering over this for quite a while, but I'm stumped and I
    haven't had any luck googling for it.
    Thanks in advance for your help.
    Last edited by a moderator: Nov 8, 2018
  2. If you have Photoshop we can post an automation (action or droplet) for you.

    Maybe someone else can suggest an alternate program.
  3. Just create an action to do the cropping per your desires and save as to a new file, then call that action via batch. I do this all the time. If you create the crop action independently, you can embed it into another script, or you can have a single action that does the entire crop and save as a monolithic piece.

    Here's a pair I made just now for you as examples:

    For simplicity sake, I made two, one for Horizontals and the other for Verticals. Install them into Photoshop CS2. Then open Bridge on a folder of JPEG images you want to squareify, select all the horizontals, use the menu item to choose Photoshop batch, set up a destination folder and override the output file name, tell it to go. Do the same for the verticals when that's done.

    It's best to write your own script and make it do precisely what you want, but this is a rough demonstration that works. I applied it to a folder of 30 H and 30 V JPEG files, it produced another folder of 60 square files for me.

  4. LOL ... just playing with my simple scripts and I see the limitations ... It works well when I
    have a set of pictures of identical resolution that matches the action I created, but is pretty
    hopeless when handing it a bunch of images that vary in size and resolution.
    I suspect this means that you want to script <br>
    - rendering the image files to fit particular size and resolution density
    Image->Image Size... with resampling<br>
    - apply a standard crop to that result
    fun fun fun<br>
  5. I have an idea that might work. Do an action that will
    1. First change the canvas size to a square format. This should still keep the center of the image at the center

    2. Do a resize using just the resolution setting

    3. Do a crop using again the canvas size setting.

    This should work ok with different sizes and resolutions as long as the size are not too widely different.
  6. Steve,

    I have the same problem with actions all the time. You can script Photoshop using JavaScript and these scripts can access image properties such as width and height.



    Hope that helps. I am not very good at JavaScript programming but can probably help you out if you need assistance.
  7. Actually you can use either Applescript or Visual Basic to do this too. Both of these are apparently easier to work with than JS. I have a Mac and use AppleScript but have never used Visual Basic.

    The advantage of JavaScript is that it will work on either platform.
  8. If you use a Mac here is an Applescript to do exactly what you want. You should be able translate it to VBScript. I tested it on my copy of PS7. Watch the line breaks introduced here. I retyped it here (rather than lik my latop up) so watch out for typos.

    tell application "Adobe Photoshop 7.0"

    --just be a little careful


    set docRef to current document

    on error

    display dialog "must have an open document"

    end try

    set docWidth to width of docRef

    set docHeight to height of docRef

    if docWidth > docHeight then

    set minDimension to docHeight


    set minDimension to docWidth

    end if

    crop docRef bounds {(docWidth-minDimension)/2 , (docHeight-minDimension)/2 , (docWidth+minDimension)/2 , (docHeight+minDimension)/2 }
  9. I am mortified that I haven't responded to you sooner, I think I must have had email notifications turned off.

    Pico: I have Photoshop CS and an action would be great if you could provide one, but I'm not sure it's possible with a 'straight' action.

    Godfrey: Thanks for your suggestions, but I really want to be able to do this without having to separate them into horizontal and vertical photos.

    Sravan: I don't think this is going to work as the images have varying aspect ratios.

    Alistair: I think you're right and I'll have to do it with scripting. I'm on a PC so I'll probably use Javascript and build on your Applescript statement.

    Many thanks to you all for your help.
  10. Javascript has a big advantage over either of the two other scripting languages because Javascript scripts can be embedded in Photoshop actions. At least on PS 7 I don't know how to embed Applescript scripts.
  11. Steve,

    If you run into problems don't hesitate to contact me. I don't know the JavaScript object model off the top of my head but I have the right source and it should be a matter of minute to whip up a script that works.
  12. Hey folks,
    I know there are some solutions presented here already, but I thought I would contribute mine. I made an action called Square Thumbnails (h+v).atn that automates this process as much as possible without using outside scripts.
    It creates full-frame thumbnails at 256px x 256 px. To solve the horizontal/vertical orientation issue, it actually creates 2 thumbnails of each photo, one correctly cropped and one not correctly cropped, and puts them in a "h" and a "v" folder. The background of the incorrectly cropped thumbnails is red so you can tell from the finder when it's not the right one, and ignore it or delete it manually.
    Save Location, Thumbnail Size, and Export Quality are all configurable by opening up an image and double clicking on the individual action item and editing as needed, but if 256px square and on the desktop works for you, that's not needed.
    Hope it helps someone.
    Shawn Taylor - Photographer and co-founder of
  13. Auto crop image is awesome. I stumbled across this post yesterday after struggling to find anything to make all my e-commerce pictures square using the longest side of the image. This is the only solution I could find. That's everyone.
  14. Hi Steve. The description of Auto Crop looks like it does the job and I hever have used it yet here are the steps that will record properly to do what you want

    1) Load image
    2) Duplicate Layer Cmd J (Cntl + J for PC)
    3) Transform second Layer and rotate 90 degrees either direction
    4) Cmd click on Layer Thumbnail of Duplicate Layer to create selection (Cntl click on Layer Thumbnail for PC)
    5) Delete Duplicate Layer
    6) Image > Crop
    7) Optionally Cmd + D to remove selection (Cntl + D on PC)
    8) Size and save image as desired using Image > Image Size (with desired parameters)

    This gives you a square iamge cropped exactly in the center of the image no matter if you started with portrait or landscape image.

    Hope this helps
  15. William Michael

    William Michael Moderator Staff Member

    NOTE: the original post was written in 2006.
  16. Thanks William, I just keyed off of recent posts and did not notice the thread was 12 years old. Are you trying to tell me I am just a bit late? :):):);)
  17. William Michael

    William Michael Moderator Staff Member

    haha just a little bit late.

    john, it is easy to do.

    This conversation was reinvigorated by a post a few days ago, (which has subsequently been deleted), that (now deleted) response pushed the thread to the top, so, understandably, you thought it was a recent conversation.

    Anyway we know know about "auto crop".


Share This Page