PHP load image imagecreatefrom_gif_jpeg_png Series Function Usage Analysis, imagecreatefromjpeg

Source: Internet
Author: User

PHP load image imagecreatefrom_gif_jpeg_png Series Function Usage Analysis, imagecreatefromjpeg

This document analyzes the usage of PHP-loaded imagecreatefrom_gif_jpeg_png functions. We will share this with you for your reference. The details are as follows:

Imagecreatefrom functions are used to load an image from a file or URL.

Load Image

Imagecreatefrom functions are used to load an image from a file or URL. An image resource is returned successfully. If the image fails, an empty string is returned.

The series of functions include:

Imagecreatefromgif (): Creates a canvas and loads an image from a GIF file or URL.
Imagecreatefromjpeg (): Creates a canvas and loads an image from a JPEG file or URL.
Imagecreatefrompng (): Creates a canvas and loads an image from a PNG file or URL.
Imagecreatefromwbmp (): Creates a canvas and loads an image from a WBMP file or URL.
Imagecreatefromstring (): Creates a canvas and creates an image from the image stream in the string.

Syntax:

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 (150, 30); $ bg = imagecolorallocate ($ im, 255,255,255); $ text_color = imagecolorallocate ($ im, 0, 0,255 ); // fill in the background color imagefilledrectangle ($ im, 0, 0,150, 30, $ bg); // output the error message imagestring ($ im, 3, 5, 5, "Error loading image", $ text_color);} else {// output this image imagejpeg ($ im) ;}?>

In this example, we load and output the source image. Since PHP does not provide friendly error prompts for image creation errors, we have customized error processing information.

Prompt

For PHP-generated images, to be displayed directly on a common webpage rather than output through the header, use the following method:

 

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.