Create an image using php
⧉ Category: Programing | 📅 Date: 17 Mar 2024 | अ🉀 Translation:


header("Content-type: image/png");
Now we can use imagecreatetruecolor function to create an image and give it width of 300 and height of 200. Also to publish the image, we use imagepng function because the image we are making is PNG type. You can change it to jpeg, gif or any other image format if needed. but you will have to modify the header as well.
$image = imagecreatetruecolor(300, 200);
imagepng($image);
Some other functions we use in the code
imagecolorallocate : assign a color
imagefill : fill the image with color
imagefilledellipse : create a filled circle
imagefilledarc : create a filled arc
imagestring : draw a word;
formats
imagecolorallocate(target image, Red, Green, Blue);
imagefill(target image, x position, y position, color);
imagefilledellipse(target image, x position, y position, width, height, color);
imagefilledarc(target image, x position, y position, width, height, starting angle, ending angle, color, Type of arc);
imagestring(target image, font size, x position, y position, Text, color);
RGB Red, Green, Blue color codes can be 0-255, X, Y positions can be any number but exceeding the Target image's width and height will be out of bounds, angle can be 0-360, color can be added by using imagecolorallocate function, Type of arc can be 1-5, and font size can be 1-5.
Instead of trying to learn these functions, copy and paste the code from below and try experimenting with it by changing its values. You can understand it quickly.
Here is the full code
header("Content-type: image/png");
$image = imagecreatetruecolor(300, 200);
$bg = imagecolorallocate($image, 255, 255, 255);
$color1 = imagecolorallocate($image, 0,0,255);
$color2 = imagecolorallocate($image, 255, 0, 0);
imagefill($image, 0, 0, $bg);
imagefilledellipse($image, 150, 100, 150, 150, $color2);
imagefilledellipse($image, 110, 90, 20, 20, $bg);
imagefilledellipse($image, 180, 90, 20, 20, $bg);
imagefilledarc($image, 150, 130, 50, 50, -20, 200, $bg, 4);
imagestring($image, 5, 130, 180, "hello", $color1);
imagepng($image);
imagedestroy($image);
Comments
Please solve above captcha based on the hint given..