Image output garbled

Source: Internet
Author: User
Problem: garbled image output & lt ;? Php?image='new0.jpg '; $ img = getimagesize ($ image); // print_r ($ img); switch ($ img [2]) {case1: $ dimg = imagecreatef help: garbled image output
Required imageapps'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 );
?>
The above is the source code. if this is used directly, a prompt will be prompted.
Warning: Imagecreatefrompng () [function. imagecreatefrompng]: 'new0.jpg 'is not a valid PNG file in E: \ wamp \ www \ test \ imgtest. phpOn line 11
Warning: Imagejpeg () expects parameter 1 to be resource, boolean given in E: \ wamp \ www \ test \ imgtest
Tested Image type: Array
(
[0] = & gt; 479
[1] => 700.
[2] => 2
[3] => width = "479" height = "700"
[Bits] => 8
[Channels] => 3
[Mime] => image/jpeg
)
The problem is that the switch statement does not seem to have been successfully run. Why does it mean to judge imagecreatefrompng?
If you do not want to switch the statement and run imagecreatefromjpeg directly, the output is garbled. why?

------ Solution --------------------
Switch ($ img [2]) {
Case 1:
$ Dimg = imagecreatefromgif ($ image );
Break;
Case 2:
$ Dimg = imagecreatefromjpeg ($ image );
Break;
Case 3:
$ Dimg = imagecreatefrompng ($ image );
Break;
}

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.