stil / gd-text

PHP class making it easy to type text on pictures. Supports multi-lined text, horizontal and vertical alignment.
401 stars 130 forks source link

No example how to use it #1

Closed onigetoc closed 10 years ago

onigetoc commented 10 years ago

You script look interesting but there's no example how to use it.

Can you provide some example?

stil commented 10 years ago
<?php
require './vendor/autoload.php';

use GDText\Box;

$im = imagecreatetruecolor(500, 500); // create image
$backgroundColor = imagecolorallocate($im, 64, 86, 221);
imagefill($im, 0, 0, $backgroundColor); // fill image with color

$box = new Box($im);
$box->setFontFace('BebasNeue.otf'); // assuming you have this font http://www.dafont.com/bebas-neue.font
$box->setFontColor([235, 138, 34]); // RGB
$box->setTextShadow([50, 50, 50], 0, -1); // shadow color, x and y shift values
$box->setFontSize(50);
$box->setLeading(0.8);
$box->setBox(50, 50, 400, 400);
$box->setTextAlign('center', 'center'); // x and y align

$box->draw("Lorem Ipsum\nDolor\nSit Amet");

header("Content-type: image/png");
imagepng($im);
onigetoc commented 10 years ago

Thank you but i have php error on line 13 and 14

stil commented 10 years ago

It's because you have PHP older than 5.4. In 5.3 and lower you must use array() instead of []