當我通過一個jpg文件到imgsize.php?w=100&h=100&img=powered_by.jpg
那麼它的工作做好 沒有工作,但我通過一個PNG文件imgsize.php?w=100&h=100&img=mengo.png
它不工作我「png格式」圖像大小調整圖像的代碼在PHP
我imgsize.php文件代碼是
$extension = pathinfo($_GET['img']);
$extension = $extension[extension];
if ($extension == "jpg" || $extension == "jpeg" || $extension == "JPG") {
header("Content-type: image/jpeg");
}
if ($extension == "png") {
header("Content-type: image/png");
}
if ($extension == "gif") {
header("Content-type: image/gif");
}
$img = $_GET['img'];
$nwidth = $_GET['w'];
$nheight = $_GET['h'];
$img2 = imagecreatefromjpeg($_GET['img']);
$width = imagesx($img2);
$height = imagesy($img2);
$ratio = $width/$height;
$new_nwidth = $nwidth;
$new_nheight = floor($height * ($nwidth/$width));
$im = imagecreatefromjpeg($img) or $im = imagecreatefrompng($img) or $im = imagecreatefromgif($img) or $im = false;
if (!$im) {
} else {
$thumb = imagecreatetruecolor($new_nwidth, $new_nheight);
imagealphablending($thumb, false);
imagesavealpha($thumb, true);
$transparent = imagecolorallocatealpha($thumb, 255, 255, 255, 127);
imagefilledrectangle($thumb, 0, 0, $new_nwidth, $new_nheight, $transparent);
imagecopyresized($thumb, $im, 0, 0, 0, 0, $new_nwidth, $new_nheight, $width, $height);
if ($extension == "jpg" || $extension == "jpeg" || $extension == "JPG") {
imagejpeg($thumb, null, 100);
}
if ($extension == "png") {
imagepng($thumb, null, 9);
}
if ($extension == "gif") {
imagegif($thumb, null, 100);
}
}
它的任何解決方案嗎?其顯示空白圖像時,我把它傳遞出一個PNG文件
看看函數名稱,然後認爲PNG不是JPEG格式但可能手冊具有相同的功能爲PNG。 – 2012-02-29 05:46:34