Fat Galah NewsFat Galah NewsFat Galah BlogFat Galah Client LoginFat Galah Client Contact Details
Fat Galah Internet Design Studios
103 Burrendah Road, Jindalee, QLD

Local call: 1800 99 33 99 (Australia Only)
International Ph: +61 7 3715 5999
Ph: 07 37155999

How to Convert Text to image and rotate

July 22nd, 2009

hosting starts from $20 per mthThis script will allow you to use a string and convert to image and rotate to any angle.

How to call

$text = ''Hello World';

$height = (strlen($text)*6.3)+2;

'<img id="testImg" alt="str2Img" src="/imagePng.php?text='.$text.'&height='.$height.'" />';

 

Place the script below into a page called imagePng.php

<?php
header("Content-type: image/png");
$height = $_GET['height'] == '' ? 400 : $_GET['height'];
//imagecreate(width, height);
$im = imagecreate(20, $height);

$green = imagecolorallocate($im, 0, 255, 0);
$red = imagecolorallocate($im, 255, 0, 0);
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
// imagefill($im, 0, 0, $white) background to the image
imagefill($im, 0, 0, $white);
// path to font
$font = $_SERVER['DOCUMENT_ROOT'].'/inc/fonts/arial.ttf'; // point to where it can find the True Type Font
$fontSize = 9 ;
$angle = 90;
// imagettftext($im, font size, angle, first point x, first point y, font colour, font family, string);
$text = $_GET['text']; // <img id="testImg" alt="btn" src="imagePng.php?text='.$text.'&height='.$height.'" />
//imagettftext($im, $fontSize, $angle, 15, ($height-5), $green, $font, $text);// if you want a shadow
imagettftext($im, $fontSize, $angle, 16, ($height-4), $black, $font, $text);
imagepng($im);
imagedestroy($im);
?>

 

Example - Click here
 

 

Leave A Comment:

Name:(Required)
XHTML ValidationCSS Validation