PHP Imagecreatefromjpeg return bool (false) Problem solving method

Source: Internet
Author: User

Error Description:

Imagecreatefromjpeg returns BOOL (false)
Imagecreatefromjpeg (): Xxx.jpg is not a valid JPEG file
Imagecreatefromjpeg (): Gd-jpeg:jpeg Library reports unrecoverable error

PHP Load Image function:

Imagecreatefromgif ()
Imagecreatefromjpeg ()
Imagecreatefrompng ()
Imagecreatefromwbmp ()
Imagecreatefromstring ()
Function: Creates a new image from a file or URL or image stream in a string, returns the image resource after success, and returns false after failure.
PS: A simple understanding of its role is to be divided into the image temporarily read in memory.

Error NOTE:
Error message translation: Picture is not a valid JPEG file

Error Reason:
This error is usually caused by inconsistencies in the function and image format used to process the picture, such as the PNG-formatted picture you are using the Imagecreatefromjpeg function.
Of course, you can be puzzled: the image extension is. jpg, with the Imagecreatefromjpeg function to deal with there is no wrong place ah?
In general, the picture's extension and the picture's format are the same. But there are times when the extension of the picture and the inconsistency of the image format, such as human modification, the image of PNG or GIF changed the extension to JPG, so sometimes the extension we see is not necessarily the correct extension of the picture file. So the program will throw the error back in the process.

Solution Idea:
Use the getimagesize function to get a picture format when you are working on a picture, and then judge the image processing function that you use. Also, determine if the return value is False, and if false, try a different function type.

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.