Solved

PHP - save imagettftext created as a image?

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

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…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

813 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

8 Experts available now in Live!

Get 1:1 Help Now