<?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>rabidGadfly &#187; thumbnails</title>
	<atom:link href="http://rabidgadfly.com/tag/thumbnails/feed/" rel="self" type="application/rss+xml" />
	<link>http://rabidgadfly.com</link>
	<description>Simple Solutions to Nagging Coding Problems</description>
	<lastBuildDate>Wed, 19 Oct 2011 13:43:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Use &lt;CFIMAGE&gt; to Generate Temporary Thumbnails</title>
		<link>http://rabidgadfly.com/2008/06/use-cfimage-to-generate-temporary-thumbnails/</link>
		<comments>http://rabidgadfly.com/2008/06/use-cfimage-to-generate-temporary-thumbnails/#comments</comments>
		<pubDate>Fri, 20 Jun 2008 14:10:19 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[coldFusion]]></category>
		<category><![CDATA[cfimage]]></category>
		<category><![CDATA[thumbnails]]></category>

		<guid isPermaLink="false">http://www.rabidgadfly.com/?p=66</guid>
		<description><![CDATA[I&#8217;m wrapping up a sizable project that required 200&#215;200 thumbnails for about two thousand pieces of content. The agency I&#8217;m working with required properly-sized thumbnails to proceed with their testing. Unfortunately, thumbnails did not exist at that point. ColdFusion &#60;CFIMAGE&#62; to the rescue! By using &#60;CFIMAGE&#62;, I was able to generate thumbnails for every piece [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m wrapping up a sizable project that required 200&#215;200 thumbnails for about two thousand pieces of content. The agency I&#8217;m working with required properly-sized thumbnails to proceed with their testing. Unfortunately, thumbnails did not exist at that point.</p>
<p>ColdFusion &lt;CFIMAGE&gt; to the rescue!</p>
<p>By using &lt;CFIMAGE&gt;, I was able to generate thumbnails for every piece of content in under 30 seconds. To add a little variety into the mix I created five different base images named thumb1.jpg &#8211; thumb5.jpg and chose one at random for each record. As I looped through the table that contained the content records, I used the content record&#8217;s ID (an auto-generated integer) as the filename and updated the thumbnail field as I went along.</p>
<p>The code I used looks something like this:</p>
<pre><code>
<cfsetting requestTimeOut = "9999">

<cfquery name="qContent"  datasource="myDS">
	select *
	from content
</cfquery>

<cfset thumbpath= ExpandPath("/images/tempthumbs/") />

<cfoutput>

<cfloop query="qContent">

	<cfset thumbnum = RandRange( 1, 5, "SHA1PRNG" )>
	<cfset thumbname = "thumb#thumbnum#.jpg">

	<cfimage source="#thumbpath##thumbname#" name="contentThumb">
	<cfset ImageDrawText(contentThumb, "#content_name#", 5, 15)>
	<cfimage source="#contentThumb#" action="write" destination="#thumbpath##qContent.contentID#.jpg" overwrite="yes">

	<cfquery name="updContent" datasource="myDS">
		UPDATE	content
		SET	thumbnail_image='http://www.mydomain.com/images/tempthumbs/#qContent.contentID#.jpg'
		WHERE	contentID = '#contentID#'
	</cfquery>

</cfloop>

</cfoutput>
</code>

</code></pre>
<p>The &#8220;cfset imageDrawText&#8221; line is the one that adds the text contained in the content_name column to the image. It also places the caption 5px in and 15px down from the top left corner of the image.</p>
<p>When the code finishes I have unique thumbnails for each piece of content.</p>
<p>-rG</p>
]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2008/06/use-cfimage-to-generate-temporary-thumbnails/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

