# RMagick and thumbnails

**URL:** <https://www.ruby-forum.com/t/rmagick-and-thumbnails/56066>\
**Category:** Rails\
**Created:** [March 27, 2006, 9:43pm UTC](https://www.ruby-forum.com/t/rmagick-and-thumbnails/56066 "2006-03-27T21:43:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lindsay\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ecae2f/32.png) [@Lindsay\_B](https://www.ruby-forum.com/u/Lindsay_B)\
**Post date:** [March 27, 2006, 9:43pm UTC](https://www.ruby-forum.com/t/rmagick-and-thumbnails/56066/1 "2006-03-27T21:43:52Z")

</div>

I’ve based my code on the Agile example for uploading files, pages  
362-365. I’ve successfully loaded the Picture object to the database,  
but I come unstuck when trying to replicate this for a thumbnail version  
of the original image:

```
      thumbnail = Thumbnail.new
      thumbnail.name = 'thumbnail_' + @picture.name.to_s
      thumbnail.content_type = @picture.content_type
      thumbnail.data = @picture.data
      thumbnail.make_thumbnail
      thumbnail.save

```

I get the following error on the make\_thumbnail method:

ArgumentError (can’t decode image):  
/app/models/thumbnail.rb:11:in `read_inline' /app/models/thumbnail.rb:11:in`make\_thumbnail’

Here’s the Thumbnail model:

require ‘RMagick’  
include Magick

def make\_thumbnail  
img = Image.read\_inline(self.data)  
…  
end

What do I have to do to thumbnail.data to get RMagick to read it?

Lindsay

---

<div class="post-metadata">

**Author:** ![Lindsay\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ecae2f/32.png) [@Lindsay\_B](https://www.ruby-forum.com/u/Lindsay_B)\
**Post date:** [March 27, 2006, 10:24pm UTC](https://www.ruby-forum.com/t/rmagick-and-thumbnails/56066/2 "2006-03-27T22:24:33Z")

</div>

You should go the easy way by :

- using mini\_magick instead rmagick (less memory foot print)
- storing your pictures on disk instead on db

In that case, handling file upload is quite simple.

Look here : [Image manipulation/resizing server-side? - Rails - Ruby-Forum](http://www.ruby-forum.com/topic/59545#new)

---

<div class="post-metadata">

**Author:** ![Lindsay\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ecae2f/32.png) [@Lindsay\_B](https://www.ruby-forum.com/u/Lindsay_B)\
**Post date:** [March 27, 2006, 10:33pm UTC](https://www.ruby-forum.com/t/rmagick-and-thumbnails/56066/3 "2006-03-27T22:33:07Z")

</div>

Christophe G. wrote:

> You should go the easy way by :
> 
> - using mini\_magick instead rmagick (less memory foot print)
> - storing your pictures on disk instead on db
> 
> In that case, handling file upload is quite simple.
> 
> Look here : [Image manipulation/resizing server-side? - Rails - Ruby-Forum](http://www.ruby-forum.com/topic/59545#new)

I would prefer to store the images in the database - but I’ll definitely  
look into mini\_magick. Thanks.

---

<div class="post-metadata">

**Author:** ![Lindsay\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ecae2f/32.png) [@Lindsay\_B](https://www.ruby-forum.com/u/Lindsay_B)\
**Post date:** [March 28, 2006, 2:53am UTC](https://www.ruby-forum.com/t/rmagick-and-thumbnails/56066/4 "2006-03-28T02:53:38Z")

</div>

Lindsay B. wrote:

> What do I have to do to thumbnail.data to get RMagick to read it?

According to my reading of the RMagick docs, read\_inline takes a  
Base64-encoded string. Is your @picture.data encoded, or raw?

–Al Evans
