Sup Guyz :3
I usually like to avoid asking questions but I am working on a site and I am trying to resize images to use them as thumbnails. The script that I am using works great for .gif and .jpg but for some reason not for .png. Can anyone tell me why? or supply a script that will do it?
Google was no help.
<?php
$varwidth=$_GET['width'];
$varheight=$_GET['height'];
$filename = $_GET['file'];
$ext = substr($filename, -3);
$width = $varwidth;
$height = $varheight;
if($ext=="jpg") {
header('Content-type: image/jpeg');
}
if($ext=="png") {
header('Content-type: image/png');
}
if($ext=="gif") {
header('Content-type: image/gif');
}
list($width_orig, $height_orig) = getimagesize($filename);
$ratio_orig = $width_orig/$height_orig;
if ($width/$height > $ratio_orig) {
$width = $height*$ratio_orig;
} else {
$height = $width/$ratio_orig;
}
$image_p = imagecreatetruecolor($width, $height);
if($ext=="jpg") {
$image = imagecreatefromjpeg($filename);
}
if($ext=="png") {
$image = imagecreatefrompng($filename);
}
if($ext=="gif") {
$image = imagecreatefromgif($filename);
}
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
if($ext=="jpg") {
imagejpeg($image_p, null, 100);
}
if($ext=="png") {
imagepng($image_p, null, 100);
}
if($ext=="gif") {
imagegif($image_p, null, 100);
}
?>