求助:图片输出乱码问题
<?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);
?>
上面是源码,如果这样直接用,会提示
<b>Warning</b>: imagecreatefrompng() [<a href='function.imagecreatefrompng'>function.imagecreatefrompng</a>]: 'new0.jpg' is not a valid PNG file in <b>E:\wamp\www\test\imgtest.php</b> on line <b>11</b><br /><b>Warning</b>: imagejpeg() expects parameter 1 to be resource, boolean given in <b>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;
}