PHP imagegd2 Function: Output GD2 Images to Browser or File
The article explains the PHP imagegd2() function, detailing its parameters, return values, and usage example for outputting GD2 images either directly to the browser or saving them to a file, including optional chunk size and type settings.
Function Overview
The imagegd2() function outputs a GD image to a specified filename or directly to the browser if the filename is omitted or set to NULL. It can also accept optional chunk size and image type parameters.
Parameters
image : The GD image resource to be output.
filename : Path where the image should be saved; if omitted or NULL, the raw image stream is sent to the browser.
chunk_size : (Optional) Size of data chunks.
type : (Optional) Either IMG_GD2_RAW or IMG_GD2_COMPRESSED. Default is IMG_GD2_RAW.
Return Value
Returns TRUE on success and FALSE on failure.
Example Usage
<?php
// Create a blank image and add some text
$im = imagecreatetruecolor(120,20);
$text_color = imagecolorallocate($im,233,14,91);
imagestring($im,1,5,5,"A Simple Text String",$text_color);
// Output the image
imagegd2($im);
// Free up memory
imagedestroy($im);
?>Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
