[Zope] Photo: somes issues and thoughts
J M Cerqueira Esteves
jmce@artenumerica.com
Fri, 4 Jan 2002 06:40:07 +0000
* J M Cerqueira Esteves <jmce@artenumerica.com> [2002-01-03 19:40 +0000]:
> Unfortunately, I had no time to determine the precise equation used
> by ImageMagick to calculate new sizes maintaining aspect ratio.
> Having it, you could use that instead of the calculation at
> _getAspectRatioSize when resizing with PIL (since PIL's `resize',
> unlike ImageMagick's `convert', doesn't try to maintain aspect ratio
> and needs to be given precise final sizes).
I have just found what ImageMagick uses, in magick/image.c, function
ParseImageGeometry. If (w0, h0) are the original width and height and
(wM, hM) are the maximum width and height allowed (specified with
-geometry wMxhM), ImageMagick defines the final width and height
as follows (in Python):
scale = min (float (wM) / w0, float (hM) / h0)
width = max (int (scale * w0 + 0.5), 1)
height = max (int (scale * h0 + 0.5), 1)
while Photo uses (with integer division, therefore with truncation everywhere):
if hM > h0 * wM / w0:
height = h0 * wM / w0
width = wM
else:
height = hM
width = w0 * hM / w0