A user-defined function used to determine the image format

Source: Internet
Author: User
Ask for a user-defined function to determine the image format. after writing the image, it cannot be output normally. The image is in jpg format and can be output normally without a user-defined function, the code is as follows: function & nbsp; image_check ($ aa, $ im) {& nbsp; $ img = getimagesize ($ aa ); & nbsp ask for a user-defined function to determine the image format
The user-defined function used to determine the image format. after writing the image, it cannot be output normally. The image is in jpg format and can be output normally without a user-defined function. the code is as follows:

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 );


------ Solution --------------------

function image_check($aa)
{
  $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';
$bb=image_check($image);
header("Content-type:image/jpeg");
imagejpeg($bb);

I just read it. it should be the question of passing parameters. now I have changed it. can you try it?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.