<?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>Compiled Thoughts by John Ciacia &#187; gd</title>
	<atom:link href="http://www.johnciacia.com/tag/gd/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.johnciacia.com</link>
	<description>Science, Technology, and Beyond</description>
	<lastBuildDate>Fri, 06 Jan 2012 15:46:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Basic OCR</title>
		<link>http://www.johnciacia.com/2010/01/04/basic-ocr/</link>
		<comments>http://www.johnciacia.com/2010/01/04/basic-ocr/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 03:40:11 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[captcha]]></category>
		<category><![CDATA[gd]]></category>

		<guid isPermaLink="false">http://www.johnciacia.com/?p=454</guid>
		<description><![CDATA[This is a very basic optical character recognition script written in PHP. This is untested and serves merely a proof of concept. As noted in the comments, adjusting the sample size can improve results, since with a large sample size on a small image there can be many collisions. A database is needed to compare [...]]]></description>
			<content:encoded><![CDATA[<p>This is a very basic optical character recognition script written in PHP. This is untested and serves merely a proof of concept. As noted in the comments, adjusting the sample size can improve results, since with a large sample size on a small image there can be many collisions. A database is needed to compare output results of this script with known values.</p>
<p>[code lang="PHP"]<?php</p>
<p>/* create a test image */<br />
$im = @imagecreate(100, 20) or die("Cannot Initialize new GD image stream");<br />
$background_color = imagecolorallocate($im, 255, 255, 255);<br />
$text_color = imagecolorallocate($im, 0, 0, 0);<br />
imagestring($im, 1, 5, 5,  "Hello, World!", $text_color);</p>
<p>/***<br />
 * Assumptions:<br />
 *   A monochrome image where characters are black<br />
 *   A single character is connected<br />
 *   Characters are disjointed by white space<br />
 */</p>
<p>$width = imagesx($im);<br />
$height = imagesy($im);</p>
<p>/***<br />
 * Notes:<br />
 *   The smaller the sample size the more accurate it will be,<br />
 *   however, it will take longer. Larger images can use a larger<br />
 *   sample size wihtout compromizing much accuracy.<br />
 */<br />
$x_sample = 1;<br />
$y_sample = 1;</p>
<p>$last = 0;<br />
for($i = 0; $i < $width; $i++) {<br />
    $col = array();</p>
<p>    for($j = 0; $j < $height; $j++) {<br />
        $col[$j] = imagecolorat($im, $i, $j);<br />
    }</p>
<p>    if(($current = array_sum($col)) > 0) {<br />
        if($last == 0) {<br />
            $l = 0;<br />
        }</p>
<p>        for($k = 0; $k < $height; $k++) {<br />
            if(($l % $x_sample) == 0) {<br />
                if(($k % $y_sample) == 0) {<br />
                    $sample .= $col[$k];<br />
                }<br />
            }<br />
        }</p>
<p>        $l++;<br />
        $last = $current;<br />
    } else {<br />
        $last = 0;<br />
    }</p>
<p>    if(!empty($sample) &#038;&#038; $last == 0) {<br />
        echo $sample . "\n";<br />
        $sample = "";<br />
    }<br />
}<br />
?>[/code]</p>
<p>Output (each line represents a character)</p>
<div class="quote">00000011111100000000000000001000000000000000000010000000000000000011111100000000<br />
00000000011000000000000000001011000000000000000011010000000000000000010100000000<br />
000000100001000000000000001111110000000000000000000100000000<br />
000000100001000000000000001111110000000000000000000100000000<br />
00000000011000000000000000001001000000000000000010010000000000000000011000000000<br />
000000000001000000000000000001100000000000000000010000000000<br />
00000011111100000000000000000110000000000000000001100000000000000011111100000000<br />
00000000011000000000000000001001000000000000000010010000000000000000011000000000<br />
00000000111100000000000000000100000000000000000010000000000000000000010000000000<br />
000000100001000000000000001111110000000000000000000100000000<br />
00000000011000000000000000001001000000000000000010100000000000000011111100000000<br />
00000001110100000000</div>
]]></content:encoded>
			<wfw:commentRss>http://www.johnciacia.com/2010/01/04/basic-ocr/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Using PHP and GD to add border to text</title>
		<link>http://www.johnciacia.com/2010/01/04/using-php-and-gd-to-add-border-to-text/</link>
		<comments>http://www.johnciacia.com/2010/01/04/using-php-and-gd-to-add-border-to-text/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 23:41:03 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[border]]></category>
		<category><![CDATA[gd]]></category>
		<category><![CDATA[image border]]></category>
		<category><![CDATA[imagettf]]></category>
		<category><![CDATA[stroke]]></category>
		<category><![CDATA[text]]></category>
		<category><![CDATA[text border]]></category>

		<guid isPermaLink="false">http://www.johnciacia.com/?p=449</guid>
		<description><![CDATA[[code lang="PHP"][/code]]]></description>
			<content:encoded><![CDATA[<p>[code lang="PHP"]<?php<br />
/**<br />
 * Writes the given text with a border into the image using TrueType fonts.<br />
 * @author John Ciacia<br />
 * @param image An image resource<br />
 * @param size The font size<br />
 * @param angle The angle in degrees to rotate the text<br />
 * @param x Upper left corner of the text<br />
 * @param y Lower left corner of the text<br />
 * @param textcolor This is the color of the main text<br />
 * @param strokecolor This is the color of the text border<br />
 * @param fontfile The path to the TrueType font you wish to use<br />
 * @param text The text string in UTF-8 encoding<br />
 * @param px Number of pixels the text border will be<br />
 * @see http://us.php.net/manual/en/function.imagettftext.php<br />
 */<br />
function imagettfstroketext(&#038;$image, $size, $angle, $x, $y, &#038;$textcolor, &#038;$strokecolor, $fontfile, $text, $px) {</p>
<p>    for($c1 = ($x-abs($px)); $c1 <= ($x+abs($px)); $c1++)<br />
        for($c2 = ($y-abs($px)); $c2 <= ($y+abs($px)); $c2++)<br />
            $bg = imagettftext($image, $size, $angle, $c1, $c2, $strokecolor, $fontfile, $text);</p>
<p>   return imagettftext($image, $size, $angle, $x, $y, $textcolor, $fontfile, $text);<br />
} [/code]</p>
<p>[code lang="PHP"]<?php<br />
$img = imagecreatefrompng("/home/john/Desktop/test.png");<br />
$font_color = imagecolorallocate($img, 0, 0, 0);<br />
$stroke_color = imagecolorallocate($img, 255, 0, 0);<br />
imagettfstroketext($img, 10, 0, 10, 50, $font_color, $stroke_color, "abstract.ttf", "Hello, World!", 2);<br />
?>[/code]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johnciacia.com/2010/01/04/using-php-and-gd-to-add-border-to-text/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Basic CAPTCHA</title>
		<link>http://www.johnciacia.com/2010/01/04/basic-captcha/</link>
		<comments>http://www.johnciacia.com/2010/01/04/basic-captcha/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 23:01:18 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[captcha]]></category>
		<category><![CDATA[gd]]></category>

		<guid isPermaLink="false">http://www.johnciacia.com/?p=443</guid>
		<description><![CDATA[Very basic code demonstrating the use of the GD library by creating a simple CAPTCHA. [code lang="PHP"][/code]]]></description>
			<content:encoded><![CDATA[<p>Very basic code demonstrating the use of the GD library by creating a simple CAPTCHA.<br />
[code lang="PHP"]<?php<br />
function randomString($length){<br />
    $pattern = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";<br />
    if(empty($length)){<br />
        $length = "10";<br />
    }</p>
<p>    for($i=0; $i<$length; $i++){<br />
        $string .= $pattern{rand(0,61)};<br />
    }</p>
<p>    return $string;<br />
}</p>
<p>function captcha() {<br />
    header("Content-type: image/png");<br />
    $im = @imagecreate(100, 50) or die("Cannot Initialize new GD image stream");<br />
    $background_color = imagecolorallocate($im, 0, 0, 0);<br />
    $text_color = imagecolorallocate($im, 255, 0, 0);<br />
    $string = randomString();<br />
    imagestring($im, 10, 5, 5,  $string, $text_color);<br />
    imagepng($im);<br />
    imagedestroy($im);<br />
}</p>
<p>captcha();<br />
?>[/code]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johnciacia.com/2010/01/04/basic-captcha/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>imagettftext only displays yellow text</title>
		<link>http://www.johnciacia.com/2009/05/09/imagettftext-only-displays-yellow-text/</link>
		<comments>http://www.johnciacia.com/2009/05/09/imagettftext-only-displays-yellow-text/#comments</comments>
		<pubDate>Sat, 09 May 2009 23:44:42 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[gd]]></category>
		<category><![CDATA[imagettftext]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[yellow]]></category>

		<guid isPermaLink="false">http://www.johnciacia.com/?p=73</guid>
		<description><![CDATA[Lately I have been doing some work with the PHP GD library. I wanted to put text on an image so I naturally used imagettftext(). I started by copying the example code provided by the manual and intended on modifying the code to fit my needs. When I executed the code my my browser, the [...]]]></description>
			<content:encoded><![CDATA[<p>Lately I have been doing some work with the PHP GD library. I wanted to put text on an image so I naturally used <a href="http://us2.php.net/manual/en/function.imagettftext.php">imagettftext()</a>. I started by copying the example code provided by the manual and intended on modifying the code to fit my needs. When I executed the code my my browser, the text was yellow. I took a look at the code, and the results did not match. The text should have been black. I tried adjusting the imagecolorallocate parameters to reflect a different color. However, this time with I executed the code, no text showed up. It turns out I needed configure PHP &#8211;with-freetype-dir. After a recompile with the new configuration it worked fine.</p>
<blockquote><p>./configure \<br />
&#8211;disable-magic-quotes \<br />
&#8211;enable-bcmath \<br />
&#8211;enable-sockets \<br />
&#8211;with-mysq=/usr/local \<br />
&#8211;with-apxs2=/usr/local/apache2/bin/apxs \<br />
&#8211;with-curl \<br />
&#8211;with-gd \<br />
&#8211;with-freetype-dir=/usr<br />
&#8211;with-png \<br />
&#8211;with-jpeg \<br />
&#8211;with-ttf</p></blockquote>
<p><a href="http://www.johnciacia.com/wp-content/uploads/2009/05/text1.png"><img src="http://www.johnciacia.com/wp-content/uploads/2009/05/text1-300x22.png" alt="text1" title="text1" width="300" height="22" class="alignleft size-medium wp-image-75" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.johnciacia.com/2009/05/09/imagettftext-only-displays-yellow-text/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced

Served from: www.johnciacia.com @ 2012-02-05 10:27:03 -->
