我正在创建各种格式(jpg, png)
的myImage
的缩略图。这里是我的代码imagepng不起作用,它创建一个空白图像和图像不压缩
<?php
error_reporting(E_ALL);
//$file = 'H:/xampp/htdocs/myfolder/new.jpg';
$file = 'H:/xampp/htdocs/myfolder/phool.png';
$pathToSave = 'H:/xampp/myfolder/New/';
$sourceWidth =60;
$sourceHeight = 60;
$what = getimagesize($file);
$file_name = basename($file);
//print "MIME ".$what['mime'];
switch(strtolower($what['mime']))
{
case 'image/png':
$img = imagecreatefrompng($file);
$img = imagecreatefromstring($img);
$new = imagecreatetruecolor($what[0],$what[1]);
imagecopy($new,$img,0,0,0,0,$what[0],$what[1]);
header('Content-Type: image/png');
imagepng($new,$pathToSave.$file_name);
imagedestroy($new);
break;
case 'image/jpeg':
$img = imagecreatefromjpeg($file);
$new = imagecreatetruecolor($what[0],$what[1]);
imagecopy($new,$img,0,0,0,0,$what[0],$what[1]);
header('Content-Type: image/jpeg');
imagejpeg($new,$pathToSave.$file_name);
imagedestroy($new);
break;
case 'image/gif':
$img = imagecreatefromgif($file);
break;
default: die();
}
但是,它不工作PNG images.It保存在我的目的地$pathToSave = 'H:/xampp/htdocs/myfolder/New/'
空白图像。
如果我删除$img = imagecreatefromstring($img);
然后imagepng
保存图像,但不会像imagejpg
那样压缩图像。
只是尽量不使用'$ IMG = imagecreatefromstring($ IMG);' – 2014-10-09 14:00:31
善于观察,但如果我删除,它只是保存原始图像,它不会在这里进行压缩 – Hitesh 2014-10-09 14:05:10
你的意思原始图像?你的文件'phool.png'所以它可能是相同的图像 – 2014-10-09 14:12:37