<?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>Steve&#039;s Blog &#187; imaging</title>
	<atom:link href="http://crindigo.com/blog/tag/imaging/feed/" rel="self" type="application/rss+xml" />
	<link>http://crindigo.com/blog</link>
	<description>Escapades of a web programmer</description>
	<lastBuildDate>Thu, 24 Jun 2010 00:33:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1-alpha</generator>
		<item>
		<title>Ancient Image Class</title>
		<link>http://crindigo.com/blog/2010/06/ancient-image-class/</link>
		<comments>http://crindigo.com/blog/2010/06/ancient-image-class/#comments</comments>
		<pubDate>Tue, 08 Jun 2010 01:33:19 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[imaging]]></category>

		<guid isPermaLink="false">http://crindigo.com/blog/?p=81</guid>
		<description><![CDATA[This is a really old image library/class thing I wrote back in Summer 2006 while working with Jeremy and his company. I believe it was originally written in PHP4 and updated to PHP5 a month or two after the original &#8230; <a href="http://crindigo.com/blog/2010/06/ancient-image-class/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This is a really old image library/class thing I wrote back in Summer 2006 while working with <a href="http://jeremyprivett.com/">Jeremy</a> and his company. I believe it was originally written in PHP4 and updated to PHP5 a month or two after the original was written. There are some features, like drawing rotated images/ellipses, that were commented away due to them not working on PHP4, but may work now if someone dares to try. <img src='http://crindigo.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  The comments are fairly plentiful, and I&#8217;m feeling lazy, so it shouldn&#8217;t need a manual to get started (besides, I haven&#8217;t used it in years either).</p>
<p>The code is located at <a href="http://gist.github.com/429474">http://gist.github.com/429474</a></p>
]]></content:encoded>
			<wfw:commentRss>http://crindigo.com/blog/2010/06/ancient-image-class/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Obfuscated Cake</title>
		<link>http://crindigo.com/blog/2009/12/obfuscated-cake/</link>
		<comments>http://crindigo.com/blog/2009/12/obfuscated-cake/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 03:52:25 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[imaging]]></category>
		<category><![CDATA[obfuscated]]></category>

		<guid isPermaLink="false">http://crindigo.com/blog/?p=32</guid>
		<description><![CDATA[Almost forgot about this one. I wrote it back in June 2008 for Jeremy&#8217;s birthday since he was having a rough day. Like the heart, this is code in the shape of a birthday cake (well, as long as you &#8230; <a href="http://crindigo.com/blog/2009/12/obfuscated-cake/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Almost forgot about this one. I wrote it back in June 2008 for <a href="http://www.jeremyprivett.com/">Jeremy&#8217;s</a> birthday since he was having a rough day. Like the heart, this is code in the shape of a birthday cake (well, as long as you use some imagination <img src='http://crindigo.com/blog/wp-includes/images/smilies/icon_razz.gif' alt=':-P' class='wp-smiley' /> ) that draws a birthday cake. A chocolate one.</p>
<p>The code first draws the main cake rectangle. After that, it loops three times to draw the rectangles for the candlesticks, polygons for the flames, then orange circles with an alpha channel for the light. It finishes off with a series of lines whose lengths are determined by the sine function, used for the frosting.</p>
<p><a href="http://crindigo.com/birthday.php">Here&#8217;s the output.</a></p>
<pre class="brush: php;">
&lt;?php               header             ('Content'.
'-type:'.          'image/png'         );$f = 'im'.
'agecre'.          'atetrueco'.        'lor';$im=$f
(250,250);         $g='imagef'.        'illedrect'.
'angle';$g         ($im,10,120,        240,240,(630*
10000)+ 37         *100+44);for        ($i=0;$i&lt;3;$i
++){$x=60+         $i*60;$g($im        ,$x+2,50,$x+8,
120,0xeeeeee);$h=str_rot13('vzntrsvyyrqcbyltba');$h(
$im,array($x,50,$x+5,30,$x+10,50),3,0xc00000);$h($im,
array($x+2,50,$x+ 5,40,$x+8,50),3, 0xff8000);$h ($im,
array($x+3,50,$x+5,45,$x+7,50),3,0x0000ff);$el='ima'.
'gefilledellipse';$el($im,$x+5,40,40,40,0x48ffa000);}
$l='i'.'m'.'a'. 'g'.'e'.'l'.'in'.'e';$c=0xd0d0ff; for
($i=10;$i&lt;=240;$i++){$y=130+3* sin(($i-10)/2);$l($im,
$i,120,$i,$y,$c);}$p=strrev('egami').'png';$d='imag';
$d.='ede';$de='str';$d.=$de;$d.='oy';$p($im);$d($im);
</pre>
<p>Unobfuscated version:</p>
<pre class="brush: php;">
&lt;?php

header('Content-type: image/png');
$img = imageCreateTrueColor(250, 250);
imageFilledRectangle($img, 10, 120, 240, 240, 0x603000);

// loop through the 3 candles
for ($i = 0; $i &lt; 3; $i++) {
	$x = 60 + $i * 60;
	// candlestick, red flame, orange flame, blue flame, light
	imageFilledRectangle($img, $x + 2, 50, $x + 8, 120, 0xEEEEEE);
	imageFilledPolygon($img, array($x, 50, $x + 5, 30, $x + 10, 50), 3, 0xC00000);
	imageFilledPolygon($img, array($x + 2, 50, $x + 5, 40, $x + 8, 50), 3, 0xFF8000);
	imageFilledPolygon($img, array($x + 3, 50, $x + 5, 45, $x + 7, 50), 3, 0x0000FF);
	imageFilledEllipse($img, $x + 5, 40, 40, 40, 0x48FFA000);
}

// frosting
for ($i = 10; $i &lt;= 240; $i++) {
	$y = 130 + 3 * sin(($i - 10) / 2);
	imageLine($img, $i, 120, $i, $y, 0xD0D0FF);
}

imagePNG($img);
imageDestroy($img);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://crindigo.com/blog/2009/12/obfuscated-cake/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Voronoi Diagram</title>
		<link>http://crindigo.com/blog/2009/12/voronoi-diagram/</link>
		<comments>http://crindigo.com/blog/2009/12/voronoi-diagram/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 03:28:44 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[imaging]]></category>

		<guid isPermaLink="false">http://crindigo.com/blog/?p=23</guid>
		<description><![CDATA[Here&#8217;s another imaging example done with PHP &#8211; a Voronoi Diagram. I don&#8217;t exactly remember when I wrote this, but it was some time this year. The code doesn&#8217;t use any fancy, ultra-efficient algorithm, so it takes several seconds to &#8230; <a href="http://crindigo.com/blog/2009/12/voronoi-diagram/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s another imaging example done with PHP &#8211; a <a href="http://en.wikipedia.org/wiki/Voronoi_diagram">Voronoi Diagram</a>. I don&#8217;t exactly remember when I wrote this, but it was some time this year. The code doesn&#8217;t use any fancy, ultra-efficient algorithm, so it takes several seconds to make a medium-size image on my (old) computer.</p>
<p>The algorithm used is very simple: Iterate through each pixel of the image, and find which reference point it is closest to. Then, set the color of the pixel to the color of the reference point.</p>
<p><a href="http://crindigo.com/code/php/voronoi.phps">Here&#8217;s the code.</a></p>
<div id="attachment_27" class="wp-caption alignnone" style="width: 260px"><a href="http://crindigo.com/blog/wp-content/uploads/2009/12/voronoi.png"><img src="http://crindigo.com/blog/wp-content/uploads/2009/12/voronoi.png" alt="Voronoi Diagram" title="Voronoi Diagram" width="250" height="250" class="size-full wp-image-27" /></a><p class="wp-caption-text">Voronoi Diagram with 50 Colors</p></div>
]]></content:encoded>
			<wfw:commentRss>http://crindigo.com/blog/2009/12/voronoi-diagram/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Random Line Generator</title>
		<link>http://crindigo.com/blog/2009/12/random-line-generator/</link>
		<comments>http://crindigo.com/blog/2009/12/random-line-generator/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 04:20:56 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[imaging]]></category>

		<guid isPermaLink="false">http://crindigo.com/blog/?p=17</guid>
		<description><![CDATA[Another repost, though a bit more fresh &#8211; it was originally posted in September 2007. JS Random Line Generator The random line generator uses the HTML5 canvas element to draw a series of connected lines, with a large variety of &#8230; <a href="http://crindigo.com/blog/2009/12/random-line-generator/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Another repost, though a bit more fresh &#8211; it was originally posted in September 2007.</p>
<p><a href="http://crindigo.com/randomline.html">JS Random Line Generator</a></p>
<p>The random line generator uses the HTML5 canvas element to draw a series of connected lines, with a large variety of options. You can choose where to start drawing, the initial angle, the line lengths, how far the lines can turn left or right, the number of lines, the line colors, the line width, and the background color. In addition, if you are using a modern browser that supports canvas&#8217;s toDataURL() method, you can save the image to your computer (otherwise you&#8217;ll likely have to Print Screen it).</p>
<p>One nifty thing you can do with the line colors is cycle through a gradient. By using a <a href="http://www.vex.net/~x/xfade/advanced.html">color fade generator</a> and selecting &#8220;show HTML codes&#8221; then the color sequence, you can copy and paste the list into the line colors box. Additionally, it accepts code in HTML (font/color, and span/style), so if somebody has a nice gradient on a website, chances are you can copy/paste the source and use it.</p>
<p>Here&#8217;s an example image that I created:<br />
<div id="attachment_25" class="wp-caption alignnone" style="width: 510px"><a href="http://crindigo.com/blog/wp-content/uploads/2009/12/randomline2.png"><img src="http://crindigo.com/blog/wp-content/uploads/2009/12/randomline2.png" alt="Random Line Example" title="Random Line Example" width="500" height="500" class="size-full wp-image-25" /></a><p class="wp-caption-text">Random line with black-white gradient</p></div></p>
<p>For people with older browsers, there is a <a href="http://crindigo.com/RandomLine.php">PHP version</a> with slightly reduced functionality. It has a max color limit of 30, and no line width setting. It does allow you to turn anti-aliasing on and off, though. The source for the PHP version can be found <a href="http://crindigo.com/code/php/RandomLine.phps">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://crindigo.com/blog/2009/12/random-line-generator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Obfuscated Heart</title>
		<link>http://crindigo.com/blog/2009/12/obfuscated-heart/</link>
		<comments>http://crindigo.com/blog/2009/12/obfuscated-heart/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 03:42:25 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[imaging]]></category>
		<category><![CDATA[obfuscated]]></category>

		<guid isPermaLink="false">http://crindigo.com/blog/?p=9</guid>
		<description><![CDATA[I originally wrote this in July 2006 for PHP image generation practice, but decided to repost it. Basically, it&#8217;s code written in the shape of a heart, that draws a heart. Going more in-depth, the code uses polar coordinates to &#8230; <a href="http://crindigo.com/blog/2009/12/obfuscated-heart/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I originally wrote this in July 2006 for PHP image generation practice, but decided to repost it. Basically, it&#8217;s code written in the shape of a heart, that draws a heart.</p>
<p>Going more in-depth, the code uses polar coordinates to draw a cardioid-like figure, which are converted into cartesian coordinates via the cfp_x() and cfp_y() functions. The new coordinates are then used in PHP&#8217;s <a href="http://php.net/imagefilledpolygon">imageFilledPolygon()</a> function to draw the shape.</p>
<p>The formula to create the heart is simply done by setting the radius equal to the angle, rotated 90 degrees so that the shape is right-side up. So, at 0, the coordinates are at the origin &#8211; the sharp valley of the heart. At 180, the coordinates are at the bottom point of the heart.</p>
<p>View the output <a href="http://crindigo.com/code/php/heart.php">here</a>.</p>
<pre class="brush: php;">
           function                cfp_x($ox,
     $a,$d) {return ($ox+    round((cos (deg2rad($a
   ))*$d)));}function cfp_y($oy, $a, $d){return ($oy+
  round((sin(deg2rad($a)) * $d)));} $crd=array();$ct=0;
 $im=imageCreateTrueColor(250,250);$c=imageColorAllocate
 ($im,255,0,0);header(&quot;Content-type: image/png&quot;);for($i
  =-180;$i&lt;180;$i++){$crd[]=cfp_x(125,$i -90,abs($i));
    $crd[] = cfp_y(50, $i - 90, abs($i) ); $ct++;}
        imageFilledPolygon($im, $crd,$ct,$c);
            imagePNG($im);imageDestroy
                      (($im));
                         ?&gt;
</pre>
<p>Unobfuscated version:</p>
<pre class="brush: php;">
function cfp_x($origin_x, $angle, $radius) {
    return $origin_x + round(cos(deg2rad($angle)) * $radius);
}
function cfp_y($origin_y, $angle, $radius) {
    return $origin_y + round(sin(deg2rad($angle)) * $radius);
}

$coords = array();
$num_pts = 0;
$img = imageCreateTrueColor(250, 250);

for ($i = -180; $i &lt; 180; $i++) {
    $coords[] = cfp_x(125, $i - 90, abs($i));
    $coords[] = cfp_y(50, $i - 90, abs($i));
    $num_pts++;
}

imageFilledPolygon($img, $coords, $num_pts, 0xFF0000);
header('Content-type: image/png');
imagePNG($img);
imageDestroy($img);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://crindigo.com/blog/2009/12/obfuscated-heart/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
