Solved

PHP - save imagettftext created as a image?

Posted on 2011-09-06
2
1,287 Views
Last Modified: 2012-05-12
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);
?>
0
Comment
Question by:sabecs
2 Comments
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 500 total points
ID: 36488123
I see you are using imagepng which will do it. You need to supply extra paramaters, for example

imagepng($im, $newFilePath, $quality);


See http://www.php.net/imagepng for more details
0
 

Author Closing Comment

by:sabecs
ID: 36488313
Thanks  bportlock.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now