DISQUS

OLD Bamboo Blog: Super simple image resizing

  • James Urquhart · 2 years ago
    For the user and company avatars in RailsCollab, i just installed the GD2 bindings for ruby and ended up with this relatively simple code.

    max_width = AppConfig.max_logo_width
    max_height = AppConfig.max_logo_height

    begin
    data = value.read
    image = GD2::Image.load(data)
    image.resize!(image.width > max_width ? max_width : image.width,
    image.height > max_height ? max_height : image.height)
    rescue
    self.errors.add(:avatar, "Invalid data")
    return
    end

    Granted, could be simpler. But it works. ;)
  • Learn To Write · 2 years ago
    C'mon, isn't Super Simple good enough? Can't you express yourself without "f*****" and "goddam"? Grow up!
  • Steve · 2 years ago
    ImageMagick is a pain to install?

    apt-get install imagemagick librmagick-ruby
  • sharnik · 2 years ago
    Steve:
    Yes, because when you do 'apt-get install imagemagick librmagick-ruby' it still doesn't work. Not on my system, anyway.
  • Justin · 2 years ago
    f****** could mean anything! I for one read it as "fancy".

    Anyway, this looks awesome. Someone should add it as a processor for attachment_fu...
  • Mak · 2 years ago
    You could say what all the funny kids are saying these days:
    It's Sofa King Simple!

    Nice utility, I've been using ImageScience with pleasant results, but I'm really looking forward to trying this out. Not only will my code base shrink I can eliminate the _one_ compiled from source application on my servers.
  • Damien Tanner · 2 years ago
    Justin: Of course... it was actually super 'fascinating' .

    Mak: Ha. I'm using it in a little merb app and it's so much faster than imagemagick. In fact, here ([attachment_pu.rb](http://blog.new-bamboo.co.uk/assets/2007/12/7/attachment_pu.rb)) is the little merb lib which I'm using for attachments. Very simple, S3 and more will be added as time goes on.
  • Stephen Sykes · 2 years ago
    Thanks for this. In fact I just needed to find the dimensions of my images, but your code proved very helpful - I modded it to just return the dimensions. I made an entry in my blog ( http://pennysmalls.com ) with the code.