This paper analyzes the Imagecreatefrom_gif_jpeg_png series function usage of PHP loading image. Share to everyone for your reference, specific 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, return an image resource successfully, and return an empty string if it fails.
The series functions are:
Imagecreatefromgif (): Creates a canvas and loads an image from a GIF file or URL address
Imagecreatefromjpeg (): Creates a canvas and loads an image from a JPEG file or URL address
Imagecreatefrompng (): Creates a canvas and loads an image from a PNG file or URL address
Imagecreatefromwbmp (): Creates a canvas and loads an image from a WBMP file or URL address
Imagecreatefromstring (): Creates a canvas, and creates a 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 a picture
$im = @imagecreatefromjpeg ("images/flower_1.jpg");
Error handling
if (! $im) {
$im = Imagecreatetruecolor (from);
$BG = Imagecolorallocate ($im, 255, 255, 255);
$text _color = imagecolorallocate ($im, 0, 0, 255);
Fill background color
imagefilledrectangle ($im, 0, 0, $BG);
Output error messages in Images
imagestring ($im, 3, 5, 5, "Error loading image", $text _color);
Imagejpeg ($im);
>
In this example, we load and output the original image. Because PHP does not have friendly error prompts for image creation errors, we have customized error handling information.
Tips
For PHP-generated images, if you want to display them directly in the normal Web page rather than through the header output, you can invoke the following:
More about PHP Interested readers can view the site topics: "PHP graphics and pictures Operating skills summary", "PHP file Operation Summary", "PHP Array" operation Skills Encyclopedia, "PHP Basic Grammar Introductory Course", "PHP Operations and Operator Usage Summary", " Introduction to PHP object-oriented programming program, "PHP Network Programming Skills Summary", "PHP string (String) Usage Summary", "Php+mysql database Operation Tutorial" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design.