php tutorial graphics processing function imagetypes() imagecreatetruecolor() imagecreate()
//Determine whether the current gd library supports png
if(imagetypes() & img_png)
{
echo "png support is enabled";
}
else
{
echo "png support is disabled";
}
/*
int imagetypes (void)
This function returns the image format supported by the gd library associated with the current PHP version in the form of a bit field. The following results will be returned, img_gif | img_jpg | img_png | img_wbmp | img_xpm. For example to check if png
*/
//Create image
$img=imagecreatetruecolor(300,200);
//Get image width
echo imagesx($img);
/*
Let’s see an example
*///Create a 100x30 image
$im=imagecreate(100,30);
//White background and blue text
$bg=imagecolorallocate($im,255,255,255);
$textcolor=imagecolorallocate($im,0,0,255);
//Write the string in the upper left corner of the image
imagestring($im,5,0,0,"hello world!",$textcolor);
//Output image
header("content-type: image/png");
imagepng($im);
/*
If you want to create a png image *transparent* where the background is completely transparent and all the action happens within the draw, other than that, then do the following:
*/
$png = imagecreatetruecolor(800, 600);
imagesavealpha($png, true);
$trans_colour = imagecolorallocatealpha($png, 0, 0, 0, 127);
Imagefill($png, 0, 0, $trans_colour);
$red = imagecolorallocate($png, 255, 0, 0);
Imagefilledellips tutorial tutorial e($png, 400, 300, 400, 300, $red);
header("content-type: image/png");
Imagepng($png);