Solved

PHP - save imagettftext created as a image?

Posted on 2011-09-06
2
1,321 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

756 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