Created
September 17, 2013 19:40
-
-
Save tomschlick/6599457 to your computer and use it in GitHub Desktop.
Simple example for creating an avatar based on the user's initials and a background color
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$string = 'TS'; | |
$imagine = new Imagine\Gd\Imagine(); | |
$size = new Imagine\Image\Box($imgsize, $imgsize); | |
$color = new Imagine\Image\Color('#333', 100); | |
$image = $imagine->create($size, $color); | |
$textImg = new Imagine\Gd\Font(DOCROOT.'/Arial.ttf', ceil($imgsize * .35), new Imagine\Image\Color('#fff')); | |
$YdescriptionBoxImg = $textImg->box($string, 0)->getHeight(); | |
$XdescriptionBoxImg = $textImg->box($string, 0)->getWidth(); | |
// set the point to start drawing text, depending on parent image width | |
$YCenter = ceil(($image->getSize()->getHeight() - $YdescriptionBoxImg) / 2); | |
$XCenter = ceil(($image->getSize()->getWidth() - $XdescriptionBoxImg) / 2); | |
$image->draw() | |
->text( | |
$string, | |
$textImg, | |
new Imagine\Image\Point($XCenter, $YCenter) | |
); | |
$image->show('jpg'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment