<?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>Chapter 42 &#187; images</title>
	<atom:link href="http://chapter42.whitewhale.net/tag/images/feed/" rel="self" type="application/rss+xml" />
	<link>http://chapter42.whitewhale.net</link>
	<description></description>
	<lastBuildDate>Thu, 30 Sep 2010 17:20:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Resizing images to fit</title>
		<link>http://chapter42.whitewhale.net/2008/07/22/resizing-images-to-fit/</link>
		<comments>http://chapter42.whitewhale.net/2008/07/22/resizing-images-to-fit/#comments</comments>
		<pubDate>Tue, 22 Jul 2008 15:50:40 +0000</pubDate>
		<dc:creator>Donald</dc:creator>
				<category><![CDATA[Behind the scenes]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[images]]></category>
		<category><![CDATA[livewhale]]></category>
		<category><![CDATA[lwblog]]></category>
		<category><![CDATA[photos]]></category>
		<category><![CDATA[resizing]]></category>

		<guid isPermaLink="false">http://chapter42.whaleblogs.net/?p=68</guid>
		<description><![CDATA[Last week, we flew Alex out to the Bay Area for some company togetherness and to devote some serious time to the aforementioned yet still-unannounced internal project. An also-secret major feature of said project required us to use PHP to place arbitrarily-selected images in arbitrarily-sized spaces (without, of course, unattractively stretching or squishing the image).
With [...]]]></description>
			<content:encoded><![CDATA[<p>Last week, we flew Alex out to the Bay Area for some company togetherness and to devote some serious time to the aforementioned yet still-unannounced internal project. An also-secret major feature of said project required us to use PHP to place arbitrarily-selected images in arbitrarily-sized spaces (without, of course, unattractively stretching or squishing the image).</p>
<p>With some thought, we were able to come up with a taxonomy of content photo sizing:<span id="more-68"></span></p>
<ol>
<li>Constrained horizontally (e.g. in a sidebar):<br />
<a href="http://www.whitewhale.net/wordpress/wp-content/uploads/2008/07/constrain_horizontal.jpg"><img class="alignnone size-medium wp-image-69" title="constrain_horizontal" src="http://www.whitewhale.net/wordpress/wp-content/uploads/2008/07/constrain_horizontal.jpg" alt="Constrained horizontally" width="124" height="104" /></a><a href="http://www.whitewhale.net/wordpress/wp-content/uploads/2008/07/constrain_horizontal.jpg"><br />
</a></li>
<li>Constrained vertically (e.g. to align alongside text):<br />
<a href="http://www.whitewhale.net/wordpress/wp-content/uploads/2008/07/contrain_vertical.jpg"><img class="alignnone size-medium wp-image-73" title="contrain_vertical" src="http://www.whitewhale.net/wordpress/wp-content/uploads/2008/07/contrain_vertical.jpg" alt="Constrained vertically" width="224" height="104" /></a></li>
<li>Constrained both horizontally and vertically within a box:<br />
<a href="http://www.whitewhale.net/wordpress/wp-content/uploads/2008/07/constrain_both_nocrop.jpg"><img class="alignnone size-medium wp-image-71" title="constrain_both_nocrop" src="http://www.whitewhale.net/wordpress/wp-content/uploads/2008/07/constrain_both_nocrop.jpg" alt="" width="104" height="104" /></a></li>
<li>Constrained both horizontally and vertically to fill the box, with the edges lobbed off automatically (e.g. when needed as specific design element):<br />
<a href="http://www.whitewhale.net/wordpress/wp-content/uploads/2008/07/contrain_both_crop.jpg"><img class="alignnone size-medium wp-image-72" title="contrain_both_crop" src="http://www.whitewhale.net/wordpress/wp-content/uploads/2008/07/contrain_both_crop.jpg" alt="Constrained both horizontally and vertically, and cropped" width="146" height="104" /></a></li>
</ol>
<p>I thought the fourth case would be the only troublesome one, but we knocked out uses 1, 2, and 4 rather quickly. Use 3, however, proved to be a problem; we just couldn&#8217;t get it to size appropriately for every test case. Unlike the others, it was unclear what dimension to constrain to: it varies not only for the same image placed in different spaces, but also for different images in the same-sized space:<br />
<a href="http://www.whitewhale.net/wordpress/wp-content/uploads/2008/07/4cases.jpg"><img class="alignnone size-medium wp-image-70" title="4cases" src="http://www.whitewhale.net/wordpress/wp-content/uploads/2008/07/4cases.jpg" alt="Four different uses" width="265" height="247" /></a></p>
<p>It was one of those problems that is as easy to describe&#8211;&#8221;fit the image in the box&#8221;&#8211;but hard to wrap your mind around programatically. We knew there must be simple logic to it, but despite examples in Photoshop and repeatedly walking through the problem we were <a href="http://www.whitewhale.net/wordpress/wp-content/uploads/2008/07/whiteboard.jpg">having trouble making sense of it</a>. Finally, we realized that the key comparison is the ratios of the images: if height<sub>original</sub>:width<sub>original</sub> &gt; height<sub>target</sub>:width<sub>target</sub> constrain by height; otherwise, constrain by width. We actually managed to make an educated guess at the solution before we fully understood the problem, but we did <a href="http://www.whitewhale.net/wordpress/wp-content/uploads/2008/07/penandpaper.jpg">some old-fashioned pen-and-paper work</a> to prove ourselves right.</p>
<p>The ins-and-outs of this backend code and logic no doubt are pretty dry to much of our audience. But this sort of problem is one of my favorite parts of my job: working through the logic of it is completely fun stuff to my inner geek, but more importantly there&#8217;s a great satisfaction in knowing you&#8217;ve found that killer solution. When you get home, it&#8217;s hard to explain to your significant other why spending the afternoon on this one simple function wasn&#8217;t a waste of time&#8211;heck, sometimes it&#8217;s tough to get that across to your boss. But here&#8217;s a case where, by taking that time, we were able to both clearly define all the ways we employ content photos on the design-side and create a single function that quickly fits any given photo to those uses. And that not only solves an immediate goal, but we can take that solution with us. We nailed it. And we may never need to think about image sizing again.</p>
]]></content:encoded>
			<wfw:commentRss>http://chapter42.whitewhale.net/2008/07/22/resizing-images-to-fit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

