Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once("../includes/config.php");
- require_once("../includes/class.textimage.php");
- $image = new TextImage();
- $image->color('000000');
- $image->text(!empty($_GET['text']) ? $_GET['text'] : 'Error:-missing-?text-arguement');
- header("Content-Type: image/png");
- /*header("Cache-Control: private, max-age=10800, pre-check=10800");
- header("Pragma: private");
- header("Expires: " . date(DATE_RFC822, strtotime("2 day")));
- if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
- header('Last-Modified: ' . $_SERVER['HTTP_IF_MODIFIED_SINCE'], true, 304);
- exit;
- }*/
- $image->output();
- ?>
- <?php
- class TextImage {
- function __construct() {
- $this->rotationDegree = 0;
- $this->font = '../fonts/arial.ttf';
- $this->size = (!empty($_GET['size']) ? $_GET['size'] : 150);
- $this->fontSize = 24/150*$this->size;
- $this->width = $this->size;
- $this->height = $this->size;
- }
- public function color($hex) {
- if ($hex[0] == '#') {
- $hex = substr($hex, 1);
- }
- if (strlen($hex) == 6) {
- list($r, $g, $b) = array($hex[0].$hex[1],
- $hex[2].$hex[3],
- $hex[4].$hex[5]);
- }
- else if (strlen($hex) == 3) {
- list($r, $g, $b) = array($hex[0].$hex[0], $hex[1].$hex[1], $hex[2].$hex[2]);
- }
- else {
- return false;
- }
- $this->fontColor = array(
- 'r' => hexdec($r),
- 'g' => hexdec($g),
- 'b' => hexdec($b)
- );
- }
- public function text($text) {
- $this->text = $text;
- }
- public function output() {
- $this->create();
- $this->fitText(urldecode($this->text));
- $this->display();
- $this->trash();
- }
- private function create() {
- $this->newImage = imagecreatetruecolor($this->width, $this->height);
- imagealphablending($this->newImage, false);
- imagesavealpha($this->newImage, true);
- $transparent = imagecolorallocatealpha($this->newImage, 255, 255, 255, 127);
- imagefilledrectangle($this->newImage, 0, 0, $this->width, $this->height, $transparent);
- }
- private function fitText($text) {
- imagealphablending($this->newImage, true);
- $num = count(explode('-', $this->text));
- $i = 1;
- foreach(explode('-', $text) as $word) {
- //$word = ucwords(strtolower($word));
- $xbox = imagettfbbox($this->fontSize, $this->rotationDegree, $this->font, $word);
- $x = ($this->width / 2) - (((($xbox[2] - $xbox[0]) + ($xbox[4] - $xbox[6])) / 2) / 2);
- $ybox = imagettfbbox($this->fontSize, $this->rotationDegree, $this->font, substr($word, 0, 1));
- $y = ($this->height / 2) - (((($ybox[3] - $ybox[5]) + ($ybox[1] - $ybox[7])) / 2) / 2) + ($ybox[3] - $ybox[5]);
- $color = imagecolorallocate($this->newImage, $this->fontColor['r'], $this->fontColor['g'], $this->fontColor['b']);
- $mod = $this->fontSize * 1.5;
- $y = $y + (($i - $num) * $mod) + ($num - 1) * $mod / 2;
- imagettftext($this->newImage, $this->fontSize, $this->rotationDegree, $x, $y, $color, $this->font, $word);
- $i++;
- }
- }
- private function display() {
- imagepng($this->newImage);
- }
- private function trash() {
- imagedestroy($this->newImage);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement