求助:图片输出乱码问题
<?php
$image='new0.jpg';
$img=getimagesize($image);
//print_r($img);
switch ($img[2]){
case 1:
$dimg=imagecreatefromgif($image);
case 2:
$dimg=imagecreatefromjpeg($image);
case 3:
$dimg=imagecreatefrompng($image);
}
header("Content-type:image/jpeg");
imagejpeg($dimg);
?>
上面是源码,如果这样直接用,会提示
Warning: imagecreatefrompng() [function.imagecreatefrompng]: 'new0.jpg' is not a valid PNG file in E:\wamp\www\test\imgtest.php on line 11
Warning: imagejpeg() expects parameter 1 to be resource, boolean given in E:\wamp\www\test\imgtest
测试过图片类型了:Array
(
[0] => 479
[1] => 700
[2] => 2
[3] => width="479" height="700"
[bits] => 8
[channels] => 3
[mime] => image/jpeg
)
现在的问题是,开关语句好像没有成功运行,不知道为什么老去判断imagecreatefrompng这个语句?
还有 如果不要开关语句,直接运行imagecreatefromjpeg的话,输出却又是乱码,这是为什么啊?
------解决方案--------------------
switch ($img[2]){
case 1:
$dimg=imagecreatefromgif($image);
break;
case 2:
$dimg=imagecreatefromjpeg($image);
break;
case 3:
$dimg=imagecreatefrompng($image);
break;
}