摘要:getimagesize函数Array ( [0] => 1136 [1] => 757 [2] => 2 [3] => width="1136" height="757" [bits] => 8 [channels] => 3 [mime] => image/jpeg )明显可以看出这个图片...
getimagesize函数
Array ( [0] => 1136 [1] => 757 [2] => 2 [3] => width="1136" height="757" [bits] => 8 [channels] => 3 [mime] => image/jpeg )
明显可以看出这个图片的类型是jpeg的,而我在程序里判断的代码如下:
$ext = explode(".",$picname);
$ext=end($ext); //判断图片类型 www.bcty365.com
switch($ext){
case "png":
$image=imagecreatefrompng($picname);
break;
case "jpeg":
$image=imagecreatefromjpeg($picname);
break;
case "jpg":
$image=imagecreatefromjpeg($picname);
break;
case "gif":
$image=imagecreatefromgif($picname);
break;
}
使用$ext = explode(".",$picname);$ext=end($ext);判断图片类型明显有弊端
那该如何优化呢?代码如下
$ename=getimagesize($picname);
$ename=explode('/',$ename['mime']);
$ext=$ename[1];
switch($ext){
case "png":
$image=imagecreatefrompng($picname);
break;
case "jpeg":
$image=imagecreatefromjpeg($picname);
break;
case "jpg":
$image=imagecreatefromjpeg($picname);
break;
case "gif":
$image=imagecreatefromgif($picname);
break;
}
这样获取准确的图片类型,然后在执行裁剪,这样裁剪就没有问题了,奇葩问题。。。。