<?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>SmileyLover Blog &#187; dynamic image border</title>
	<atom:link href="http://blog.smileylover.com/tag/dynamic-image-border/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.smileylover.com</link>
	<description>Sharing Knowledge and Resources</description>
	<lastBuildDate>Sun, 04 Apr 2010 18:32:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Making Border Image with PHP and GD Library</title>
		<link>http://blog.smileylover.com/making-border-image-with-php-and-gd-library/</link>
		<comments>http://blog.smileylover.com/making-border-image-with-php-and-gd-library/#comments</comments>
		<pubDate>Mon, 27 Oct 2008 19:45:46 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[border image php gd]]></category>
		<category><![CDATA[dynamic image border]]></category>

		<guid isPermaLink="false">http://blog.smileylover.com/?p=107</guid>
		<description><![CDATA[As i know, PHP don&#8217;t have a function to create image border directly. So, how to make border image if PHP doesn&#8217;t have it? We must set manually using imageline function that already have in PHP since version 4 built in GD library. Before we go, we need to describe what is image border. That [...]


Related posts:<ol><li><a href='http://blog.smileylover.com/calculation-your-php-processing-time-using-simple-counter/' rel='bookmark' title='Permanent Link: Calculation Your PHP Processing Time Using Simple Counter'>Calculation Your PHP Processing Time Using Simple Counter</a></li>
<li><a href='http://blog.smileylover.com/making-wordpress-exchange-links-without-plugins/' rel='bookmark' title='Permanent Link: Making WordPress Exchange Links Without Plugins'>Making WordPress Exchange Links Without Plugins</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">As i know, PHP don&#8217;t have a function to create image border directly.  So, how to make border image if PHP doesn&#8217;t have it?  We must set manually using imageline function that already have in PHP since version 4 built in GD library.  Before we go, we need to describe what is image border. That is a line in all side of image, top, right, bottom, and left.</p>
<p style="text-align: justify;">Imageline function just allowed us to draw a single line between two given points.  The parameters are :</p>
<blockquote>
<p style="text-align: justify;">image<br />
An image resource, returned by one of the image creation functions, such as imagecreatetruecolor().</p>
<p>x1<br />
x-coordinate for first point</p>
<p>y1<br />
y-coordinate for first point</p>
<p>x2<br />
x-coordinate for second point</p>
<p>y2<br />
y-coordinate for second point</p>
<p>color<br />
The line color. A color identifier created with imagecolorallocate()</p></blockquote>
<p style="text-align: justify;"><span id="more-107"></span></p>
<p style="text-align: justify;">It will return true on success and false on failed.  Because we need four single line in all side of image to create border, so we need to create imageline function four times to cover top, right, bottom, and left.  This is the code (don&#8217;t forget to manually add <strong>&lt;?php</strong> and<strong> ?&gt;</strong> tag in begin and end code).</p>
<p style="text-align: justify;">

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p107code2'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1072"><td class="code" id="p107code2"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// create a 200*60 image</span>
<span style="color: #000088;">$im</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/imagecreate"><span style="color: #990000;">imagecreate</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">200</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// white background and blue text</span>
<span style="color: #000088;">$bg</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/imagecolorallocate"><span style="color: #990000;">imagecolorallocate</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">222</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">222</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">222</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$textcolor</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/imagecolorallocate"><span style="color: #990000;">imagecolorallocate</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// write the string</span>
<a href="http://www.php.net/imagestring"><span style="color: #990000;">imagestring</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">30</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;SmileyLover.Com&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$textcolor</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//border</span>
	<span style="color: #000088;">$bordercolors</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/imagecolorallocate"><span style="color: #990000;">imagecolorallocate</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Define border color  Yellow</span>
&nbsp;
	<span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$y</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$w</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/imagesx"><span style="color: #990000;">imagesx</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//get width image and decrease 1px or points ?</span>
	<span style="color: #000088;">$h</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/imagesy"><span style="color: #990000;">imagesy</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//get height image and decrease 1px or points ?</span>
	<a href="http://www.php.net/imageline"><span style="color: #990000;">imageline</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #000088;">$x</span><span style="color: #339933;">,</span><span style="color: #000088;">$y</span><span style="color: #339933;">,</span><span style="color: #000088;">$x</span><span style="color: #339933;">,</span><span style="color: #000088;">$y</span><span style="color: #339933;">+</span><span style="color: #000088;">$h</span><span style="color: #339933;">,</span><span style="color: #000088;">$bordercolors</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//left</span>
	<a href="http://www.php.net/imageline"><span style="color: #990000;">imageline</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #000088;">$x</span><span style="color: #339933;">,</span><span style="color: #000088;">$y</span><span style="color: #339933;">,</span><span style="color: #000088;">$x</span><span style="color: #339933;">+</span><span style="color: #000088;">$w</span><span style="color: #339933;">,</span><span style="color: #000088;">$y</span><span style="color: #339933;">,</span><span style="color: #000088;">$bordercolors</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//top</span>
	<a href="http://www.php.net/imageline"><span style="color: #990000;">imageline</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #000088;">$x</span><span style="color: #339933;">+</span><span style="color: #000088;">$w</span><span style="color: #339933;">,</span><span style="color: #000088;">$y</span><span style="color: #339933;">,</span><span style="color: #000088;">$x</span><span style="color: #339933;">+</span><span style="color: #000088;">$w</span><span style="color: #339933;">,</span><span style="color: #000088;">$y</span><span style="color: #339933;">+</span><span style="color: #000088;">$h</span><span style="color: #339933;">,</span><span style="color: #000088;">$bordercolors</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//right</span>
	<a href="http://www.php.net/imageline"><span style="color: #990000;">imageline</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #000088;">$x</span><span style="color: #339933;">,</span><span style="color: #000088;">$y</span><span style="color: #339933;">+</span><span style="color: #000088;">$h</span><span style="color: #339933;">,</span><span style="color: #000088;">$x</span><span style="color: #339933;">+</span><span style="color: #000088;">$w</span><span style="color: #339933;">,</span><span style="color: #000088;">$y</span><span style="color: #339933;">+</span><span style="color: #000088;">$h</span><span style="color: #339933;">,</span><span style="color: #000088;">$bordercolors</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//bottom</span>
	<span style="color: #666666; font-style: italic;">//end border</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// output the image</span>
<a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-type: image/png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a href="http://www.php.net/imagepng"><span style="color: #990000;">imagepng</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p style="text-align: justify;">This code only give you 1px line border with yellow color.  If you want to make a 10px border maybe you can loops this function and decrease a padding -1px for each loops <img src='http://blog.smileylover.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   Good luck &#8230; and this is the screenshot result.</p>
<p style="text-align: center;"><a href="http://www.imagecow.net/content.php?id=17714&#038;owner=ghprod" target="_blank"><br />
<img src="http://www.imagecow.net/preview/000017714.png" border="0" alt="Making Border Image with PHP and GD Library" title="Making Border Image with PHP and GD Library"></a></p>
<script type="text/javascript" class="owbutton" src="http://onlywire.com/btn/button_3793" title="Making Border Image with PHP and GD Library" url="http://blog.smileylover.com/making-border-image-with-php-and-gd-library/"></script>

<p>Related posts:<ol><li><a href='http://blog.smileylover.com/calculation-your-php-processing-time-using-simple-counter/' rel='bookmark' title='Permanent Link: Calculation Your PHP Processing Time Using Simple Counter'>Calculation Your PHP Processing Time Using Simple Counter</a></li>
<li><a href='http://blog.smileylover.com/making-wordpress-exchange-links-without-plugins/' rel='bookmark' title='Permanent Link: Making WordPress Exchange Links Without Plugins'>Making WordPress Exchange Links Without Plugins</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.smileylover.com/making-border-image-with-php-and-gd-library/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
