jlaso/gd-wrapper

1.2 2016-10-02 15:35 UTC

This package is auto-updated.

Last update: 2024-10-15 11:04:13 UTC


README

image wrapper for PHP GD image

I created this package with the only intention to write compact and understandable scripts.

The idea is to use this:

$image = new Image(800, 600);

$image
    ->createColor('black', new Color(['R' => 0, 'G' => 0, 'B' => 0]))
    ->createColor('white', new Color(['R' => 255, 'G' => 255, 'B' => 255]))
    ->setColor('black')
    ->fill()
    ->setColor('white')
    ->fill(new Ellipse(new Point(400, 300), 200, 150))
    ->setColor('black')
    ->fill(new Circle(new Point(400, 300), 100))
    ->setColor('white')
    ->fill(new Circle(new Point(400, 300), 30))
    ->saveAsPng('/tmp/eye.png');

Instead of this:

$image = imagecreate(800, 600);

$black = imagecolorallocate($image, 0, 0, 0); 
$white = imagecolorallocate($image, 255, 255, 255);
 
imagefill($image, 0, 0, $black);
 
imagefilledellipse($image, 400, 300, 200, 150, $white);
imagefilledellipse($image, 400, 300, 100, 100, $black);
imagefilledellipse($image, 400, 300, 30, 30, $white);

imagepng($image, '/tmp/eye.png');

Example to write ellipses and circles:

php sample-eye.php && open /tmp/eye.png

Eye example

Example to write polygons:

php sample-penta.php && open /tmp/penta.png

Polygon example

Example to write text: take a look over sample-text.php

php sample-text.php && open /tmp/text.png

Text example

Example to use palette:

php sample-palette.php && open /tmp/palette.png

Palette example

Internal palettes had been imported from Jam3/nice-color-palettes

200 palettes

How to edit this file