Skip to content

Instantly share code, notes, and snippets.

@gvgvgvijayan
Created December 22, 2019 05:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gvgvgvijayan/f15dd5e623a86b9ff9fd63598a33141d to your computer and use it in GitHub Desktop.
Save gvgvgvijayan/f15dd5e623a86b9ff9fd63598a33141d to your computer and use it in GitHub Desktop.
This is used to create basic filled rectangle image using PHP
<?php
$handle = imagecreatetruecolor(640, 480); #create a 640px wide 480px height image. Consider this like canvas to draw.
$green = imagecolorallocate($handle, 0, 255, 0); #assign green color
imagefilledrectangle($handle, 0, 0, 640, 480, $green); #Create filled rectangle with green color. Consider like this the shape drawn over the canvas.
# Jpeg conversion
header("Content-type: image/jpg");
imagejpeg($handle);
imagedestroy($handle); #Destroy the image handle to free up the resource
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment