<?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>Random Renegade Bits</title>
	<atom:link href="http://rrbits.com/epb/feed/" rel="self" type="application/rss+xml" />
	<link>http://rrbits.com/epb</link>
	<description>Whatever comes to mind</description>
	<lastBuildDate>Wed, 29 Feb 2012 18:10:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Solved: GIMP Script-Fu Console Image ID</title>
		<link>http://rrbits.com/epb/2012/02/18/solved-gimp-script-fu-console-image-id/</link>
		<comments>http://rrbits.com/epb/2012/02/18/solved-gimp-script-fu-console-image-id/#comments</comments>
		<pubDate>Sun, 19 Feb 2012 02:09:59 +0000</pubDate>
		<dc:creator>epb</dc:creator>
				<category><![CDATA[Problems]]></category>
		<category><![CDATA[GIMP]]></category>

		<guid isPermaLink="false">http://rrbits.com/epb/?p=378</guid>
		<description><![CDATA[Problem: In experimenting with GIMP&#8217;s Script-Fu console, I could not figure out what values to feed in to scriptfu-rounded-corners (you know, to see what would happen) for image and drawable.  It was surprisingly simple though. Solution: Image ID: The image ID to use is displayed in the image window&#8217;s titlebar.  For example in &#8220;DianeLatest.jpg-4.0&#8221; the [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong> In experimenting with GIMP&#8217;s Script-Fu console, I could not figure out what values to feed in to scriptfu-rounded-corners (you know, to see what would happen) for image and drawable.  It was surprisingly simple though.</p>
<p><span id="more-378"></span></p>
<p><strong>Solution:</strong></p>
<p>Image ID: The image ID to use is displayed in the image window&#8217;s titlebar.  For example in &#8220;DianeLatest.jpg-<strong>4.0</strong>&#8221; the 4 is the image id.  The zero after the dot is the view id. (Might be useful to know, but I don&#8217;t know where you&#8217;d use it.)</p>
<p>Drawable: For simplicity&#8217;s sake when I was testing I just took the active drawable for the image, which you can get from (car (gimp-image-get-active-drawable [IMAGEID]) where the [IMAGEID] is replaced by the number you have for the image.</p>
<p><strong>Example:</strong> (script-fu-round-corners 1 (car (gimp-image-get-active-drawable 1)) 30 1 6 6 20 1 0)</p>
<p>This adds uses script-fu to add rounded corners, a drop-shadow, and a background layer to the active drawable (usually a layer) of image #1.  [Details: Corners have a radius of 30, shadow is offset 6 pixels to the right and 6 pixels down.  Shadow is blurred by 20 pixels.] (The color of the background layer appears to be taken from the currently active background color.)</p>
<p><strong>Notes:</strong></p>
<ol>
<li>The procedure browser shows a run-mode parameter for script-fu functions.  Don&#8217;t provide it, GIMP does that for you.</li>
<li>The (car &#8230;) function is required because the drawable parameter is expecting a number, but scheme functions return lists, so car is used to grab the first item from the list produced by gimp-image-get-active-drawable.</li>
<li>More specific to rounding corners this way: If you just want to round the corners of an image and have a transparent background, make sure there&#8217;s an alpha channel on the layer.  You can tell because it&#8217;s layer-name will be in bold if it does not have one.</li>
</ol>
<p>Here&#8217;s the result of the command I used as an example:</p>
<p><a href="http://rrbits.com/epb/files/2012/02/cordelia_sample.jpg" rel="lightbox[378]"><img class="alignnone size-full wp-image-382" title="Cordelia (Rounded Corner Sample)" src="http://rrbits.com/epb/files/2012/02/cordelia_sample.jpg" alt="" width="480" height="400" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://rrbits.com/epb/2012/02/18/solved-gimp-script-fu-console-image-id/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programmers should strive to Expand their Knowledge Bases</title>
		<link>http://rrbits.com/epb/2012/02/12/programmers-should-expand-knowledge-bases/</link>
		<comments>http://rrbits.com/epb/2012/02/12/programmers-should-expand-knowledge-bases/#comments</comments>
		<pubDate>Sun, 12 Feb 2012 06:56:41 +0000</pubDate>
		<dc:creator>epb</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://rrbits.com/epb/?p=369</guid>
		<description><![CDATA[With a title like &#8220;Programmers should strive to Expand their Knowledge Bases&#8221; you&#8217;d think I was referring to things like OOP, DRY, and other acronyms. However, I am not.  I&#8217;m not referring to learning additional programming languages or algorithms.  I&#8217;m talking about learning things from other domains entirely.  For example: science, knitting, cat photography, cat [...]]]></description>
			<content:encoded><![CDATA[<p>With a title like &#8220;Programmers should strive to Expand their Knowledge Bases&#8221; you&#8217;d think I was referring to things like OOP, DRY, and other acronyms. However, I am not.  I&#8217;m not referring to learning additional programming languages or algorithms.  I&#8217;m talking about learning things from other domains entirely.  For example: science, knitting, cat photography, cat photograph captioning and so on.  Honestly it&#8217;s a little bit of a weak point for me as well.  My grammar is a sore example.  Of course, I&#8217;m a mediocre-self-taught-programmer, so that is to be expected anyway.  First off there&#8217;s knowledge you can apply directly to programming problems.</p>
<p>Having knowledge about other fields allows you to more readily solve programming problems that involve those fields.  There&#8217;s even a term for this: domain knowledge or domain-specific knowledge.  You don&#8217;t necessarily need to be an expert either.  For example, with a base level of knowledge it become easier to get input from experts in a particular domain This is because you already have a base understanding.  There are two less-obvious benefits though, and I think they are more important.</p>
<p>First, having a broad base of knowledge to pull from enhances problem solving skills. I don&#8217;t have solid numbers to back this statement up though. (This is a blog, not a peer-reviewed paper.) Usually, when confronted with a problem in different domains the manner in which you come to a solution differs based on the domain at hand.  More specifically: you think differently.  Being able to solve problems in programming often requires you to shift your way of thinking and having more experience approaching problems from different angles can be very beneficial.  It can even apply to learning new programming paradigms.  I didn&#8217;t fully grasp OOP until I considered things in terms of chemistry.</p>
<p>Second, having a broad knowledge base can make it easier to communicate with people of different backgrounds.  Much like dealing with experts above, but often a little more general.  This is also somewhat tied to the problem solving mentioned previously.  When you can shift thinking readily, it becomes far easier to think like the person you are communicating with and explain things with terms or analogies that that person can understand.  As a personal example of this: I&#8217;ve explained the Linux boot process almost entirely with car analogies to a car guy.  I&#8217;m pretty certain that had i never taken auto shop, this would have been impossible.</p>
<p>tl;dr version: Learn stuff. It makes you a better problem solver and communicator.  Soft skills for the win.</p>
]]></content:encoded>
			<wfw:commentRss>http://rrbits.com/epb/2012/02/12/programmers-should-expand-knowledge-bases/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Now I remember why I hate HP&#8217;s website</title>
		<link>http://rrbits.com/epb/2012/01/30/now-i-remember-why-i-hate-hps-website/</link>
		<comments>http://rrbits.com/epb/2012/01/30/now-i-remember-why-i-hate-hps-website/#comments</comments>
		<pubDate>Mon, 30 Jan 2012 08:36:56 +0000</pubDate>
		<dc:creator>epb</dc:creator>
				<category><![CDATA[Problems]]></category>

		<guid isPermaLink="false">http://rrbits.com/epb/?p=364</guid>
		<description><![CDATA[So I go off to search for a part (specifically a replacement battery for a laptop) but I don&#8217;t have the thing with me since it&#8217;s not mine, I&#8217;ve just been tasked with finding a replacement.  (So, no stickers for me!)  As a last ditch effort before contacting the owner, I go googling and grab [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_365" class="wp-caption alignnone" style="width: 310px"><a href="http://rrbits.com/epb/files/2012/01/retardedhp.jpg" rel="lightbox[364]"><img class="size-medium wp-image-365" title="Seriously HP?" src="http://rrbits.com/epb/files/2012/01/retardedhp-300x167.jpg" alt="" width="300" height="167" /></a><p class="wp-caption-text">Not entering a valid part number is not a crime.</p></div>
<p>So I go off to search for a part (specifically a replacement battery for a laptop) but I don&#8217;t have the thing with me since it&#8217;s not mine, I&#8217;ve just been tasked with finding a replacement.  (So, no stickers for me!)  As a last ditch effort before contacting the owner, I go googling and grab a random part number and decide to try to plug it into the part search and hope that it happens to match with HP&#8217;s all-knowing database, knowing full well it would probably say something like &#8220;Invalid Part Number&#8221; or something.  Plug in: SFB-HPDV7_56157 and I&#8217;m met with a much more condescending message:</p>
<blockquote><p>A potentially dangerous input was detected from the client browser. This incident is reported to Support team. Please click &#8216;Home&#8217; link to continue.</p></blockquote>
<p>Really?  It&#8217;s always such a pain to use HP&#8217;s website to find&#8230; umm&#8230; anything, but this is a first I have to admit.  I wasn&#8217;t aware that dashes and underscores could be dangerous.  Couldn&#8217;t be polite and just say &#8220;that part number isn&#8217;t valid.&#8221;&lt;/rant&gt;</p>
<p>That out of the way, why do manufacturers go through such lengths to avoid parting us from our money?  If I cannot, with ease, find a replacement part from you, <em>I will not be able to buy it from you</em>. For those who don&#8217;t know, with HP, to find anything you need both the product number <em>and</em> serial number to even begin your search. (Alternatively run their HP support assistant program on the laptop itself.)</p>
]]></content:encoded>
			<wfw:commentRss>http://rrbits.com/epb/2012/01/30/now-i-remember-why-i-hate-hps-website/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Significant Times of the Day</title>
		<link>http://rrbits.com/epb/2011/10/14/significant-times-of-the-day/</link>
		<comments>http://rrbits.com/epb/2011/10/14/significant-times-of-the-day/#comments</comments>
		<pubDate>Sat, 15 Oct 2011 05:54:07 +0000</pubDate>
		<dc:creator>epb</dc:creator>
				<category><![CDATA[Comic]]></category>
		<category><![CDATA[Random]]></category>
		<category><![CDATA[comic]]></category>

		<guid isPermaLink="false">http://rrbits.com/epb/?p=353</guid>
		<description><![CDATA[For those who cannot see images: Significant times of the day 4:04 &#8211; Time is not found. 5:00 &#8211; Time is Broken. 4:03 &#8211; The forbidden time. 3:03 &#8211; The time for seeing others. 4:09 &#8211; Time of Confrontation 4:10 &#8211; Time of Disappearance 3:02 &#8211; Time of Finding 2:02 &#8211; Time of Willful Procrastination [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_355" class="wp-caption aligncenter" style="width: 423px"><img class="size-full wp-image-355 " title="Significant Times of The Day" src="http://rrbits.com/epb/files/2011/10/bigtimess8.png" alt="" width="413" height="600" /><p class="wp-caption-text">Important times to watch out for</p></div>
<p>For those who cannot see images:</p>
<p>Significant times of the day</p>
<p>4:04 &#8211; Time is not found.<br />
5:00 &#8211; Time is Broken.<br />
4:03 &#8211; The forbidden time.<br />
3:03 &#8211; The time for seeing others.<br />
4:09 &#8211; Time of Confrontation<br />
4:10 &#8211; Time of Disappearance<br />
3:02 &#8211; Time of Finding<br />
2:02 &#8211; Time of Willful Procrastination</p>
<p>Don&#8217;t quite get it? Read up on <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html">HTTP error codes.</a></p>
<p><a href="http://rrbits.com/epb/files/2011/10/bigtimes.pdf">Significant Times of the Day printable PDF</a></p>
<p><a href="http://rrbits.com/bigtimes.svg">Significant Times of the Day source SVG</a> (The fonts used are available on <a href="http://www.fontsquirrel.com/">Font Squirrel</a>.)</p>
]]></content:encoded>
			<wfw:commentRss>http://rrbits.com/epb/2011/10/14/significant-times-of-the-day/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zombinanza 2 now in progress</title>
		<link>http://rrbits.com/epb/2011/10/14/zombinanza-2-now-in-progress/</link>
		<comments>http://rrbits.com/epb/2011/10/14/zombinanza-2-now-in-progress/#comments</comments>
		<pubDate>Fri, 14 Oct 2011 06:02:12 +0000</pubDate>
		<dc:creator>epb</dc:creator>
				<category><![CDATA[Games]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://rrbits.com/epb/?p=349</guid>
		<description><![CDATA[It was mentioned that a sequel to Zombinanza has long been missing, and as a consequence Zombinanza 2 shall be attempted to be started to be made. Harass me if it doesn&#8217;t.]]></description>
			<content:encoded><![CDATA[<p>It was mentioned that a sequel to Zombinanza has long been missing, and as a consequence Zombinanza 2 shall be attempted to be started to be made.  Harass me if it doesn&#8217;t.</p>
]]></content:encoded>
			<wfw:commentRss>http://rrbits.com/epb/2011/10/14/zombinanza-2-now-in-progress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP: Get zipcode for an Address</title>
		<link>http://rrbits.com/epb/2011/10/13/zipcode-for-address-php-googlemaps/</link>
		<comments>http://rrbits.com/epb/2011/10/13/zipcode-for-address-php-googlemaps/#comments</comments>
		<pubDate>Fri, 14 Oct 2011 02:10:01 +0000</pubDate>
		<dc:creator>epb</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://rrbits.com/epb/?p=342</guid>
		<description><![CDATA[I needed a small php function that could take an address (which lacked a zip code) and fetch a best guess postal code for it. I had a database full of addresses with city and state, but no zip code. Thankfully, if you have enough information in your address to locate it with the Google [...]]]></description>
			<content:encoded><![CDATA[<p>I needed a small php function that could take an address (which lacked a zip code) and fetch a best guess postal code for it.  I had a database full of addresses with city and state, but no zip code.  Thankfully, if you have enough information in your address to locate it with the Google maps geocoding service, you have enough information to get the zip code.  If not the correct zip code, it should pull one that&#8217;s relatively close assuming you&#8217;ve specified the correct city and state in your address.</p>
<p>This is possible because the geocoding service will return matches with full address data available.  If we assume that the first match is most likely the correct match, we can just extract it&#8217;s postal code. I&#8217;ve only tested this with US addresses, but it may work in other countries where Google can geocode an address.</p>
<p><span id="more-342"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Uses Google Maps Geocoder (V3) to get postal code for an address.  Uses first address match.
 * @param String Address - Make sure to include at least the street address, city and state.
 * @return String - Zip code on success, blank if a zip code is failed to be retrieved.
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> zip_code_from_address<span style="color: #009900;">&#40;</span><span style="color: #000088;">$address</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$ura</span> <span style="color: #339933;">=</span> <span style="color: #990000;">rawurlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$address</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$rurl</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&amp;address=<span style="color: #006699; font-weight: bold;">$ura</span>&quot;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$dom</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DOMDocument<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$res</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dom</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loadXML</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rurl</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$res</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$status</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dom</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'status'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
         <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$status</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'OK'</span><span style="color: #009900;">&#41;</span>
         <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">//If status is OK, then at least one result should be here.</span>
            <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dom</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'result'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$postalcode</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'address_component'</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$comp</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
               <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$comp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'postal_code'</span><span style="color: #009900;">&#41;</span>
               <span style="color: #009900;">&#123;</span>
                  <span style="color: #000088;">$postalcode</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$comp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'short_name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span><span style="color: #339933;">;</span>
               <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #000088;">$postalcode</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
         <span style="color: #b1b100;">else</span>
         <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
   <span style="color: #b1b100;">else</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://rrbits.com/epb/2011/10/13/zipcode-for-address-php-googlemaps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I feel cryptastic</title>
		<link>http://rrbits.com/epb/2011/04/17/i-feel-cryptastic/</link>
		<comments>http://rrbits.com/epb/2011/04/17/i-feel-cryptastic/#comments</comments>
		<pubDate>Sun, 17 Apr 2011 19:30:50 +0000</pubDate>
		<dc:creator>epb</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[mcrypt]]></category>

		<guid isPermaLink="false">http://rrbits.com/epb/?p=338</guid>
		<description><![CDATA[Looking for a quick and easy to use encryption class for PHP?  I stumbled upon Cryptastic in my searches for example code to use with mcrypt for a personal project.  I must say it&#8217;s quite handy. It implements a message integrity check and handles the initialization vector stuff for you making encrypting data as easy [...]]]></description>
			<content:encoded><![CDATA[<p>Looking for a quick and easy to use encryption class for PHP?  I stumbled upon <a href="http://www.itnewb.com/v/PHP-Encryption-Decryption-Using-the-MCrypt-Library-libmcrypt">Cryptastic </a>in my searches for example code to use with mcrypt for a personal project.  I must say it&#8217;s quite handy. It implements a message integrity check and handles the initialization vector stuff for you making encrypting data as easy as a single call.</p>
]]></content:encoded>
			<wfw:commentRss>http://rrbits.com/epb/2011/04/17/i-feel-cryptastic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get the Bounding Box of an SVG Path</title>
		<link>http://rrbits.com/epb/2011/02/06/get-the-bounding-box-of-an-svg-path/</link>
		<comments>http://rrbits.com/epb/2011/02/06/get-the-bounding-box-of-an-svg-path/#comments</comments>
		<pubDate>Mon, 07 Feb 2011 00:39:04 +0000</pubDate>
		<dc:creator>epb</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[hopefully_that_made_sense]]></category>
		<category><![CDATA[ImageMagick]]></category>
		<category><![CDATA[problem]]></category>
		<category><![CDATA[svg]]></category>

		<guid isPermaLink="false">http://rrbits.com/epb/?p=325</guid>
		<description><![CDATA[There may be times you need to find the bounding box of an SVG path. One way to find it would be to parse the path and then apply any group transformation on it to find the range of X and Y coordinates the object occupies. However that&#8217;s a bit of code, and I&#8217;m quite [...]]]></description>
			<content:encoded><![CDATA[<p>There may be times you need to find the bounding box of an SVG path.  One way to find it would be to parse the path and then apply any group transformation on it to find the range of X and Y coordinates the object occupies.  However that&#8217;s a bit of code, and I&#8217;m quite a bit lazy, so I decided to try another approach: rasterize the path object by itself and find where in the image it was drawn.<br />
<span id="more-325"></span><br />
To do this, basically, all you need to do is erase all the other content from the document, leaving only the path you want to find the bounding box of and then trim the sides off with ImageMagick and have it tell you the info instead of generating an image.</p>
<p>Here&#8217;s an example ImageMagick convert command line:</p>
<pre>bash:~&gt;convert -density 200 pumpkinsheet.svg -trim info:-
pumpkinsheet.svg SVG 1813x2244 2066x2922+207+576 16-bit DirectClass 0.070u 0:00.029</pre>
<p>First you have the file name, type, resulting crop size, original canvas size and the offsets where the crop starts.  Respectively: pumpkinsheet.svg; SVG; 1813 x 2244; 2066&#215;2922; and 207,586.</p>
<p>You can then find the bounding offsets of the drawn object:</p>
<p>Top left X: 207 (horizontal offset)<br />
Top left Y: 576 (vertical offset)<br />
Bottom right X: 207 + 1813 (horizontal offset + cropped width)<br />
Bottom right Y: 576 + 2244 (vertical offset + cropped height)</p>
<p>Unless you use the default density (72) these canvas sizes won&#8217;t match up to what you likely have in your SVG set as the width and height, so convert them to percentages by dividing them by the original width (for the Xs) and the original height (for the Ys).</p>
<p>Once you have the percentages, multiply the width and height of your SVG if you need it in absolute points of the SVG instead of percentages.</p>
<p>A couple of caveats with this method:</p>
<ul>
<li>If you have borders, they will add to the bounding box.</li>
<li>This will clip any path that falls outside the canvas unless you expand the canvas of the single-node object.</li>
<li>You&#8217;ll need to preserve patterns and gradients if you want those patterns and gradients to play a role in your bounding calculation.</li>
<li>Using higher densities will get you more sub-pixel accurate results, but will consume more memory in the process.</li>
</ul>
<p>I have some rough code I&#8217;m using in my own project below.  I just use the percentages for my purposes, as such the discover_bounding_box only returns the bounding coordinates as percentages.  The create_single_object_svg function could function differently as well.  Instead of making a copy of the SVG, it could just loop through the SVG&#8217;s DOM and remove any node that would result in drawing except our desired object.  This would make it fairly easy to preserve patterns and gradients.  It uses proc_open and DO NOT run this on a server with autoregister globals on.  That is a recipe for disaster.  The code below is provided for demonstration purposes only and should not necessarily be expected to work as you expect without modification.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * Determines the bounding box of a specific path, rectangle, polygon, or ellipses
 * in an SVG.  Accepts the SVG's DOM, and the node specifically desired to be checked.
 * Assumes convert is at /usr/bin/convert unless a global called $convertpath is set.
 *
 * @param DOMDocument $svg SVG DOMDocument to use to find this item's bounding box.
 * @param DOMDocument $object Node that we want to find the bounding box for.
 * @param Float $precision Precision desired, 1 is rougly pixel-accurate, between 0.1 and 1 is less than pixel accurate
 *   and anything above 1 should be sub-pixel accurate.  (Max is 3)
 * @return Mixed Boolean false on failure, Array with topleft-x, topleft-y, bottomright-x, bottomright-y in percentages
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> discover_bounding_box<span style="color: #009900;">&#40;</span><span style="color: #000088;">$svg</span><span style="color: #339933;">,</span> <span style="color: #000088;">$object</span><span style="color: #339933;">,</span> <span style="color: #000088;">$precision</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$convertpath</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$convert</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$convertpath</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$convertpath</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'/usr/bin/convert'</span><span style="color: #339933;">;</span>
   <span style="color: #666666; font-style: italic;">// We assume density 72 is the pixel-size accurate </span>
   <span style="color: #000088;">$density</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">72</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$precision</span> <span style="color: #339933;">&gt;=</span> <span style="color:#800080;">0.1</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$precision</span> <span style="color: #339933;">&lt;=</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
       <span style="color: #000088;">$density</span> <span style="color: #339933;">=</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">72</span><span style="color: #339933;">*</span><span style="color: #000088;">$precision</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #000088;">$singlesvg</span> <span style="color: #339933;">=</span> create_single_object_svg<span style="color: #009900;">&#40;</span><span style="color: #000088;">$svg</span><span style="color: #339933;">,</span> <span style="color: #000088;">$object</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
   <span style="color: #666666; font-style: italic;">//Now that we've got the SVG in hand, let's pass it on to process image.</span>
   <span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   process_image<span style="color: #009900;">&#40;</span><span style="color: #000088;">$singlesvg</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'-trim'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'svg'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'info'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;-density <span style="color: #006699; font-weight: bold;">$density</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$info</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">ob_get_clean</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">//Tokenize the fragments of text from our friend, ImageMagick.</span>
   <span style="color: #000088;">$fragments</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$info</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$trimmed_width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$trimmed_height</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'x'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$fragments</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #666666; font-style: italic;">//If both intval'd are not 0, then we can assume that all when well.</span>
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$trimmed_width</span> <span style="color: #339933;">=</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$trimmed_width</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$trimmed_height</span> <span style="color: #339933;">=</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$trimmed_height</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">//Now get the original width, original height, clip offsetx and clip offsety</span>
      <span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$original_width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$original_height</span><span style="color: #339933;">,</span> <span style="color: #000088;">$clip_offsetx</span><span style="color: #339933;">,</span> <span style="color: #000088;">$clip_offsety</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> 
         <span style="color: #990000;">array_map</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'_intval'</span><span style="color: #339933;">,</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'+'</span><span style="color: #339933;">,</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'x'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'+'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$fragments</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000088;">$bounding_top_left_x</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$clip_offsetx</span><span style="color: #339933;">/</span><span style="color: #000088;">$original_width</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$bounding_top_left_y</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$clip_offsety</span><span style="color: #339933;">/</span><span style="color: #000088;">$original_height</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$bounding_bottom_right_x</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$clip_offsetx</span><span style="color: #339933;">+</span><span style="color: #000088;">$trimmed_width</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #000088;">$original_width</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$bounding_bottom_right_y</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$clip_offsety</span><span style="color: #339933;">+</span><span style="color: #000088;">$trimmed_height</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #000088;">$original_height</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #b1b100;">return</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$bounding_top_left_x</span><span style="color: #339933;">,</span> <span style="color: #000088;">$bounding_top_left_y</span><span style="color: #339933;">,</span> 
         <span style="color: #000088;">$bounding_bottom_right_x</span><span style="color: #339933;">,</span> <span style="color: #000088;">$bounding_bottom_right_y</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * Creates an extract from an SVG based on an input DOM and desired object.
 * @param DOMDocument $svg A fully loaded DOMDocument for the SVG.
 * @param DOMNode $object Target node to extract.
 * @return String Returns an SVG file containing only the desired object.  At present
 * this function also removes patterns and gradients which may be a notable problem in 
 * cases where you want to find the visible bounding box of an object, not necessarily
 * it's exact box.
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> create_single_object_svg<span style="color: #009900;">&#40;</span><span style="color: #000088;">$svg</span><span style="color: #339933;">,</span> <span style="color: #000088;">$object</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #666666; font-style: italic;">//Get the width and height of the current document.</span>
   <span style="color: #000088;">$root</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$svg</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'svg'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$width</span> <span style="color: #339933;">=</span> <span style="color: #990000;">htmlspecialchars</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$root</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'width'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$height</span> <span style="color: #339933;">=</span> <span style="color: #990000;">htmlspecialchars</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$root</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'height'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">//It's best if you have a solid color set in the style or fill attribute</span>
   <span style="color: #666666; font-style: italic;">//but it shouldn't be that big a deal.   </span>
&nbsp;
   <span style="color: #666666; font-style: italic;">//Get an transforms from group nodes.</span>
   <span style="color: #000088;">$transforms</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$current</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$object</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$current</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">parentNode</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">//Continue climbing until there's no where else to climb to.</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$current</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$current</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">parentNode</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$current</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeName</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'g'</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
         <span style="color: #000088;">$transforms</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$current</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'transform'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * Run stuff through image_magick uses the global convert path settings.  Outputs image on success (and sets header)
 * @param String $imgdata Raw image file data to pipe to image magick.
 * @param String $processing_instruction Command line options to pass to image magick's convert program.
 * @param String $inputtype Default: jpg Input image format.
 * @param String $outputtype Default: jpg Output image format.
 * @param String $preload_instructions Add instructions that go before the file to load.
 * @return void
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> process_image<span style="color: #009900;">&#40;</span><span style="color: #000088;">$imgdata</span><span style="color: #339933;">,</span> <span style="color: #000088;">$processing_instruction</span><span style="color: #339933;">,</span> <span style="color: #000088;">$inputtype</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'jpg'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$outputtype</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'jpg'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$preload_instructions</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$convertpath</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'proc_open'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">//Let's just pipe to imagemagick to handle our graphics transform shall we?</span>
      <span style="color: #000088;">$descriptors</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
         <span style="color: #0000ff;">'0'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;pipe&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'r'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
         <span style="color: #0000ff;">'1'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;pipe&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
         <span style="color: #0000ff;">'2'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;file&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;/dev/null&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;w&quot;</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000088;">$pipes</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$process</span> <span style="color: #339933;">=</span> <span style="color: #990000;">proc_open</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$command</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$convertpath</span> <span style="color: #006699; font-weight: bold;">$preload_instructions</span> <span style="color: #006699; font-weight: bold;">{$inputtype}</span>:- <span style="color: #006699; font-weight: bold;">$processing_instruction</span> <span style="color: #006699; font-weight: bold;">{$outputtype}</span>:-&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$descriptors</span><span style="color: #339933;">,</span> <span style="color: #000088;">$pipes</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'binary_pipes'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #666666; font-style: italic;">//die($command);</span>
      <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$process</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
         <span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pipes</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$imgdata</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #666666; font-style: italic;">//fwrite($pipes[0], EOF);</span>
         <span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pipes</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #000088;">$contents</span> <span style="color: #339933;">=</span> <span style="color: #990000;">stream_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pipes</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #990000;">proc_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$process</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
         <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$contents</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">50</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$outputtype</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'info'</span><span style="color: #009900;">&#41;</span>
         <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$contents</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
         <span style="color: #b1b100;">else</span>
         <span style="color: #009900;">&#123;</span>
            <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HTTP/1.1 500 Internal Error'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'content-type: text/plain'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Failed to process image.'</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #b1b100;">else</span>
      <span style="color: #009900;">&#123;</span>
         <span style="color: #666666; font-style: italic;">//Poor process died.  Should we do something?</span>
         <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HTTP/1.1 500 Internal Error'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'content-type: text/plain'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Failed to process image.'</span><span style="color: #339933;">;</span>               
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://rrbits.com/epb/2011/02/06/get-the-bounding-box-of-an-svg-path/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CherryPad America</title>
		<link>http://rrbits.com/epb/2010/11/15/cherrypad-america/</link>
		<comments>http://rrbits.com/epb/2010/11/15/cherrypad-america/#comments</comments>
		<pubDate>Tue, 16 Nov 2010 04:26:37 +0000</pubDate>
		<dc:creator>epb</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[CherryPad]]></category>

		<guid isPermaLink="false">http://rrbits.com/epb/?p=229</guid>
		<description><![CDATA[I got my CherryPad America toward the end of October.  It&#8217;s a low-end tablet, comparable to the ones you can now find at WalMart and KMart.  I bought mine primarily to function as an e-reader, and quickly found that it had impressive video codec support and could do more than I was expecting out of [...]]]></description>
			<content:encoded><![CDATA[<p>I got my CherryPad America toward the end of October.  It&#8217;s a low-end tablet, comparable to the ones you can now find at WalMart and KMart.  I bought mine primarily to function as an e-reader, and quickly found that it had impressive video codec support and could do more than I was expecting out of such a cheap device.  (When I bought it, it was one of the cheapest on the market.)</p>
<p>I was order number 58, so some things are probably different now.  I believe the factory language is now English instead of Chinese for instance.</p>
<p>Some initial thoughts:</p>
<ul>
<li>Good codec support (Too bad the Android video player doesn&#8217;t support internal mkv subtitles.  You need third party software from the market for that.)</li>
<li>Root access!</li>
<li>Android Market is a pain to get (and keep) working.</li>
<li>Resistive Screen takes some getting used to</li>
<li>Speakers are less than impressive, but sounds pretty decent with headphones or externally attached speakers.</li>
<li>Fits in one hand, good for reading.</li>
<li>Gah, why is JavaScript not on by default?</li>
<li>I like the aluminum case.</li>
<li>Uses my iPod&#8217;s docking cable.</li>
<li>A little slow sometimes, depends on the task.</li>
</ul>
<p>Getting the Android Marketplace to function well has been an uphill battle, and honestly, the biggest problem I&#8217;ve run into.  It will work for a bit and then stop working entirely.  Actually, hasn&#8217;t worked for a week for me now. *sigh* I think I&#8217;ll email and ask about that.</p>
<p>If you&#8217;re looking for a simple music-playing, video-playing tablet, that you can use for reading and browsing the Internet.  It&#8217;s perfectly capable of all that.  I even use it to order parts off NewEgg and such.  Once you get it set up to your liking and get used to the resistive screen, it&#8217;s nice, if a little slow.  Verdict is that I like it, but am hesitant to recommend buying it because of the issues I&#8217;ve had with the Android Market.</p>
]]></content:encoded>
			<wfw:commentRss>http://rrbits.com/epb/2010/11/15/cherrypad-america/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CherryPad America Factory Reset</title>
		<link>http://rrbits.com/epb/2010/10/27/cherrypad-america-factory-reset/</link>
		<comments>http://rrbits.com/epb/2010/10/27/cherrypad-america-factory-reset/#comments</comments>
		<pubDate>Wed, 27 Oct 2010 17:14:46 +0000</pubDate>
		<dc:creator>epb</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[tablets]]></category>

		<guid isPermaLink="false">http://rrbits.com/epb/?p=225</guid>
		<description><![CDATA[The CherryPad America is a tablet running Android I plan to write up a review for later, however a quick note for anyone who might be searching: Yes, if you do a factory restore, the default language will be Chinese. You can change it to English by pressing the change-language button in the lower-right hand [...]]]></description>
			<content:encoded><![CDATA[<p>The CherryPad America is a tablet running Android I plan to write up a review for later, however a quick note for anyone who might be searching: Yes, if you do a factory restore, the default language will be Chinese.</p>
<p>You can change it to English by pressing the change-language button in the lower-right hand corner of the initial start screen where you are asked to press on the android. (But you can&#8217;t read that since it&#8217;s in Chinese. <img src='http://rrbits.com/epb/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  )  Then you can pick English and be good to go for your initial boot.</p>
]]></content:encoded>
			<wfw:commentRss>http://rrbits.com/epb/2010/10/27/cherrypad-america-factory-reset/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

