Re: image sizing/cropping



William Gill wrote:
Daniele wrote:
William Gill wrote:
... would like to allow ... without me having to process each one.

imagemagick.org
have a look there
it solve lot of my problem that i had with gd on big photo

I scanned imagemagick.org, but none of the imagemagick extensions appear to be installed on the server so I don't see how this helps me.

You can do it without imagemagick, but it's a bit slower. All you need are the GD functions.

Basically, you create a new image and copy the old one. Some sample code adapted from another project (untested, so no guarantees, but it's close)

// function resizeImage
// Resizes an image, maintaining the aspect ratio
// Input: full path and filename to image to be resized,
// new width
// new height
// Output: handle to a jpg image, or NULL if an error

function resizeImage($image, $x, $y)
if (file_exists($image)) {
if ($x > 0 && $y > 0) {
$image_size = getimagesize($image);
if ($image_size[0] > 0 && $image_size[1] > 0) {
$x_ratio = $x / $image_size[0];
$y_ratio = $y / $image_size[1];
if ($x_ratio < $y_ratio) {
$y = intval(round($image_size[1] * $x_ratio));
} else {
$x = intval(round($image_size[0] * $y_ratio));
}
} else {
return null;
}
$image_show = imagecreatetruecolor($x, $y);
switch ($image_size['mime']) {
case 'image/jpeg':
$image_in = imagecreatefromjpeg($image);
break;
case 'image/gif':
$image_in = imagecreatefromgif($image);
break;
case 'image/png':
$image_in = imagecreatefrompng($image);
break;
default:
return null;
}
imagecopyresampled($image_show, $image_in, 0, 0, 0, 0, $x, $y, $image_size[0], $image_size[1]);
return $image_show;
}
}
return null;
}

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
.