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.