# Im trying to make Thumbnail pics -- any suggestions?

**URL:** <https://rubytalk.org/t/im-trying-to-make-thumbnail-pics-any-suggestions/42580>\
**Category:** ruby-talk\
**Created:** [28 November 2007 17:35 UTC](https://rubytalk.org/t/im-trying-to-make-thumbnail-pics-any-suggestions/42580 "2007-11-28T17:35:00Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wiz\_Pendases](https://avatars.discourse-cdn.com/v4/letter/w/34f0e0/32.png) [@Wiz\_Pendases](https://rubytalk.org/u/Wiz_Pendases)\
**Post date:** [28 November 2007 17:35 UTC](https://rubytalk.org/t/im-trying-to-make-thumbnail-pics-any-suggestions/42580/1 "2007-11-28T17:35:00Z")

</div>

Im trying to make Thumbnail pics -- any suggestions? (dont know wher  
to start)

---

<div class="post-metadata">

**Author:** ![Piyush\_Ranjan](https://avatars.discourse-cdn.com/v4/letter/p/a587f6/32.png) [@Piyush\_Ranjan](https://rubytalk.org/u/Piyush_Ranjan)\
**Post date:** [28 November 2007 17:45 UTC](https://rubytalk.org/t/im-trying-to-make-thumbnail-pics-any-suggestions/42580/2 "2007-11-28T17:45:04Z")

</div>

Use rmagick which is a sort of a ruby binding on ImageMagick and  
grpahicsmagick

> **···**
>
> On Nov 28, 2007 11:05 PM, \<wiz\_pendases@yahoo.com\> wrote:
> 
> > Im trying to make Thumbnail pics -- any suggestions? (dont know wher  
> > to start)

---

<div class="post-metadata">

**Author:** ![Tom\_Reilly](https://avatars.discourse-cdn.com/v4/letter/t/9de0a6/32.png) [@Tom\_Reilly](https://rubytalk.org/u/Tom_Reilly)\
**Post date:** [28 November 2007 23:01 UTC](https://rubytalk.org/t/im-trying-to-make-thumbnail-pics-any-suggestions/42580/3 "2007-11-28T23:01:39Z")

</div>

wiz\_pendases@yahoo.com wrote:

> Im trying to make Thumbnail pics -- any suggestions? (dont know wher  
> to start)

# Make Thumb Nails  
# This works fine to make thumbnails for my web site  
# lots of luck  
#Tom Reilly

require 'rmagick'  
include Magick

def rsz(hgt,wdt,msze)  
&nbsp;&nbsp;&nbsp;&nbsp;if hgt \> wdt  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;r = msze.to\_f / hgt.to\_f  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return [msze, (wdt.to\_f \* r).to\_i]  
&nbsp;&nbsp;&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;r = msze.to\_f / wdt.to\_f  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return [(hgt.to\_f \* r).to\_i, msze]  
&nbsp;&nbsp;&nbsp;&nbsp;end  
end

tnDir = ".\\"  
jpgArray = Array.new  
dir = Dir.new(tnDir)  
dir.each do |d|  
&nbsp;&nbsp;&nbsp;&nbsp;jpgArray.push(d) if d =~ /jpg/  
end

pix = ImageList.new  
jpgArray.each {|x| pix.read(x) if x .downcase =~ /jpg/}

pix.each do |x|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rows = x.rows  
&nbsp;&nbsp;&nbsp;&nbsp;columns = x.columns  
&nbsp;&nbsp;&nbsp;&nbsp;factor1 = 200  
&nbsp;&nbsp;&nbsp;&nbsp;factor2 = 450  
&nbsp;&nbsp;&nbsp;&nbsp;a = rsz(columns,rows,factor1)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x.resize!(a[0],a[1])  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#img.resize!(cols,rows)  
# img2 = x.frame  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x.write(".\\stamp\\#{"t" + x.filename}")  
end

---

<div class="post-metadata">

**Author:** ![Eric\_Tucker](https://avatars.discourse-cdn.com/v4/letter/e/59ef9b/32.png) [@Eric\_Tucker](https://rubytalk.org/u/Eric_Tucker)\
**Post date:** [28 November 2007 18:08 UTC](https://rubytalk.org/t/im-trying-to-make-thumbnail-pics-any-suggestions/42580/4 "2007-11-28T18:08:10Z")

</div>

I am using rmagick. However, I hear good things about imagescience if your needs featurewise are more modest.  
Sent wirelessly via BlackBerry from T-Mobile.

> **···**
>
> -----Original Message-----  
> From: "Piyush Ranjan" \<piyush.pr@gmail.com\>
> 
> Date: Thu, 29 Nov 2007 02:45:04  
> To:ruby-talk@ruby-lang.org (ruby-talk ML)  
> Subject: Re: Im trying to make Thumbnail pics -- any suggestions?
> 
> Use rmagick which is a sort of a ruby binding on ImageMagick and  
> grpahicsmagick
> 
> On Nov 28, 2007 11:05 PM, \<wiz\_pendases@yahoo.com\> wrote:
> 
> > Im trying to make Thumbnail pics -- any suggestions? (dont know wher  
> > to start)

---

<div class="post-metadata">

**Author:** ![Aredridel1](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@Aredridel1](https://rubytalk.org/u/Aredridel1)\
**Post date:** [28 November 2007 18:27 UTC](https://rubytalk.org/t/im-trying-to-make-thumbnail-pics-any-suggestions/42580/5 "2007-11-28T18:27:50Z")

</div>

Or ImageScience or the epeg library

> **···**
>
> On Nov 28, 2007, at 10:45 AM, Piyush Ranjan wrote:
> 
> > Use rmagick which is a sort of a ruby binding on ImageMagick and  
> > grpahicsmagick

---

<div class="post-metadata">

**Author:** ![Ryan\_Davis1](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/ryan_davis1/32/1848_2.png) [@Ryan\_Davis1](https://rubytalk.org/u/Ryan_Davis1)\
**Post date:** [29 November 2007 00:29 UTC](https://rubytalk.org/t/im-trying-to-make-thumbnail-pics-any-suggestions/42580/6 "2007-11-29T00:29:25Z")

</div>

Blech!

This is exactly why I wrote image\_science... well, that and installing ImageMagick/rmagick was always a PITA.

require 'rubygems'  
require 'image\_science'

Dir["\*.jpg"].each do |file|  
&nbsp;&nbsp;&nbsp;ImageScience.with\_image(file) do |img|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;img.thumbnail(200) do |thumb|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;thumb.save "#{file.sub(/.jpg$/, '')}\_thumb.png"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;end  
end

> **···**
>
> On Nov 28, 2007, at 15:01 , Tom Reilly wrote:
> 
> > # Make Thumb Nails  
> > # This works fine to make thumbnails for my web site  
> > # lots of luck  
> > #Tom Reilly
> > 
> > require 'rmagick'  
> > include Magick
> > 
> > def rsz(hgt,wdt,msze)  
> > &nbsp;&nbsp;if hgt \> wdt  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;r = msze.to\_f / hgt.to\_f  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return [msze, (wdt.to\_f \* r).to\_i]  
> > &nbsp;&nbsp;else  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;r = msze.to\_f / wdt.to\_f  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return [(hgt.to\_f \* r).to\_i, msze]  
> > &nbsp;&nbsp;end  
> > end
> > 
> > tnDir = ".\\"  
> > jpgArray = Array.new  
> > dir = Dir.new(tnDir)  
> > dir.each do |d|  
> > &nbsp;&nbsp;jpgArray.push(d) if d =~ /jpg/  
> > end
> > 
> > pix = ImageList.new  
> > jpgArray.each {|x| pix.read(x) if x .downcase =~ /jpg/}
> > 
> > pix.each do |x|  
> > &nbsp;&nbsp;&nbsp;&nbsp;rows = x.rows  
> > &nbsp;&nbsp;columns = x.columns  
> > &nbsp;&nbsp;factor1 = 200  
> > &nbsp;&nbsp;factor2 = 450  
> > &nbsp;&nbsp;a = rsz(columns,rows,factor1)  
> > &nbsp;&nbsp;&nbsp;x.resize!(a[0],a[1])  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#img.resize!(cols,rows)  
> > # img2 = x.frame  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x.write(".\\stamp\\#{"t" + x.filename}")  
> > end

---

<div class="post-metadata">

**Author:** ![Thufir](https://avatars.discourse-cdn.com/v4/letter/t/ee7513/32.png) [@Thufir](https://rubytalk.org/u/Thufir)\
**Post date:** [29 November 2007 02:30 UTC](https://rubytalk.org/t/im-trying-to-make-thumbnail-pics-any-suggestions/42580/7 "2007-11-29T02:30:27Z")

</div>

Very cool 🙂

I'm ok with the ruby, but how would you put that \*into\* a rails project  
so that the above code is run when the new images are imported to the db?

thanks,

Thufir

> **···**
>
> On Thu, 29 Nov 2007 09:29:25 +0900, Ryan Davis wrote:
> 
> > require 'rubygems'  
> > require 'image\_science'
> > 
> > Dir["\*.jpg"].each do |file|  
> > &nbsp;&nbsp;&nbsp;ImageScience.with\_image(file) do |img|  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;img.thumbnail(200) do |thumb|  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;thumb.save "#{file.sub(/.jpg$/, '')}\_thumb.png"  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
> > &nbsp;&nbsp;&nbsp;end  
> > end

---

<div class="post-metadata">

**Author:** ![Andrew\_Stewart](https://avatars.discourse-cdn.com/v4/letter/a/9de053/32.png) [@Andrew\_Stewart](https://rubytalk.org/u/Andrew_Stewart)\
**Post date:** [29 November 2007 09:59 UTC](https://rubytalk.org/t/im-trying-to-make-thumbnail-pics-any-suggestions/42580/8 "2007-11-29T09:59:33Z")

</div>

Have a look at the attachment\_fu plugin:

[http://svn.techno-weenie.net/projects/plugins/attachment\_fu/](http://svn.techno-weenie.net/projects/plugins/attachment_fu/)

Regards,  
Andy Stewart

> **···**
>
> On 29 Nov 2007, at 02:30, Thufir wrote:
> 
> > On Thu, 29 Nov 2007 09:29:25 +0900, Ryan Davis wrote:
> > 
> > > require 'rubygems'  
> > > require 'image\_science'
> > > 
> > > Dir["\*.jpg"].each do |file|  
> > > &nbsp;&nbsp;&nbsp;ImageScience.with\_image(file) do |img|  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;img.thumbnail(200) do |thumb|  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;thumb.save "#{file.sub(/.jpg$/, '')}\_thumb.png"  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
> > > &nbsp;&nbsp;&nbsp;end  
> > > end
> > 
> > Very cool 🙂
> > 
> > I'm ok with the ruby, but how would you put that \*into\* a rails project  
> > so that the above code is run when the new images are imported to the db?
> 
> -------
> 
> > **[AirBlade Software](https://airbladesoftware.com/)**
> >
> > Andrew Stewart of AirBlade Software.

---

<div class="post-metadata">

**Author:** ![James\_Britt](https://avatars.discourse-cdn.com/v4/letter/j/22d042/32.png) [@James\_Britt](https://rubytalk.org/u/James_Britt)\
**Post date:** [29 November 2007 12:00 UTC](https://rubytalk.org/t/im-trying-to-make-thumbnail-pics-any-suggestions/42580/9 "2007-11-29T12:00:35Z")

</div>

Put things like that into the Model file.

> **···**
>
> On Nov 28, 2007, at 8:30 PM, Thufir wrote:
> 
> > Very cool 🙂
> > 
> > I'm ok with the ruby, but how would you put that \*into\* a rails project  
> > so that the above code is run when the new images are imported to the db?
> > 
> > thanks,
> > 
> > Thufir

---

<div class="post-metadata">

**Author:** ![Piyush\_Ranjan](https://avatars.discourse-cdn.com/v4/letter/p/a587f6/32.png) [@Piyush\_Ranjan](https://rubytalk.org/u/Piyush_Ranjan)\
**Post date:** [30 November 2007 07:50 UTC](https://rubytalk.org/t/im-trying-to-make-thumbnail-pics-any-suggestions/42580/10 "2007-11-30T07:50:22Z")

</div>

you can also use filecolumn for rails file upload and thumbnailing needs.

> **···**
>
> On Nov 29, 2007 5:30 PM, John Joyce \<dangerwillrobinsondanger@gmail.com\> wrote:
> 
> > On Nov 28, 2007, at 8:30 PM, Thufir wrote:  
> > \>  
> > \> Very cool 🙂  
> > \>  
> > \>  
> > \> I'm ok with the ruby, but how would you put that \*into\* a rails  
> > \> project  
> > \> so that the above code is run when the new images are imported to  
> > \> the db?  
> > \>  
> > \>  
> > \>  
> > \> thanks,  
> > \>  
> > \> Thufir  
> > \>  
> > \>
> > 
> > Put things like that into the Model file.
