Recreating thumbnails with attachment_fu

Posted on May 25, 2008

In one of my apps, the need arose to use a new thumbnail size (using attachment_fu). My problem was I had a ton of existing images that I would have to create this thumbnail size for. But how? A google search didn’t turn up much. So i threw together a little instance method that would make quick and short work or creating (or re-creating) a thumbnail for images i already had in my database. I just stuck it in an initializer with my other attachment_fu hacks. It goes a little something like this


module Technoweenie 
  module AttachmentFu
    module InstanceMethods
      def create_thumbnail_size(target_size)
        actual_size = self.attachment_options[:thumbnails][target_size]
        raise "this class doesn't have a thubnail size for #{target_size}" if actual_size.nil?
        tmp = self.create_temp_file
        self.create_or_update_thumbnail(tmp, target_size.to_s, actual_size)
        FileUtils.rm_rf(Dir.glob(File.join(RAILS_ROOT, 'tmp', 'attachment_fu', '*')))
      end
    end
  end
end

nothing fancy and by no means the “best it could be” but meh, it gets the job done for me. Here an example of usage:

Say you have an Avatar class that you stuck your “has_attachment” on and you’ve decided you want to generate thumbnails of a new size. You designate this new size as “smaller” (in your has_attachment options, you’ve added it like so, :thumbnails => {:thumb => ‘75×75>’, :smaller => ‘25×25>‘}). To create “smaller” avatar thumbnails, you’d grab all the avatars that need one and call create_thumbnail_size on each one. Like so…
avatar. create_thumbnail_size(:smaller)

Voila. Thumbnails are recreated and you can move on. cheers!

With Ruby 1.9 comes an updated version of the PickAxe!

Posted on December 15, 2007
With Ruby 1.9 on the horizon it’s good to see the Pargmatic crew release an updated version of their Programming Ruby book, also known by it’s one-word moniker, the PickAxe. This book has singlehandedly taught scores of people the inner nuances of Ruby and without it, learning the language would’ve been that much harder.

The Ruby 1.9 PickAxe is currently only available in beta form but the $59.95 for the beta and paperback version is sure to be money well spent.

Breaking down what's new in Ruby 1.9

Posted on December 15, 2007

For the Rubists out there who didn’t know, there’s a nice breakdown of what’s new in Ruby 1.9 over at Eigenclass and by “breakdown” I mean extremely long list. It makes for pretty decent “casual perusal” material.

I like the JSON-esque literal Hash syntax and how File.exists? is deprecated. Always wondered about why “exists?” and “exist?”, umm, existed.

ZOMG Microsoft shows Ruby some serious love

Posted on May 01, 2007

Microsoft pretty much shocked and awed the whole world today with a number of announcements they unleashed today at MIX07, most of which were about their “does everything” Silverlight platform. The platform itself, and it’s ability to stream 720p content at native full screen size, is fun and exciting but what puts that glazed cherry on top is that Microsoft has added a little CLR to Silverlight, that includes support for Ruby! That’s right, all you Ruby developers will now be able to shower the world with gifts of cross-browser and cross-platform awesomeness. Silverlight also supports Javascript and some other languages but seriously, Ruby is the only one you needed to know about (well, the python bit is cool too).

I cannot wait to get a crack at programming some goodies on this Silverlight platform. The piece on TechCrunch spoke of a demo that sounded pretty rad. Goodbye Actionscript, hello Ruby…again.

Here’s an interview with the creator of the RubyCLR, John Lam.