Dynamic image resizing on upload

Dynamic image resizing on upload

am 12.06.2007 15:39:04 von Mark Abrams

Is there a PHP function to resize a user's JPG or GIF image during an
upload?

I was advised to use Image Magick http://www.imagemagick.org However, the
Windows install doc has not been written. I have unsuccessfully struggled
with the install for days ...

All I want to do is to resize a large image to a thumbnail of my dimensions
when my end user uploads a an image.

TIA for any help.

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Dynamic image resizing on upload

am 12.06.2007 15:48:16 von Dale Attree

------=_NextPart_000_0034_01C7AD09.1837F5E0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit

$Filename = full path and filename of original file
$Thumbnail = full path and filename of thumbnail
$WIDTH && $HEIGHT = specified for resizing

Gdlib must be installed.

function Resize($Filename,$Thumbnail,$WIDTH,$HEIGHT){
$image = $Filename;
$thumbnail = $Thumbnail;
$imagesize = getimagesize($image);
$fwidth = $imagesize[0];
$fheight = $imagesize[1];

if($fheight <= $fwidth){
$percentage = round(($WIDTH/$fwidth) * 100);
$newwidth = round(($fwidth * $percentage)/100);
$newheight = round(($fheight * $percentage)/100);
}
elseif($fheight > $fwidth){
$percentage = round(($HEIGHT/$fheight) * 100);
$newwidth = round(($fwidth * $percentage)/100);
$newheight = round(($fheight * $percentage)/100);
}
else{
$percentage = round(($fwidth/$WIDTH) * 100);
$newwidth = round(($fwidth * $percentage)/100);
$newheight = round(($fheight * $percentage)/100);
}
$destImage = imagecreatetruecolor($newwidth,$newheight) or
die($file.' - '.$newwidth.':'.$newheight);
$type = strtolower(substr($Filename,-3));
switch($type){
case 'gif':
$srcImage = ImageCreateFromGif($image);
ImageCopyResized($destImage, $srcImage, 0,
0, 0, 0, $newwidth, $newheight, imagesx($srcImage), imagesy($srcImage));
ImageGif($destImage,$thumbnail);
break;
case 'jpg':
$srcImage = ImageCreateFromJPEG($image);
ImageCopyResized($destImage, $srcImage, 0,
0, 0, 0, $newwidth, $newheight, imagesx($srcImage), imagesy($srcImage));
ImageJPEG($destImage,$thumbnail);
break;
case 'png':
$srcImage = ImageCreateFromPNG($image);
ImageCopyResized($destImage, $srcImage, 0,
0, 0, 0, $newwidth, $newheight, imagesx($srcImage), imagesy($srcImage));
ImagePNG($destImage,$thumbnail);
break;
}
//free the memory used for the images
ImageDestroy($srcImage);
ImageDestroy($destImage);

if(file_exists($thumbnail)){
return true;
}
else{
return false;
}
}?>

-----Original Message-----
From: Mark Abrams [mailto:mark@hospitalsystemsgroup.com]
Sent: 12 June 2007 03:39 PM
To: php-windows@lists.php.net
Subject: [PHP-WIN] Dynamic image resizing on upload

Is there a PHP function to resize a user's JPG or GIF image during an
upload?

I was advised to use Image Magick http://www.imagemagick.org However, the

Windows install doc has not been written. I have unsuccessfully struggled
with the install for days ...

All I want to do is to resize a large image to a thumbnail of my dimensions

when my end user uploads a an image.

TIA for any help.

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




************************************************************ ***********************************
The information contained in this e-mail is confidential and may be subject to legal privilege.
Access to this e-mail by anyone other than the intended recipient is unauthorised.

If you are not the intended recipient you must not use, copy, distribute or disclose the e-mail or any part of its contents or take any action in reliance on it. If you have received this e-mail in error, please notify us immediately by e-mail (postmaster@jacklinenterprises.com) or telephone (+27 11 265 4200).
This message is free of all known viruses. It has been screened for viruses by Blockmail.
************************************************************ ***********************************


------=_NextPart_000_0034_01C7AD09.1837F5E0--

Re: Dynamic image resizing on upload

am 12.06.2007 18:13:28 von PAUL MENARD

--0-1651903662-1181664808=:57402
Content-Type: text/plain; charset=ascii

Mark,

Not sure about your comment "...the Windows install doc has not been written.".

From the ImageMagick site I see the pre-compiled Windows downloads
http://www.imagemagick.org/script/binary-releases.php#window s

Just above the list of download links is the paragraph:
"The Windows version of ImageMagick is self-installing. Simply click on
the appropriate version below and it will launch itself and ask you a
few installation questions."

P-


----- Original Message ----
From: Mark Abrams
To: php-windows@lists.php.net
Sent: Tuesday, June 12, 2007 8:39:04 AM
Subject: [PHP-WIN] Dynamic image resizing on upload

Is there a PHP function to resize a user's JPG or GIF image during an
upload?

I was advised to use Image Magick http://www.imagemagick.org However, the
Windows install doc has not been written. I have unsuccessfully struggled
with the install for days ...

All I want to do is to resize a large image to a thumbnail of my dimensions
when my end user uploads a an image.

TIA for any help.

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php






--0-1651903662-1181664808=:57402--