Converting images with padding or cropping on left and right
am 23.09.2007 14:55:13 von tuxedo
I have a simple shell procedure that batch converts original jpeg's in
various sizes into thumbnail copies, maximum 75 pixels in height:
for i in *.jpg
do convert -quality 70 -geometry x75 $i ../img/`basename $i .jpg`.jpg;
done
When a resulting thumbnail image become less than 100 pixels wide I'd like
to add padding on left and right in some solid color, making the jpeg
including the solid area, to exactly 100 pixels wide.
If however a resulting thumbnail is wider than 100 pixels, I'd like it
cropped equally, or to the nearest pixel, on the left and right edges, so
that it becomes exactly 100 pixels wide.
This is like placing the resulting 75 pixes tall image in the center
of a canvas which is exactly 100x75 pixels, and discarding the excess area
if any.
I'm not sure if this can be done with the Image Magick toolset alone, and
if not, is there an easy way to do this using PerlMagick?
Re: Converting images with padding or cropping on left and right
am 23.09.2007 19:50:08 von Lars Haugseth
* Tuxedo wrote:
>
> I have a simple shell procedure that batch converts original jpeg's in
> various sizes into thumbnail copies, maximum 75 pixels in height:
>
> for i in *.jpg
> do convert -quality 70 -geometry x75 $i ../img/`basename $i .jpg`.jpg;
> done
>
> When a resulting thumbnail image become less than 100 pixels wide I'd like
> to add padding on left and right in some solid color, making the jpeg
> including the solid area, to exactly 100 pixels wide.
>
> If however a resulting thumbnail is wider than 100 pixels, I'd like it
> cropped equally, or to the nearest pixel, on the left and right edges, so
> that it becomes exactly 100 pixels wide.
>
> This is like placing the resulting 75 pixes tall image in the center
> of a canvas which is exactly 100x75 pixels, and discarding the excess area
> if any.
>
> I'm not sure if this can be done with the Image Magick toolset alone, and
> if not, is there an easy way to do this using PerlMagick?
This is easily done using -border/-crop on the command line, or with
PerlMagick using Border/Crop methods.
--
Lars Haugseth
"If anyone disagrees with anything I say, I am quite prepared not only to
retract it, but also to deny under oath that I ever said it." -Tom Lehrer
Re: Converting images with padding or cropping on left and right
am 23.09.2007 22:49:10 von tuxedo
Lars Haugseth wrote:
[...]
> This is easily done using -border/-crop on the command line, or with
> PerlMagick using Border/Crop methods.
Thanks for the tip. I'll look into this. In the meantime, someone at
comp.unix.shell came up with a very good procedure that does the cropping.