1

I need to generate thumbnail for all images in a folder like this ( example )

Original image:

enter image description here

What I want:

enter image description here

I have tried this command

mogrify *.jpg -gravity center -thumbnail 350x200 *.jpg

What I am getting with this command:

enter image description here

Platform - Windows 7.

2 Answers 2

1

A thumbnail is a small version of the graphic.

You seem to want a cropped section of the original, not a thumbnail. So you're using the wrong command. :)

You'll want to use resize the image to one of your desired dimensions, and then use the crop command(s) to take a copy of the section you want.

1
  • I didn't know that . Can you give me a example pls . I used gnuthumbnailer gnuyork.org/en/gtn-download.html to create the second image in the question . I have read the crop page . It think the values will change for each image . All the images in my folder are of different sizes .
    – Renuka
    Nov 25, 2014 at 19:08
1

You want to both crop and resize the image:

mogrify -crop 800x520+0+300 -resize 320x200 *.jpg

And yes, since you're pictures differ then you may have to adjust the crop parameters per image. With some scripting, you can programatically adjust these parameters however, for example, creating a bash script cut-resize.sh as below, and running it with a file name argument, so cut-resize.sh testimage.jpg:

#!/bin/bash
origX=`identify $1 | cut -d' ' -f3 | cut -dx -f1`
origY=`identify $1 | cut -d' ' -f3 | cut -dx -f2`
offset=300

eval "mogrify -crop ${origX}x$(($origY/2))+0+$offset -resize 320x200 $1"

Will do the nearly the same thing - cut the middle 50% of the image and then resize, for any sized image. You could add additional arguments and variables so you could specify your offset and the ammount to crop, but let your script take care of setting the geometry for imagemagick.

Or on windows, the following batch example might work, I have no idea, I only have a linux box, but the point is that you can script adjustment of the variables:

file=%1

rem identify %file%  | cut -d' ' -f3 | cut -dx -f1
for /f "tokens=3" %%G IN ('identify %file%') DO set temp=%%G
for /f "tokens=1" "delims=x" %%G IN ("%temp%") DO set oldx=%%G
for /f "tokens=2" "delims=x" %%G IN ("%temp%") DO set oldy=%%G

offset=300
newx=%oldx%
newy=%oldy%/2

mogrify -crop %newx%x%newy%+0+%offset% -resize 320x200 %file%

A good reference for batch, bash or powershell scripting is http://ss64.com/. Combining scripting with Imagemagick is very powerful once you build out your workflows and scripts.

12
  • I should have mentioned I am on Windows . Will this work in .bat ( from origX till the end ) ?
    – Renuka
    Nov 25, 2014 at 19:51
  • Your best bet on windows is to try cygwin to get bash, or use powershell. Scripting with bat files is a PAIN.
    – glallen
    Nov 25, 2014 at 21:33
  • I tried it in cygwin . Named the file resizer.sh . Placed it in D drive in a folder named "a" . Got this very long error pastebin.com/i003VgMJ
    – Renuka
    Nov 25, 2014 at 21:40
  • try replacing eval with echo so you can see what command it is trying to run, and adjust. But the scripting was just an example of what you could do, the scope of the question is what's the command to crop and resize... scripting is another realm really.
    – glallen
    Nov 25, 2014 at 21:49
  • The Windows script it not working . In your sh code i removed the empty 5th line and the \r error was gone . Now only this is left /2")syntax error: invalid arithmetic operator (error token is "
    – Renuka
    Nov 25, 2014 at 22:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .