Skip to content

Latest commit

 

History

History
38 lines (25 loc) · 1015 Bytes

how-to-set-background-color.md

File metadata and controls

38 lines (25 loc) · 1015 Bytes

How to set image background color

<?php

$im = imagecreatetruecolor(400, 300);

$c_green = imageColorAllocate($im, 46,204,64);
imagefill($im, 0, 0, $c_green);

$c_black = imageColorAllocate($im, 0,0,0);
imagefilledellipse($im, 200, 150, 100, 100, $c_black);

imagePng($im, '/tmp/image.png');
  • imagecreatetruecolor - creates true color lib:GD image object with specified width & height
  • imageColorAllocate - creates color object to later use in image
  • imagefill( - fills an entire image with a given color (green in our case)
  • imagePng - saves image in PNG format to the given path

group: background

Example:

<?php

$im = imagecreatetruecolor(400, 300);

$c_green = imageColorAllocate($im, 46,204,64);
imagefill($im, 0, 0, $c_green);

$c_black = imageColorAllocate($im, 0,0,0);
imagefilledellipse($im, 200, 150, 100, 100, $c_black);

imagePng($im, '/tmp/image.png');