Link to home
Start Free TrialLog in
Avatar of sabecs
sabecs

asked on

PHP - save imagettftext created as a image?

Hi,
I have used the PHP script below to create and display a text image which works fine, but how do I then save this as actual image in my images folder and call it say “menu_button_12.png”

Thanks in advance for your feedback.

<?php
// Set the content-type
header('Content-Type: image/png');

// Create the image
$im = imagecreatetruecolor(200, 30);

// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$blue = imagecolorallocate($im, 40, 77, 146);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 200, 30, $blue);

// The text to draw
$text = 'News and Events';

$rootd = $_SERVER['DOCUMENT_ROOT']."/";
 
// Replace path by your own font path
$font = $root.'bisa_alternates.ttf';

// Add some shadow to the text
imagettftext($im, 24, 0, 11, 25, $grey, $font, $text);

// Add the text
imagettftext($im, 24, 0, 10, 24, $white, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>
ASKER CERTIFIED SOLUTION
Avatar of Beverley Portlock
Beverley Portlock
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sabecs
sabecs

ASKER

Thanks  bportlock.