Re: image resize?

From: Date: Sat, 05 Jun 2004 17:42:28 +0000
Subject: Re: image resize?
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-12936@lists.php.net to get a copy of this message
Antti wrote:
Hi! Is there a package to perform an image resize? I see there's a few packages related to images but can they resize? Thanks -a
I posted a simple script to one of the lists recently to do this with GD. Here it is again: $fileinfo = pathinfo($file); switch(strtolower($fileinfo['extension'])) { case 'png':
    $ifh = imagecreatefrompng($dir.$file);
    break;
case 'jpg': case 'jpeg': case 'jpe':
    $ifh = imagecreatefromjpeg($dir.$file);
    break;
case 'gif':
    $ifh = imagecreatefromgif($dir.$file);
    break;
default:
    echo '  I don\'t know what to do with the extension '.$fileinfo['extension']."\n";
    exit;
    break;
} $swidth = imagesx($ifh); $sheight = imagesy($ifh); $ih = imagecreatetruecolor($width + $edge * 2, $height + $edge * 2); imagealphablending($ih, true); if($swidth > $sheight) {
    $nwidth = $width;
    $nheight = (int)($sheight / $swidth * $nwidth);
    $x = 0;
    $y = ($height - $nheight) / 2;
} else if($sheight < $swidth) {
    $nheight = $height;
    $nwidth = (int)($swidth / $sheight * $nheight);
    $y = 0;
    $x = ($width - $nwidth) / 2;
} else {
    $nwidth = $width;
    $nheight = $height;
    $x = $y = 0;
} imagecopyresampled($ih, $ifh, $x + $edge, $y + $edge, 0, 0, $nwidth, $nheight, $swidth, $sheight); header('Content-Type: image/jpeg'); imagejpeg($ih); -- paperCrane <Justin Patrin>

« previous php.pear.general (#12936) next »