[Zope] Photo: somes issues and thoughts

Jose' Sebrosa sebrosa@artenumerica.com
Fri, 04 Jan 2002 16:26:15 +0000


J M Cerqueira Esteves wrote:
> 
> * Jose' Sebrosa <sebrosa@artenumerica.com> [2002-01-04 13:29 +0000]:
> > Sometimes, truncation (floor) gives better aspect ratio than round.  I would
> > even not be surprised if, statistically, none of the methods were better.
> >
> > Two examples:
> >
> > 1-
> > Initial size: 51x49
> > Scale: 1/10
> > Final size (method=round): 5x5
> > Final size (method=floor): 5x4
> > Best method: round
> >
> > 2-
> > Initial size: 54x56
> > Scale: 1/10
> > Final size (method=round): 5x6
> > Final size (method=floor): 5x5
> > Best method: floor
> 
> Those methods are not used by Photo and ImageMagick.


Sorry then.

> With Photo and IM you start by choosing new maximum integer
> dimensions, not the scale, and one of the sides of the resulting
> rectangle gets one of those exact integer lengths.  THEN you calculate
> the scale factor and apply it to the other side; it is here that
> IM rounds and Photo truncates.


Well, I suppose that the new maximum integer dimensions are choosen from an
initial scaling factor. So you say that the Photo and IM method are to 1) start
with an initial scale, 2) choose new maximum integer dimensions (through
round(initial_scale*dimension) in IM and floor() in Photo, I guess...), 3)
choose a dimension to have the new value (which dimension? let's say it's
always the width, or that it is always the smaller...), 4) *redefine* the
scaling factor to fit the new dimension (which becomes priviledged), and 5) set
the other dimension using the *redefined* scale (with round() in IM and floor()
in Photo).

I think that this is almost the same as my brute force suggestion, with the
single difference that I do not priviledge any of the dimentions in my choices
-- my criterium is just the final aspect ratio.  To arrange the code the way
IM/Photo does while keeping the symmetry in handling the two dimensions, I
think it would be necessary to do the calculations twice: one choosing width in
3) above, and other choosing height.  Then the final aspect ratios could be
compared, and the better approximation could be choosed.

Eventually, if the priviledged dimension choosed in 4 is the smaller (it is?),
there is no need to perform the second calculation, but this isn't obvious to
me.  Anyway, for the interested reader, it should be a simple exercice on math
to prove that this is, or isn't, true. On the other hand we can forget about
math and do it brute force -- it's easier!  :^)


Sebrosa