<?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>It's not a blog, It's a feature &#187; Grails</title>
	<atom:link href="http://javazquez.com/juan/category/grails/feed/" rel="self" type="application/rss+xml" />
	<link>http://javazquez.com/juan</link>
	<description>Juan A. Vazquez</description>
	<lastBuildDate>Wed, 16 Nov 2011 02:45:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Adding and Resizing Images with Grails</title>
		<link>http://javazquez.com/juan/2009/01/24/adding-and-resizing-images-with-grails/</link>
		<comments>http://javazquez.com/juan/2009/01/24/adding-and-resizing-images-with-grails/#comments</comments>
		<pubDate>Sat, 24 Jan 2009 18:58:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[imageTools]]></category>
		<category><![CDATA[pictures]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://javazquez.com/juan/?p=179</guid>
		<description><![CDATA[Just wanted to provided a working example for those that are entering the Grails territory for the first time.]]></description>
			<content:encoded><![CDATA[<p>Here is a quick post on how to upload images within your Grails project to your file system(rather than your database). It seems simple enough, but I ran into a few snags as I was working on one of my projects. Just wanted to provided a working example for those that are entering the Grails territory for the first time. Happy Coding!</p>
<p>I am using the imageTools plugin which you can read more about <a href="http://grails.org/ImageTools+plugin">here</a> </p>
<p><strong>NOTE: </strong>The imageTools plugin has been criticized for its low quality of output. ImageMagick may be a better fit for you project(s). My particular project didn&#8217;t call for high quality pictures. A quick google search for &#8220;imagemagick for grails&#8221; should get you started on your way.</p>
<p>I am using version 1.0.3 in the example below</p>
<p><strong>to install, I ran the following command from my grails application&#8217;s root directory</strong></p>
<p><code>grails install-plugin http://www.arquetipos.co.cr/blog/files/grails-image-tools-1.0.3.zip</code></p>
<p><strong>Domain-Class</strong><br />
<code><br />
class Picture {<br />
byte[] imagefile<br />
//Any other stuff you want to track</p>
<p>}<br />
</code></p>
<p><strong>Controller Code for Saving an image</strong><br />
<code><br />
    def save = {</p>
<p>		def downloadedfile = request.getFile('imagefile')<br />
	 	def pictureInstance = new Picture(params)<br />
		def imageTool = new ImageTool()</p>
<p>     	       if(downloadedfile &#038;&#038; pictureInstance.save()){<br />
			String imagepath = grailsAttributes.getApplicationContext().getResource("images/").getFile().toString() + 	File.separatorChar + "${pictureInstance.id}.jpg"<br />
			downloadedfile.transferTo(new File(imagepath))</p>
<p>			imageTool.load(imagepath)<br />
			imageTool.thumbnail(140)</p>
<p>			imageTool.writeResult(imagepath, "JPEG")<br />
			imageTool.square()<br />
            flash.message = "Picture ${pictureInstance.id} created"<br />
            redirect(action:show,id:pictureInstance.id)<br />
        }<br />
        else {<br />
           render(view:'create',model:[pictureInstance:pictureInstance])<br />
        }<br />
    }<br />
</code><br />
<strong>Code for displaying the image in both the &#8216;show&#8217; and &#8216;list&#8217; views</strong><br />
<code><br />
	&lt;td&gt;&lt;img  src="${createLinkTo(dir:'images', file: pictureInstance.id+'.jpg' )}" /&gt; &lt;/td&gt;<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://javazquez.com/juan/2009/01/24/adding-and-resizing-images-with-grails/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

