View Full Version : Image resizing

09-23-2012, 07:32 PM

I have imported 760 products using EP and am now going through each product to update its product image.

I have update approximately 130 images and when using fixed width, the height is variable and affects the layout of the page.

When I fix the height and width, the image becomes distorted and stretched.

How can I ensure that the image is resize proportionately to its original size ?


09-24-2012, 05:29 AM
For rectangular images, pad them out with white space (or transparency) until they are square.
Example: new_width=width+abs(width-height)
Irfanview is quick n easy at doing this sort of thing, enlarging canvas by half of the above, either side.

Point of order: it is sizing proportionately - a tall narrow image will remain a tall narrow image, regardless of size - it is in proportion.

If it suits your layout better, choose a fixed height and variable width.

According to phpthumb (the image resizer) documentation:

Thumbnails can be a fixed dimension regardless of source aspect ratio and background filled with configurable color...
Perhaps someone has time to experiment.
This would appear to be the function to use:

static function ScaleToFitInBox($width, $height, $maxwidth=null, $maxheight=null, $allow_enlarge=true, $allow_reduce=true) {
$maxwidth = (is_null($maxwidth) ? $width : $maxwidth);
$maxheight = (is_null($maxheight) ? $height : $maxheight);
$scale_x = 1;
$scale_y = 1;
if (($width > $maxwidth) || ($width < $maxwidth)) {
$scale_x = ($maxwidth / $width);
if (($height > $maxheight) || ($height < $maxheight)) {
$scale_y = ($maxheight / $height);
$scale = min($scale_x, $scale_y);
if (!$allow_enlarge) {
$scale = min($scale, 1);
if (!$allow_reduce) {
$scale = max($scale, 1);
return $scale;