<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Vision Master Designs &#187; language php</title>
	<atom:link href="http://visionmasterdesigns.com/tag/language-php/feed/" rel="self" type="application/rss+xml" />
	<link>http://visionmasterdesigns.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Thu, 29 Oct 2009 20:00:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Tutorial : Convert Text into transparent PNG Image using PHP</title>
		<link>http://visionmasterdesigns.com/tutorial-convert-text-into-transparent-png-image-using-php/</link>
		<comments>http://visionmasterdesigns.com/tutorial-convert-text-into-transparent-png-image-using-php/#comments</comments>
		<pubDate>Sat, 22 Nov 2008 19:39:35 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[PHP & MySQL]]></category>
		<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[language php]]></category>

		<guid isPermaLink="false">http://www.visionmasterdesigns.com/?p=957</guid>
		<description><![CDATA[This tutorial will help you write text on a background and output as an image using the power of PHP. This is useful during those scenarios when you want to display text using a particular font (which isn`t web friendly i.e the text won`t be displayed with the same font in other&#8217;s computer). I have [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 0 0 0.6em 0.6em;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fvisionmasterdesigns.com%2Ftutorial-convert-text-into-transparent-png-image-using-php%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fvisionmasterdesigns.com%2Ftutorial-convert-text-into-transparent-png-image-using-php%2F&amp;source=rowoot&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>This tutorial will help you write text on a background and output as an image using the power of PHP. This is useful during those scenarios when you want to display text using a particular font (which isn`t web friendly i.e the text won`t be displayed with the same font in other&#8217;s computer). I have used this technique to display the number of RSS subscribers (top-right). So its pretty simple and very basic.</p>
<p>Click <a href="http://visionmasterdesigns.com/demo/image/imagegenerate.html">Here</a> for a Demo.</p>
<p align="center">
<img src="http://visionmasterdesigns.com/demo/image/image.php?text=Dynamic PNG Generation" alt="Transparent PNG text" />
</p>
<p><span id="more-957"></span></p>
<h4>STEP 1 : Create PHP file and Define Headers</h4>
<p>First we create a PHP file. Lets call it myimage.php. Now we don`t want the browser to understand myimage.php as an image since we`ll be generating the image using this file. So we need to define the headers in this file which will tell the browser that it is an image.</p>
<pre class="brush: php">
&lt;?php
//HEADERS
header(&quot;Content-type: image/png&quot;); //Picture Format
header(&quot;Expires: Mon, 01 Jul 2003 00:00:00 GMT&quot;); // Past date
header(&quot;Last-Modified: &quot; . gmdate(&quot;D, d M Y H:i:s&quot;) . &quot; GMT&quot;); // Consitnuously modified
header(&quot;Cache-Control: no-cache, must-revalidate&quot;); // HTTP/1.1
header(&quot;Pragma: no-cache&quot;); // NO CACHE

//image generation code

?&gt;
</pre>
<h4>STEP 2 : The entire code !</h4>
<p>The entire code is here, the comments should help tell what each function is doing.</p>
<pre class="brush: php">
&lt;?php

header(&quot;Content-type: image/png&quot;); //Picture Format
header(&quot;Expires: Mon, 01 Jul 2003 00:00:00 GMT&quot;); // Past date
header(&quot;Last-Modified: &quot; . gmdate(&quot;D, d M Y H:i:s&quot;) . &quot; GMT&quot;); // Consitnuously modified
header(&quot;Cache-Control: no-cache, must-revalidate&quot;); // HTTP/1.1
header(&quot;Pragma: no-cache&quot;); // NO CACHE

/*image generation code*/
//create Image of size 350px x 75px
$bg = imagecreatetruecolor(350, 75);

//This will make it transparent
imagesavealpha($bg, true);

$trans_colour = imagecolorallocatealpha($bg, 0, 0, 0, 127);
imagefill($bg, 0, 0, $trans_colour);

//Text to be written
$helloworld = isset($_GET[&#039;text&#039;]) ? $_GET[&#039;text&#039;] : &quot;hello World&quot;;

// White text
$white = imagecolorallocate($bg, 255, 255, 255);
// Grey Text
$grey = imagecolorallocate($bg, 128, 128, 128);
// Black Text
$black = imagecolorallocate($bg, 0,0,0);

$font = &#039;arial.ttf&#039;; //path to font you want to use
$fontsize = 20; //size of font

//Writes text to the image using fonts using FreeType 2
imagettftext($bg, $fontsize, 0, 20, 20, $grey, $font, $helloworld);

//Create image
imagepng($bg);

//destroy image
ImageDestroy($bg);
?&gt;
</pre>
<p>Well thats the source code if you want to generate alpha png images using PHP. Its pretty simple. This isn`t that tough, but there might be some people new to PHP who might want to know.</p>
]]></content:encoded>
			<wfw:commentRss>http://visionmasterdesigns.com/tutorial-convert-text-into-transparent-png-image-using-php/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
	</channel>
</rss>
