Briefly we could say that:
The functions below are part of the GD library, which in turn was
developed for the processing of images. It is a library
open source for dynamic image creation by programmers.
The library creates PNG, JPEG and GIF, among other formats is usually
used to generate graphics, thumbnails, banners...
According to the official documentation, syntax:
resource imagecreatetruecolor ( int $width , int $height )
imagecreatetruecolor() returns an identifier (Resource) that represents a black image of the specified size. Summarizing:
imagecreatetruecolor ($largura ,$altura )
It takes two parameters, both are integers and returns a resource (Resource) that will be used by other methods to give continuity to the work of building an image.
See an example contained in official documentation:
<?php
header ('Content-Type: image/png');
$im = imagecreatetruecolor(120, 50)
or die('Cannot Initialize new GD image stream');
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, 'Issoé um teste', $text_color);
imagepng($im);
imagedestroy($im);
Explaining line by line:
- In the first line we set a header (header) for our page, that is, it will be a PNG
- We use imagecreatetruecolor() to create "base" image (Resource). Summarizing: we create a new true color image
- imagecolorallocate() allocates a color to an image
- imagestring() - Draw a string horizontally. This is where we pass the Resource, information of which font will be used, text string and font color
- imagepng() - Output a PNG image to browser or file
- imagedestroy() - Destroys the image ("wipes the memory")
It’s not yet clear to me how it works, what exactly it does and what it’s for. This information above is in the manual, as I said, I did not understand it very well. But, thank you very much, Fábio!
– Lucas de Carvalho
I complemented the previous post with an initial paragraph that can take but some questions.
– Fábio Jânio