Re: resize pictures received by mailserver
On Wed, 2012-06-13 at 15:08 -0500, Christofer C. Bell wrote:
> The ImageMagick "identify" command could be used on the image to
> gather statistics (such as pixel size) do some math on it, and feed
> that back to mogrify, giving you some consistency in output.
>
> Example:
>
> cbell@circe:~$ identify testimage.jpg
> testimage.jpg JPEG 4752x3168 4752x3168+0+0 8-bit DirectClass 5.706MB
> 0.000u 0:00.000
> cbell@circe:~$
>
> Grab field 3, do some math to determine aspect ratio, compare the
> current resolution against your target, figure out the new size for
> the image, feed that back to mogrify to resize it correctly.
>
> Want something smaller than 800x600?
>
> In the above, the image is 4752 x 3168. We want the image to be
> smaller than 800x600. We need to decrease the image size by the
> larger of 4752/800 or 3168/600. These are 5.28 and 5.94 respectively.
> So we need to decrease the image to 16.8% of its current size
> (1/5.94).
>
> cbell@circe:~$ mogrify -resize 16.8% testimage.jpg
> cbell@circe:~$ identify testimage.jpg
> testimage.jpg JPEG 798x532 798x532+0+0 8-bit DirectClass 239KB 0.000u 0:00.010
> cbell@circe:~$
>
> Goal achieved.
It's much simpler to do:
mogrify -resize '800x600<' testimage.jpg
or to limit it to 800 in any dimension
mogrify -resize '800x800<' testimage.jpg
(These commands preserve aspect ratio and only resize if image is
greater than the given dimensions.)
--
Tixy
Reply to: