<?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; captcha</title>
	<atom:link href="http://www.johnciacia.com/tag/captcha/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>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>
	</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:54:46 -->
