PHP Load Image imagecreatefrom_gif_jpeg_png series function usage Analysis

Source: Internet
Author: User
Tags php programming
This paper analyzes the usage of PHP loaded image Imagecreatefrom_gif_jpeg_png series function. Share to everyone for your reference, as follows:

The Imagecreatefrom series function is used to load an image from a file or URL.

Loading images

The Imagecreatefrom series function is used to load an image from a file or URL, successfully returning an image resource, and failing to return an empty string.

The series functions are:

Imagecreatefromgif (): Create a canvas and load a picture from a GIF file or URL address
Imagecreatefromjpeg (): Create a canvas and load a picture from a JPEG file or URL address
Imagecreatefrompng (): Create a canvas and load a picture from a PNG file or URL address
Imagecreatefromwbmp (): Create a canvas and load an image from the WBMP file or URL address
Imagecreatefromstring (): Create a canvas and new image from the image stream in the string

Grammar:

Resource Imagecreatefromgif (string filename) resource imagecreatefromjpeg (string filename) resource Imagecreatefrompng (string filename) resource imagecreatefromwbmp (string filename) resource imagecreatefromstring ( String image)

Example:

<?header ("Content-type:image/jpeg");//Create and load an image $im = @imagecreatefromjpeg ("images/flower_1.jpg");//error handling if (!$ IM) {  $im = Imagecreatetruecolor (.);  $BG = Imagecolorallocate ($im, 255, 255, 255);  $text _color = imagecolorallocate ($im, 0, 0, 255);  Fill background color  imagefilledrectangle ($im, 0, 0, N, a, $BG);  Output error message as Image  Imagestring ($im, 3, 5, 5, "Error loading image", $text _color),} else {  //output the image  imagejpeg ($im) ;}? >

In this example, we load and output the original image. Since PHP has no friendly error prompting for image creation errors, we have customized the error handling information.

Tips

For PHP-generated images, if you want to display directly in a normal web page instead of the header output, you can call it in the following way:

I hope this article is helpful to you in PHP programming.

Related Article

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.