resizing (uploaded) images
Okay, I have my image script that's finally working. Now I'd like to resize the uploaded image (permanatly). I'd assume this would be done during the uploading process.
Basically, I'd give preset porportions. The uploaded image would then be resized to the correct size I specified, then saved to the server.
How should I go about doing this?
Here's my de facto resizing function. It covers most needs. Resizes most image types and maintains transparency and alpha if the image has them.
If you have trouble integrating this you will need to post your code but before you do, check out the code in this thread.
function resize($source, $destination = null, $w = 125, $h = 125, $quality = 100)
$details = @getimagesize($source) or die("I cannot open $source");
$type = preg_replace('@^.+(?<=/)(.+)$@', '$1', $details['mime']);
eval('$source = imagecreatefrom'.$type.'($source);');
if($details < $details)
$w = round(($h / $details) * $details);
$h = round(($w / $details) * $details);
$slate = @imagecreatetruecolor($w, $h) or die('Invalid thumbnail dimmensions');
$slate = @imagecreate($w, $h) or die('Invalid thumbnail dimmensions');
if(false !== ($trans = @imagecolorsforindex($source, imagecolortransparent($source))))
$trans = ImageColorAllocate($slate, $trans['red'], $trans['green'], $trans['blue']);
imagefilledrectangle($slate, 0, 0, $w - 1, $h - 1, $trans);
imagecopyresampled($slate, $source, 0, 0, 0, 0, $w, $h, $details, $details);
$destination or header('Content-Type: '.$details['mime']);
$destination or die;
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)