<?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>Just another Random Renegade Bits weblog</description>
	<lastBuildDate>Fri, 06 Aug 2010 21:04:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Resize and Crop to a specific width x height with a crop suggestion point.</title>
		<link>http://rrbits.com/epb/2010/07/18/resize-and-crop/</link>
		<comments>http://rrbits.com/epb/2010/07/18/resize-and-crop/#comments</comments>
		<pubDate>Mon, 19 Jul 2010 03:15:10 +0000</pubDate>
		<dc:creator>epb</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[gd]]></category>
		<category><![CDATA[images]]></category>

		<guid isPermaLink="false">http://rrbits.com/epb/?p=190</guid>
		<description><![CDATA[I really don&#8217;t have a shorter description for this.  I was working on a personal project the other day and realized that this might be a nifty function.  Basically, you know all those snippets to make cropped thumbnails (squares and the like), and how most of them either center or crop to the top of [...]]]></description>
			<content:encoded><![CDATA[<p>I really don&#8217;t have a shorter description for this.  I was working on a personal project the other day and realized that this might be a nifty function.  Basically, you know all those snippets to make cropped thumbnails (squares and the like), and how most of them either center or crop to the top of an image.  I wanted a new function that would crop to most any size I desired and any position on the image I desired without the need to change any code, only parameters.  And thus img_resize_crop was born.</p>
<p><span id="more-190"></span>Function code is below, try out a demo at <a href="http://rrbits.com/resizer/">http://rrbits.com/resizer/</a> (Demo code is available here: <a href="http://rrbits.com/resizer.zip">http://rrbits.com/resizer.zip</a> )</p>
<p>Right now it&#8217;s pure GD (uses a sharpening convolution matrix to get over GD&#8217;s resizing blurryness), though could probably be converted to ImageMagick by someone who knows more about ImageMagick than I.  (Plus more patience, no desire to port it right now.)</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>
<span style="color: #009933; font-style: italic;">/**
 * img_resize_crop
 * Resizes an image to a specific size, cropping if necessary, allows center-weighting.
 *
 * @param Resource $src - GD Resource Image to use.
 * @param Integer $twidth - Thumbnail width
 * @param Integer $theight - Thumbnail height
 * @param Integer $center_x - The x value of the target center location, leaving it at -1 autocalculates. [Default: -1]
 * @param Integer $center_y - The y value of the target center location, leaving it at -1 autocalculates. [Default: -1]
 * @param String $method - Method to use for the resize.  [Default:suggest]
 *   'suggest' (provided center coordinate is only guaranteed to be in the picture.)
 *   'force' (The provided coordinate is forced into being the center, additional data is trimmed to ensure this.)
 *   'onlycrop' (Not sure why you would use this, but only performs cropping.)
 * @param Boolean $sharpen - Specify whether or not to sharpen the resultant thumbnail [Default:true]
 * @param Int $evil_threshold - Maximum thumbnail width/height to prevent attempts at evil. [Default:1024]
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> img_resize_crop<span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #339933;">,</span> <span style="color: #000088;">$twidth</span><span style="color: #339933;">,</span> <span style="color: #000088;">$theight</span><span style="color: #339933;">,</span> <span style="color: #000088;">$center_x</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> 
    <span style="color: #000088;">$center_y</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$method</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'suggest'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sharpen</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #000088;">$evil_threshold</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1024</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #666666; font-style: italic;">/*Set defaults if they are not provided.*/</span>
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$center_x</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'force'</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$center_x</span> <span style="color: #339933;">==</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: #000088;">$center_x</span> <span style="color: #339933;">=</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">imagesx</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$center_y</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'force'</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$center_y</span> <span style="color: #339933;">==</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: #000088;">$center_y</span> <span style="color: #339933;">=</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">imagesy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">/* Prevent evil */</span>
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$twidth</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$evil_threshold</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$twidth</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$evil_threshold</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$theight</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$evil_threshold</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$theight</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$evil_threshold</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
   <span style="color: #666666; font-style: italic;">/*  The ratio of the thumbnail and the ratio 
    of the original image.*/</span>
   <span style="color: #000088;">$t_ratio</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$twidth</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$theight</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$o_ratio</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagesx</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #990000;">imagesy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$new</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatetruecolor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$twidth</span><span style="color: #339933;">,</span> <span style="color: #000088;">$theight</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">/*Ideally, we'll want to grab as much of 
     the source image as possible.
&nbsp;
     So we need to figure out how much to grab based on 
     the ratios of the desired thumbnail and the original
     image.*/</span>
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$t_ratio</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$o_ratio</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$i_width</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagesx</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$i_height</span> <span style="color: #339933;">=</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i_width</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$t_ratio</span><span style="color: #009900;">&#41;</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: #000088;">$i_height</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagesy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$i_width</span> <span style="color: #339933;">=</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i_height</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$t_ratio</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">/*Calculate the upper-left corner of the 
     source image grab area.  These will be 
     adjusted differently based on the method selected.*/</span>
   <span style="color: #000088;">$s_x</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$center_x</span> <span style="color: #339933;">-</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i_width</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$s_y</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$center_y</span> <span style="color: #339933;">-</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i_height</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
   <span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'onlycrop'</span><span style="color: #339933;">:</span>  
         <span style="color: #000088;">$i_width</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">imagesx</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$twidth</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$twidth</span> <span style="color: #339933;">:</span> <span style="color: #990000;">imagesx</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #000088;">$i_height</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">imagesy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$theight</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$theight</span> <span style="color: #339933;">:</span> <span style="color: #990000;">imagesy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #000088;">$s_x</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$center_x</span> <span style="color: #339933;">-</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i_width</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #000088;">$s_y</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$center_y</span> <span style="color: #339933;">-</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i_height</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
&nbsp;
         <span style="color: #666666; font-style: italic;">/*Make sure we're inside the left and top boundaries.*/</span>
         <span style="color: #000088;">$s_x</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$s_x</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> ? <span style="color: #cc66cc;">0</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$s_x</span><span style="color: #339933;">;</span>
         <span style="color: #000088;">$s_y</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$s_y</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> ? <span style="color: #cc66cc;">0</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$s_y</span><span style="color: #339933;">;</span>
&nbsp;
         <span style="color: #666666; font-style: italic;">/*Make sure we're inside the bottom and right boundaries.*/</span>
         <span style="color: #000088;">$s_x</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$center_x</span> <span style="color: #339933;">+</span> <span style="color: #990000;">ceil</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i_width</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #990000;">imagesx</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #990000;">imagesx</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$i_width</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$s_x</span><span style="color: #339933;">;</span>
         <span style="color: #000088;">$s_y</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$center_y</span> <span style="color: #339933;">+</span> <span style="color: #990000;">ceil</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i_height</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #990000;">imagesy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #990000;">imagesy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$i_height</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$s_y</span><span style="color: #339933;">;</span>  
&nbsp;
         <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>      
      <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
      <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'suggest'</span><span style="color: #339933;">:</span>
         <span style="color: #666666; font-style: italic;">/*Condition: Crop is thinner (ratio-wise) than the original image.*/</span>
         <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$t_ratio</span> <span style="color: #339933;">&lt;=</span> <span style="color: #000088;">$o_ratio</span><span style="color: #009900;">&#41;</span>
         <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$s_y</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$s_x</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$s_x</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> ? <span style="color: #cc66cc;">0</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$s_x</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$s_x</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$center_x</span> <span style="color: #339933;">+</span> <span style="color: #990000;">ceil</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i_width</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #990000;">imagesx</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #990000;">imagesx</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$i_width</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$s_x</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
         <span style="color: #b1b100;">else</span> <span style="color: #666666; font-style: italic;">/*Condition: Crop is wider (ratio-wise) than the original image.*/</span>
         <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$s_x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$s_y</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$s_y</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> ? <span style="color: #cc66cc;">0</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$s_y</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$s_y</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$center_y</span> <span style="color: #339933;">+</span> <span style="color: #990000;">ceil</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i_height</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #990000;">imagesy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #990000;">imagesy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$i_height</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$s_y</span><span style="color: #339933;">;</span>   
         <span style="color: #009900;">&#125;</span>
         <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'force'</span><span style="color: #339933;">:</span>
         <span style="color: #666666; font-style: italic;">/*Condition: Crop is thinner (ratio-wise) than the original image.*/</span>
         <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$t_ratio</span> <span style="color: #339933;">&lt;=</span> <span style="color: #000088;">$o_ratio</span><span style="color: #009900;">&#41;</span>
         <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">/*Find the maximum possible height with the requested center_y.*/</span>
            <span style="color: #000088;">$i_height</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$center_y</span> <span style="color: #339933;">&gt;</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">imagesy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #009900;">&#40;</span><span style="color: #990000;">imagesy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$center_y</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$center_y</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$i_width</span> <span style="color: #339933;">=</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i_height</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$t_ratio</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">/*Height for said width.*/</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">/*If that puts the source box out of bounds, we'll need to proportionally scale down.*/</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$center_x</span> <span style="color: #339933;">-</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i_width</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$center_x</span> <span style="color: #339933;">+</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i_width</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #990000;">imagesx</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</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;">/*Minimum width.*/</span>
               <span style="color: #000088;">$i_width</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$center_x</span> <span style="color: #339933;">&gt;</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">imagesx</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #009900;">&#40;</span><span style="color: #990000;">imagesx</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$center_x</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$center_x</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
               <span style="color: #000088;">$i_height</span> <span style="color: #339933;">=</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i_width</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$t_ratio</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #666666; font-style: italic;">/*Recalculate source x and y*/</span>
            <span style="color: #000088;">$s_x</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$center_x</span> <span style="color: #339933;">-</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i_width</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$s_y</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$center_y</span> <span style="color: #339933;">-</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i_height</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>            
         <span style="color: #009900;">&#125;</span>
         <span style="color: #b1b100;">else</span> <span style="color: #666666; font-style: italic;">/*Condition: Crop is wider (ratio-wise) than the original image.*/</span>
         <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">/*Find the maximum possible width with the requested center_x.*/</span>
            <span style="color: #000088;">$i_width</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$center_x</span> <span style="color: #339933;">&gt;</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">imagesx</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #009900;">&#40;</span><span style="color: #990000;">imagesx</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$center_x</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$center_x</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$i_height</span> <span style="color: #339933;">=</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i_width</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$t_ratio</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">/*Height for said width.*/</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">/*If that puts the source box out of bounds, we'll need to proportionally scale down.*/</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$center_y</span> <span style="color: #339933;">-</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i_height</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$center_y</span> <span style="color: #339933;">+</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i_height</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #990000;">imagesy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</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;">/*Minimum height.*/</span>
               <span style="color: #000088;">$i_height</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$center_y</span> <span style="color: #339933;">&gt;</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">imagesy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #009900;">&#40;</span><span style="color: #990000;">imagesy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$center_y</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$center_y</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
               <span style="color: #000088;">$i_width</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$i_height</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$t_ratio</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #666666; font-style: italic;">/*Recalculate source x and y*/</span>
            <span style="color: #000088;">$s_x</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$center_x</span> <span style="color: #339933;">-</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i_width</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$s_y</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$center_y</span> <span style="color: #339933;">-</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i_height</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
&nbsp;
         <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #990000;">imagecopyresampled</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$new</span><span style="color: #339933;">,</span> <span style="color: #000088;">$src</span><span style="color: #339933;">,</span> 
     <span style="color: #666666; font-style: italic;">/*Destination Coords*/</span>
     <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
     <span style="color: #666666; font-style: italic;">/*Source Coords*/</span>
     <span style="color: #000088;">$s_x</span><span style="color: #339933;">,</span><span style="color: #000088;">$s_y</span><span style="color: #339933;">,</span>
     <span style="color: #666666; font-style: italic;">/*Destination Geometry*/</span>
     <span style="color: #000088;">$twidth</span><span style="color: #339933;">,</span> <span style="color: #000088;">$theight</span><span style="color: #339933;">,</span>
     <span style="color: #666666; font-style: italic;">/*Source Geometry*/</span>
     <span style="color: #000088;">$i_width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$i_height</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: #000088;">$sharpen</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$sharpen_matrix</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">16</span><span style="color: #339933;">,-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$divisor</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$offset</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #990000;">imageconvolution</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$new</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sharpen_matrix</span><span style="color: #339933;">,</span> <span style="color: #000088;">$divisor</span><span style="color: #339933;">,</span> <span style="color: #000088;">$offset</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: #000088;">$new</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://rrbits.com/epb/2010/07/18/resize-and-crop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rythmbox Sync to USB Device</title>
		<link>http://rrbits.com/epb/2010/06/23/rythmbox-sync-to-usb-device/</link>
		<comments>http://rrbits.com/epb/2010/06/23/rythmbox-sync-to-usb-device/#comments</comments>
		<pubDate>Wed, 23 Jun 2010 20:10:35 +0000</pubDate>
		<dc:creator>epb</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[mp3]]></category>
		<category><![CDATA[music]]></category>

		<guid isPermaLink="false">http://rrbits.com/epb/?p=184</guid>
		<description><![CDATA[I have a sizable collection of music, so sizable in fact that I can&#8217;t store the full collection on any portal media.  Since I only use Windows to play video games, I use Rhythmbox to manage my music and found myself in need of a way to sync to a USB thumbdrive.  Now, the issue [...]]]></description>
			<content:encoded><![CDATA[<p>I have a sizable collection of music, so sizable in fact that I can&#8217;t store the full collection on any portal media.  Since I only use Windows to play video games, I use Rhythmbox to manage my music and found myself in need of a way to sync to a USB thumbdrive.  Now, the issue with this is that, by default, Rhythmbox doesn&#8217;t treat just any USB mass-storage device as an audio player, so I stumbled upon a post titled &#8220;<a href="http://www.m-phasis.de/2008/09/26/rhythmbox-and-usb-mass-storage-sync/">Rhythmbox and USB mass storage sync</a>&#8221; dealing with a similar problem.</p>
<p>All you need to do is create a file called &#8220;.is_audio_player&#8221; and add some content to it that&#8217;s something like this:</p>
<pre>audio_folders=music/
folder_depth=1
</pre>
<p>&#8230;and then scan removable media.  (Should be in the file menu)  One caveat you should be aware of is that I&#8217;m not sure if Rhythmbox will do any audio file conversion for you during the sync to your device.  But for moving a play list from one computer to another, this is plenty fine for me.</p>
]]></content:encoded>
			<wfw:commentRss>http://rrbits.com/epb/2010/06/23/rythmbox-sync-to-usb-device/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Embed Album Art into an MP3 with PHP</title>
		<link>http://rrbits.com/epb/2010/05/31/embed-album-art-into-an-mp3-with-php/</link>
		<comments>http://rrbits.com/epb/2010/05/31/embed-album-art-into-an-mp3-with-php/#comments</comments>
		<pubDate>Mon, 31 May 2010 10:55:11 +0000</pubDate>
		<dc:creator>epb</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[metadata]]></category>
		<category><![CDATA[mp3]]></category>

		<guid isPermaLink="false">http://rrbits.com/epb/?p=178</guid>
		<description><![CDATA[An odd quest perhaps: but adding album art to an MP3 (in ID3 tags) is readily doable with the KTaglib extension for PHP.  Once you have it, you can use a script like this to add artwork to an MP3: $mp3 = new KTaglib_MPEG_File('2.mp3'); $idv2 = $mp3-&#62;getID3v2Tag(true); $album = new KTaglib_ID3v2_AttachedPictureFrame(); $album-&#62;setType(KTaglib_ID3v2_AttachedPictureFrame::FrontCover); $album-&#62;setPicture('testalbum.jpg'); $album-&#62;setMimeType('image/jpeg'); $idv2-&#62;addFrame($album); [...]]]></description>
			<content:encoded><![CDATA[<p>An odd quest perhaps: but adding album art to an MP3 (in ID3 tags) is readily doable with the KTaglib extension for PHP.  Once you have it, you can use a script like this to add artwork to an MP3:</p>
<pre>$mp3 = new KTaglib_MPEG_File('2.mp3');
$idv2 = $mp3-&gt;<a href="http://www.php.net/manual/en/mpegfile.getId3v2Tag.php">getID3v2Tag</a>(true);
$album = new KTaglib_ID3v2_AttachedPictureFrame();
$album-&gt;setType(KTaglib_ID3v2_AttachedPictureFrame::FrontCover);
$album-&gt;setPicture('testalbum.jpg');
$album-&gt;setMimeType('image/jpeg');
$idv2-&gt;addFrame($album);
$mp3-&gt;save();</pre>
<p>Assuming no exceptions are thrown, this should allow you to set an image of your choosing as a FrontCover image  (of course replacing my example values with your own real values), consult the <a href="http://www.php.net/manual/en/book.ktaglib.php">KTaglib documentation</a> for more details and check &#8220;Predefined Constants&#8221; for the other image types.</p>
]]></content:encoded>
			<wfw:commentRss>http://rrbits.com/epb/2010/05/31/embed-album-art-into-an-mp3-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bad sectors on your hard drive?  Don&#8217;t throw it out yet.</title>
		<link>http://rrbits.com/epb/2010/05/21/bad-sectors-on-your-hard-drive-dont-throw-it-out-yet/</link>
		<comments>http://rrbits.com/epb/2010/05/21/bad-sectors-on-your-hard-drive-dont-throw-it-out-yet/#comments</comments>
		<pubDate>Sat, 22 May 2010 03:57:07 +0000</pubDate>
		<dc:creator>epb</dc:creator>
				<category><![CDATA[Problems]]></category>
		<category><![CDATA[computer problems]]></category>
		<category><![CDATA[hard drive]]></category>

		<guid isPermaLink="false">http://rrbits.com/epb/?p=175</guid>
		<description><![CDATA[This week I was working on a computer that was having problems with it&#8217;s hard drive.  I could get it to start once, and then it would fail to start up again.  As you can imagine, the drive had some bad sectors, but the people I was fixing this for could not afford another $60 [...]]]></description>
			<content:encoded><![CDATA[<p>This week I was working on a computer that was having problems with it&#8217;s hard drive.  I could get it to start once, and then it would fail to start up again.  As you can imagine, the drive had some bad sectors, but the people I was fixing this for could not afford another $60 expense to replace the drive.  So I had to try to find a way to fix the computer without replacing the drive.</p>
<p>And that&#8217;s when I learned this: Before you throw out a drive with bad sectors, try to run the manufacturers test and repair utilities on the hard drive.  Western Digital has its Digital Lifeguard software and I&#8217;m sure Seagate has a similar tool.  If you can attempt a repair with it, try the repair option.  If the repair fails, then you will likely need to get a new hard drive unfortunately.  Hopefully this will help you wring another couple of months out of your drive.  (Who knows, it may work for years after you do so.)</p>
]]></content:encoded>
			<wfw:commentRss>http://rrbits.com/epb/2010/05/21/bad-sectors-on-your-hard-drive-dont-throw-it-out-yet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Greasemonkey vs. Website</title>
		<link>http://rrbits.com/epb/2010/05/06/greasemonkey-vs-website/</link>
		<comments>http://rrbits.com/epb/2010/05/06/greasemonkey-vs-website/#comments</comments>
		<pubDate>Thu, 06 May 2010 10:05:40 +0000</pubDate>
		<dc:creator>epb</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://rrbits.com/epb/?p=167</guid>
		<description><![CDATA[I made a pretty normal trip to jlist (an online shop selling all manner of things Japanese) and for some reason thought: I bet I could change this store layout with Greasemonkey!  With a couple of hours of fiddling, I had managed to create a script that took their HTML and mangled it to my [...]]]></description>
			<content:encoded><![CDATA[<p>I made a pretty normal trip to <a href="http://jbox.com/">jlist</a> (an online shop selling all manner of things Japanese) and for some reason thought: I bet I could change this store layout with Greasemonkey!  With a couple of hours of fiddling, I had managed to create a script that took their HTML and mangled it to my bidding.  That makes me sound kinda evil doesn&#8217;t it? At any rate, you can do some pretty impressive stuff to a page with just JavaScript.  So you can poke it and whatnot fairly easily, I&#8217;m providing both in this zip file: <a href="http://rrbits.com/epb/files/2010/05/jlist-condense.zip">jlist condensing greasemonkey scripts</a></p>
<p>By default, when browsing by category, everything in is shown vertically with text and pictures.  I wanted to browse without scrolling so much, so at first I made this a greasemonkey userscript called &#8220;jlist-condense.user.js&#8221; and here&#8217;s the result with that one:</p>
<div id="attachment_169" class="wp-caption alignnone" style="width: 310px"><a href="http://rrbits.com/epb/files/2010/05/jlist_cond2.jpg" rel="lightbox[167]"><img class="size-medium wp-image-169" title="Condensed JList" src="http://rrbits.com/epb/files/2010/05/jlist_cond2-300x233.jpg" alt="" width="300" height="233" /></a><p class="wp-caption-text">JList with the first condensing script</p></div>
<p>So, I decided to continue playing around with the script and then made a &#8220;super-condensed&#8221; version that uses even less space.  It would break on things that don&#8217;t have pictures at the moment btw, but most everything on jlist does have a picture. Further, I was just me messing around with Greasemonkey script shenanigans.  All it is is product image with a reflection (because I can) that you can mouse over for the title and click to view the full product descriptions.</p>
<div id="attachment_170" class="wp-caption alignnone" style="width: 310px"><a href="http://rrbits.com/epb/files/2010/05/jlist-scond.jpg" rel="lightbox[167]"><img class="size-medium wp-image-170" title="Super-Condensed jlist" src="http://rrbits.com/epb/files/2010/05/jlist-scond-300x232.jpg" alt="" width="300" height="232" /></a><p class="wp-caption-text">Super-Condensed jlist greasemonkey script</p></div>
]]></content:encoded>
			<wfw:commentRss>http://rrbits.com/epb/2010/05/06/greasemonkey-vs-website/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SVG to online coloring-sheet SWF</title>
		<link>http://rrbits.com/epb/2010/03/12/svg-to-online-coloring-sheet-swf/</link>
		<comments>http://rrbits.com/epb/2010/03/12/svg-to-online-coloring-sheet-swf/#comments</comments>
		<pubDate>Sat, 13 Mar 2010 02:11:07 +0000</pubDate>
		<dc:creator>epb</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[flash]]></category>

		<guid isPermaLink="false">http://rrbits.com/epb/?p=163</guid>
		<description><![CDATA[You can do quite a bit of unorthodox stuff with PHP.  If you head over to epbsoft.com, you&#8217;ll find several flash coloring sheets I made with PHP, not Flash.  (Sort of anyway.)  I make them by first creating specially formatted SVG (Scalable Vector Graphics) files and feeding them to a PHP script that writes ActionScript [...]]]></description>
			<content:encoded><![CDATA[<p>You can do quite a bit of unorthodox stuff with PHP.  If you head over to epbsoft.com, you&#8217;ll find several <a href="http://epbsoft.com/coloring-sheets/">flash coloring sheets</a> I made with PHP, not Flash.  (Sort of anyway.)  I make them by first creating specially formatted SVG (Scalable Vector Graphics) files and feeding them to a PHP script that writes ActionScript files that are then compiled by MotionTwin ActionScript compiler.  As far as capabilities, it&#8217;s not all that capable.  I have to jump through a couple of hoops to make an SVG that my ActionScript generator can actually parse properly, but when it works, I like the results.</p>
<p><a href="http://rrbits.com/epb/files/2010/03/svg-to-coloring.php_.zip">svg-to-coloring.php.zip</a> &lt;&#8211; The source code is available if you want to take a look at how it works.</p>
]]></content:encoded>
			<wfw:commentRss>http://rrbits.com/epb/2010/03/12/svg-to-online-coloring-sheet-swf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MongoDB looks Interesting</title>
		<link>http://rrbits.com/epb/2010/03/03/mongodb-looks-interesting/</link>
		<comments>http://rrbits.com/epb/2010/03/03/mongodb-looks-interesting/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 21:12:02 +0000</pubDate>
		<dc:creator>epb</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[rambling]]></category>

		<guid isPermaLink="false">http://rrbits.com/epb/?p=160</guid>
		<description><![CDATA[I might take a look at installing MongoDB on my server.  I like the idea of a document-driven, NoSQL database, especially after working with relational SQL databases for years, and MongoDB looks interesting.  You can read more about it in Developing scalable PHP Applications using Mongo DB. What caught my interest is how flexible using [...]]]></description>
			<content:encoded><![CDATA[<p>I might take a look at installing MongoDB on my server.  I like the idea of a document-driven, NoSQL database, especially after working with relational SQL databases for years, and MongoDB looks interesting.  You can read more about it in <a href="http://www.phpclasses.org/blog/post/118-Developing-scalable-PHP-applications-using-MongoDB.html"><em>Developing scalable PHP Applications using Mongo DB</em></a>. What caught my interest is how flexible using it appears to be from the linked article.  Plus, using something other than a SQL database could be a nice change of pace.  I HATE adding fields to a SQL database table, and it looks nearly painless in these examples.</p>
<p>Another thing that seemed as though it were worth looking into is it&#8217;s apparently designed with storing whole files in mind.  I&#8217;ve stored files in MySQL databases before, but MySQL really isn&#8217;t designed with that in mind, but at the same time, if I&#8217;m going to be making a lot of small binary files, I don&#8217;t like them cluttering up my directories.</p>
]]></content:encoded>
			<wfw:commentRss>http://rrbits.com/epb/2010/03/03/mongodb-looks-interesting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mounting a VHD in Linux</title>
		<link>http://rrbits.com/epb/2010/01/17/mounting-a-vhd-in-linux/</link>
		<comments>http://rrbits.com/epb/2010/01/17/mounting-a-vhd-in-linux/#comments</comments>
		<pubDate>Sun, 17 Jan 2010 23:52:12 +0000</pubDate>
		<dc:creator>epb</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[fuse]]></category>
		<category><![CDATA[mounting]]></category>
		<category><![CDATA[vhd]]></category>

		<guid isPermaLink="false">http://rrbits.com/epb/?p=154</guid>
		<description><![CDATA[Let&#8217;s say you have a VHD file you&#8217;d like to access while in Linux without attaching it to a Virtual Machine.  There are many reasons you might like to do this, but it&#8217;s not immediately obvious how to do so with Linux. There are two ways I know of: You can use vmware-mount provided by [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s say you have a VHD file you&#8217;d like to access while in Linux without attaching it to a Virtual Machine.  There are many reasons you might like to do this, but it&#8217;s not immediately obvious how to do so with Linux.</p>
<p>There are two ways I know of:</p>
<p>You can use vmware-mount provided by VMWare Server.  I don&#8217;t actually like this method because VMWare Server is huge and I don&#8217;t use VMWare.  However, if you do, take a gander at this: <a href="http://www.vmware.com/support/reference/linux/loopback_linux.html">http://www.vmware.com/support/reference/linux/loopback_linux.html</a></p>
<p>The method I ultimately went with was <a href="http://forums.virtualbox.org/viewtopic.php?f=7&amp;t=17574">vdfuse</a> since I use VirtualBox.  It allows you to mount any disk image supported by VirtualBox.  Basically, if you follow the instructions at that the vdfuse forum link I just provided, you can mount the VHD to a mount point in your filesystem.  Now, this alone doesn&#8217;t yet give you access to your files yet.  It provides the partitions as standard files (and a file for the entire disk as well).  The partitions are named Partition1, Partition2, etc.  You can then mount the partition you want as a loopback device.</p>
]]></content:encoded>
			<wfw:commentRss>http://rrbits.com/epb/2010/01/17/mounting-a-vhd-in-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Deepest Sender</title>
		<link>http://rrbits.com/epb/2010/01/08/deepest-sender/</link>
		<comments>http://rrbits.com/epb/2010/01/08/deepest-sender/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 07:33:04 +0000</pubDate>
		<dc:creator>epb</dc:creator>
				<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://rrbits.com/epb/2010/01/08/deepest-sender/</guid>
		<description><![CDATA[Typing this from Deepest Sender (while listening to a remixes of Septette for the Dead Princess)&#160; It&#8217;s kinda nice and exactly what I was looking for &#8211; An extension for Firefox that allows you to post directly to your blog. (Of course you need XML RPC turned on to do so.)&#160; I note that it [...]]]></description>
			<content:encoded><![CDATA[<p>Typing this from Deepest Sender (while listening to a remixes of <a href="http://www.youtube.com/watch?v=xmM7_YleeJU&amp;videos=9GmQWz6Fsaw">Septette for the Dead Princess</a>)&nbsp; It&#8217;s kinda nice and exactly what I was looking for &#8211; An extension for Firefox that allows you to post directly to your blog. (Of course you need XML RPC turned on to do so.)&nbsp; I note that it can&#8217;t upload or resize photos for you, but that would kinda be feature bloat anyway, wouldn&#8217;t it? Ack, it seems to lack the ability to easily make headings and such as well, but you can add them with raw HTML in the source editting tab though.</p>
<p>For a quick one-off post like this, it seems as though it might be a useful tool to have at your disposal. </p>
<p>What&#8217;s better yet is that it allows you to save your post so you can come back to it later.&nbsp; (Might want to make sure you give it an XML file extension and don&#8217;t accidentally load the Kanji Dictionary XML file either.&nbsp; It really doesn&#8217;t like that.&nbsp; Oops.)</p>
<p>Looking for more Firefox blogging extensions?&nbsp; I found them at <a href="http://speckyboy.com/2008/08/24/13-essential-wordpress-related-firefox-extensions-make-blogging-easy/">speckboy design magazine</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://rrbits.com/epb/2010/01/08/deepest-sender/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Danbooru</title>
		<link>http://rrbits.com/epb/2010/01/02/installing-danbooru/</link>
		<comments>http://rrbits.com/epb/2010/01/02/installing-danbooru/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 09:41:05 +0000</pubDate>
		<dc:creator>epb</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://rrbits.com/epb/?p=125</guid>
		<description><![CDATA[I noticed a couple of searches for &#8216;running danbooru&#8217; in my search phrases for this site, so I decided to post a little bit more about that.  I assume someone searching for this was actually searching for help with installing danbooru.  Admittedly, I had some difficulty with it.  For one thing, I&#8217;d never used psql [...]]]></description>
			<content:encoded><![CDATA[<p>I noticed a couple of searches for &#8216;running danbooru&#8217; in my search phrases for this site, so I decided to post a little bit more about that.  I assume someone searching for this was actually searching for help with installing danbooru.  Admittedly, I had some difficulty with it.  For one thing, I&#8217;d never used psql in my life. <img src='http://rrbits.com/epb/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p>Here&#8217;s the <a href="http://rrbits.com/INSTALL.txt" target="_blank">INSTALL</a> file that&#8217;s packaged with the source code so you know what you&#8217;re getting yourself into before you even fetch the source tree from Subversion.</p>
<p><span id="more-125"></span>I should point out that installing Danbooru is not for the faint of heart.  You&#8217;ll need to know a bit about your linux distro and be comfortable (and have the requisite access) to install software packages as the root user.  An easier to install PHP-based clone, <a href="http://code.shishnet.org/shimmie2/" target="_blank">Shimmie</a>, might be more suitable for your project if you are not.</p>
<p>First thing, and I&#8217;ll copy this directly from the INSTALL file, you&#8217;ll need the following packages installed on your system ( or more up to date versions thereof): gcc, g++, make, readline, zlib, flex, bison, gd2, bzip2, postgresql-8.3, postgresql-contrib-8.3, ruby, rubygems, memcached, subversion, apache, and phusion passenger</p>
<p>Once you have all that, you&#8217;ll also need the following ruby gems: postgres, diff-lcs, html5, memcache-client, aws-s3, json, rails (version 2.2.2)</p>
<p>Now that you&#8217;ve hopefully collected everything together it&#8217;s time to get to work.</p>
<p>From the INSTALL &#8220;It&#8217;s recommended you create a dedicated [Postgres database] account for running the Danbooru database and/or web processes. &#8220;  I say do it.  It&#8217;s much easier than any other way I could think of setting this up.</p>
<ol>
<li>Use the createuser command while logged in as postgres to grant database access to the danbooru account.</li>
<li>You will need to update the pg_hba.conf file to grant your danbooru account trusted localhost access. Make sure to restart the database server (/etc/init.d/postgresql-8.3 restart) after making any changes.</li>
</ol>
<p>I should note that I had to make a couple of minor tweaks to get rails to actually connect to Postgres, but at the moment, I can&#8217;t remember what they were so hopefully you don&#8217;t run into the same problem I did.</p>
<p>The  rest is a fairly straightforward process, this is all taken verbatim from the most recent INSTALL file:</p>
<ol>
<li> To export from Subversion: &#8220;svn export svn://donmai.us/danbooru/trunk danbooru&#8221;</li>
<li> Recursively change the owner of this directory to the danbooru account: &#8220;chown -R danbooru:danbooru danbooru&#8221;</li>
<li> Create a public/data/sample directory.</li>
<li> Compile the resizer at lib/danbooru_image_resizer: &#8220;ruby extconf.rb &amp;&amp; make&#8221;. Do not make install it. If this fails you will need to figure out your gd2/libjpeg/libpng dependencies.</li>
<li> Create new database.yml and local_config.rb files in the config directory. Example files are provided.</li>
<li> Create the database: &#8220;createdb danbooru&#8221;</li>
<li> Load the schema: &#8220;psql danbooru &lt; db/postgres.sql&#8221;</li>
<li> Run the migrations: &#8220;RAILS_ENV=production rake db:migrate&#8221;</li>
<li> Start the job daemon: &#8220;RAILS_ENV=production app/daemons/job_task_processor_ctl.rb start&#8221;</li>
<li> You now need a way of managing the Rails process. The preferred method is using the Phusion Passenger module (see section below). Alternatively you can use Mongrel or fastcgi, there are several examples on the web.</li>
<li><span style="text-decoration: underline">[Not mentioned in INSTALL]</span> You might want to remove the advertisement stuff from the templates or replace it with your own.  It crashed my installation when I tried to view pages when not logged in as the administrator.</li>
</ol>
<p>I used <a href="http://scottstuff.net/blog/2005/07/20/apache-tuning-for-rails-and-fastcgi">FastCGI</a> myself actually, so I know nothing about Phusion.</p>
<p>I <em>might </em>run through the installation process again and create a VDI image in the future that can simply be connected to VirtualBox and booted so people can play around with it with minimal hassle.  (That minimal hassle being setting the IP address.  I don&#8217;t know enough about Linux boot scripts to have it ask you by default to provide one.)</p>
<p>Sorry, that&#8217;s all the help I can deliver today, unfortunately, it&#8217;s been a while since I had done this.  Also, I&#8217;m a bit tired.</p>
]]></content:encoded>
			<wfw:commentRss>http://rrbits.com/epb/2010/01/02/installing-danbooru/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
