Skip to content

Instantly share code, notes, and snippets.

@webD97
Created January 14, 2018 11:12
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 webD97/918013404806c77bb95f8b0191a68251 to your computer and use it in GitHub Desktop.
Save webD97/918013404806c77bb95f8b0191a68251 to your computer and use it in GitHub Desktop.
<?php
require_once("vendor/autoload.php");
use \Chameleon\Image;
use \Chameleon\Vector2;
use \Chameleon\Primitives\Rectangle;
use \Chameleon\Patterns\RGBNoise;
use \Chameleon\Patterns\BackgroundColor;
use \Chameleon\Colors\RGBColor;
use \Chameleon\Colors\RGBAColor;
// Create a new image
$image = Image::create(800, 600);
$image -> setBackgroundPattern(new RGBNoise(256));
// Create a 480*360px rectangle at position (40, 40) with semi-transparent lime as background and 20px black border
$rectangle1 = new Rectangle(new Vector2(40, 40), 480, 360);
$rectangle1BackgroundColor = new BackgroundColor(RGBAColor::lime() -> setAlpha(0.5));
$rectangle1BorderColor = new BackgroundColor(RGBColor::black());
$rectangle1 -> setBackgroundPattern($rectangle1BackgroundColor);
$rectangle1 -> setBorderPattern($rectangle1BorderColor);
$rectangle1 -> setBorderThickness(20);
// Create a 480*360px rectangle at position (280, 200) with semi-transparent maroon as background and 20px black border
$rectangle2 = new Rectangle(new Vector2(280, 200), 480, 360);
$rectangle2BackgroundColor = new BackgroundColor(RGBAColor::maroon() -> setAlpha(0.5));
$rectangle2BorderColor = new BackgroundColor(RGBColor::black());
$rectangle2 -> setBackgroundPattern($rectangle2BackgroundColor);
$rectangle2 -> setBorderPattern($rectangle2BorderColor);
$rectangle2 -> setBorderThickness(20);
// Draw the rectangles onto the image, $rectangle1 on top of $rectangle2
$image -> draw($rectangle2, $rectangle1);
// Output the image as PNG to the browser
header("Content-Type: image/png");
$image -> outputFile(IMG_PNG);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment