Solved

PHP - save imagettftext created as a image?

Posted on 2011-09-06
2
1,270 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

708 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

13 Experts available now in Live!

Get 1:1 Help Now