Home > Backend Development > PHP Tutorial > 一个判断图片格式的自定义函数

一个判断图片格式的自定义函数

WBOY
Release: 2016-06-13 12:54:24
Original
901 people have browsed it

求助一个判断图片格式的自定义函数
判断图片格式的自定义函数,写完后一直不能正常输出,图片是jpg格式的,不用自定义函数可以正常输出,代码如下:

function image_check($aa,$im)
{
  $img=getimagesize($aa);
  switch($img[2])
  {
    case 1;
    $im=@imagecreatefromgif($aa);
    break;
    case 2;
    $im=@imagecreatefromjpeg($aa);
    break;
    case 3;
    $im=@imagecreatefrompng($aa);
    break;
   }
      return $im;
}
$image='c:\www\news\Winter.jpg';
image_check($image,$bb);
header("Content-type:image/jpeg");
imagejpeg($bb);


------解决方案--------------------
<br />
function image_check($aa)<br />
{<br />
  $img=getimagesize($aa);<br />
  switch($img[2])<br />
  {<br />
    case 1;<br />
    $im=@imagecreatefromgif($aa);<br />
    break;<br />
    case 2;<br />
    $im=@imagecreatefromjpeg($aa);<br />
    break;<br />
    case 3;<br />
    $im=@imagecreatefrompng($aa);<br />
    break;<br />
   }<br />
      return $im;<br />
}<br />
$image='c:\www\news\Winter.jpg';<br />
$bb=image_check($image);<br />
header("Content-type:image/jpeg");<br />
imagejpeg($bb);<br />
Copy after login

我刚看了下,应该是你传参的问题,现在我改了下,你试试行不
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template