<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: On-demand thumbnails with Rails and rmagick</title>
	<atom:link href="http://blog.jcoglan.com/2008/03/23/on-demand-thumbnails-with-rails-and-rmagick/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jcoglan.com/2008/03/23/on-demand-thumbnails-with-rails-and-rmagick/</link>
	<description>This dirt was a building before</description>
	<pubDate>Wed, 20 Aug 2008 16:51:31 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
		<item>
		<title>By: James</title>
		<link>http://blog.jcoglan.com/2008/03/23/on-demand-thumbnails-with-rails-and-rmagick/#comment-3126</link>
		<dc:creator>James</dc:creator>
		<pubDate>Thu, 10 Apr 2008 20:51:41 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jcoglan.com/2008/03/23/on-demand-thumbnails-with-rails-and-rmagick/#comment-3126</guid>
		<description>Mic, first off what I tend to do is add a method for grabbing the dimensions of an image:

&lt;pre&gt;&lt;code&gt;module ImageTools
  class &lt;&lt; self
    def dimensions(source)
      img = Image.read(source).first
      img.rows, img.columns
    end
  end
end&lt;/code&gt;&lt;/pre&gt;

Then in your model, use a before_validation hook:

&lt;pre&gt;&lt;code&gt;class MyModel &lt; ActiveRecord::Base
  before_validation :set_dimensions!
  def set_dimensions!
    rows, cols = ImageTools.dimensions(self.file_path)
    self.width = cols
    self.height = rows
    self.aspect_ratio = cols.to_f / rows
  end
end&lt;/code&gt;&lt;/pre&gt;

Hope that helps.</description>
		<content:encoded><![CDATA[<p>Mic, first off what I tend to do is add a method for grabbing the dimensions of an image:</p>
<pre><code>module ImageTools
  class < < self
    def dimensions(source)
      img = Image.read(source).first
      img.rows, img.columns
    end
  end
end</code></code></pre>
<p>Then in your model, use a before_validation hook:</p>
<pre><code>class MyModel < ActiveRecord::Base
  before_validation :set_dimensions!
  def set_dimensions!
    rows, cols = ImageTools.dimensions(self.file_path)
    self.width = cols
    self.height = rows
    self.aspect_ratio = cols.to_f / rows
  end
end</code></code></pre>
<p>Hope that helps.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mic Pringle</title>
		<link>http://blog.jcoglan.com/2008/03/23/on-demand-thumbnails-with-rails-and-rmagick/#comment-3125</link>
		<dc:creator>Mic Pringle</dc:creator>
		<pubDate>Tue, 08 Apr 2008 20:46:16 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jcoglan.com/2008/03/23/on-demand-thumbnails-with-rails-and-rmagick/#comment-3125</guid>
		<description>Hi,

This is a great article, and something that I've been searching for, for a while now.

However, you say ...

''It helps if your model includes an aspect_ratio field, which is generated from the original image on upload''

... and I was just wondering how you achieve this ? 

(I'm new to image processing, but it's kinda key to an app I'm developing)

Thanks

-Mic</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>This is a great article, and something that I&#8217;ve been searching for, for a while now.</p>
<p>However, you say &#8230;</p>
<p>&#8221;It helps if your model includes an aspect_ratio field, which is generated from the original image on upload&#8221;</p>
<p>&#8230; and I was just wondering how you achieve this ? </p>
<p>(I&#8217;m new to image processing, but it&#8217;s kinda key to an app I&#8217;m developing)</p>
<p>Thanks</p>
<p>-Mic</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James</title>
		<link>http://blog.jcoglan.com/2008/03/23/on-demand-thumbnails-with-rails-and-rmagick/#comment-3087</link>
		<dc:creator>James</dc:creator>
		<pubDate>Mon, 24 Mar 2008 19:01:26 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jcoglan.com/2008/03/23/on-demand-thumbnails-with-rails-and-rmagick/#comment-3087</guid>
		<description>Thanks, Marcos. I did originally put in some size-checking code in the example but took it out as it obscured the main point somewhat. What I tend to do is write a quick rake task for flushing the thumbnail cache and run it as a housekeeping job. You could get your application do do this job intermittently as well.</description>
		<content:encoded><![CDATA[<p>Thanks, Marcos. I did originally put in some size-checking code in the example but took it out as it obscured the main point somewhat. What I tend to do is write a quick rake task for flushing the thumbnail cache and run it as a housekeeping job. You could get your application do do this job intermittently as well.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marcos Kuhns</title>
		<link>http://blog.jcoglan.com/2008/03/23/on-demand-thumbnails-with-rails-and-rmagick/#comment-3086</link>
		<dc:creator>Marcos Kuhns</dc:creator>
		<pubDate>Mon, 24 Mar 2008 17:56:28 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jcoglan.com/2008/03/23/on-demand-thumbnails-with-rails-and-rmagick/#comment-3086</guid>
		<description>Nice implementation. I love that it gives the developer the flexibility to change their mind about thumbnail sizes at any point. The only problem I see is that a malicious user could easily fill up your hard-drive by repeatedly requesting thumbnails with increasing dimensions. This is easily fixed by limiting the allowed dimensions in your controller. If someone requests an invalid thumbnail size, send them either an error message or the closest available thumbnail. Not a show-stopping problem, I just wanted to point that out before people start using the above code on their production servers.</description>
		<content:encoded><![CDATA[<p>Nice implementation. I love that it gives the developer the flexibility to change their mind about thumbnail sizes at any point. The only problem I see is that a malicious user could easily fill up your hard-drive by repeatedly requesting thumbnails with increasing dimensions. This is easily fixed by limiting the allowed dimensions in your controller. If someone requests an invalid thumbnail size, send them either an error message or the closest available thumbnail. Not a show-stopping problem, I just wanted to point that out before people start using the above code on their production servers.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
