# Reading Images via RMagick until Ruby killed

**URL:** <https://www.ruby-forum.com/t/reading-images-via-rmagick-until-ruby-killed/127570>\
**Category:** Ruby\
**Created:** [January 30, 2008, 1:26pm UTC](https://www.ruby-forum.com/t/reading-images-via-rmagick-until-ruby-killed/127570 "2008-01-30T13:26:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![der\_guido](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@der\_guido](https://www.ruby-forum.com/u/der_guido)\
**Post date:** [January 30, 2008, 1:26pm UTC](https://www.ruby-forum.com/t/reading-images-via-rmagick-until-ruby-killed/127570/1 "2008-01-30T13:26:59Z")

</div>

Hey mates,

IÂ´m a newbie to Ruby and Rails. But IÂ´m a programer since few years. So  
my problem is, that I will try to read a lot of photos with RMagick.

require ‘rubygems’ # if installed via Gems  
require ‘RMagick’  
include Magick

exit 1 if ARGV.length != 1

files = Dir.new(ARGV[0])

exit 1 unless files

files.each do |file|  
next unless file =~ %r{.jpg$}i

puts ARGV[0]+file  
img = Image.read(ARGV[0]+file).first  
img\_orient = img.auto\_orient # turn a copy  
img\_gallery = img\_orient.resize\_to\_fit(1024,1024) # scales a copy down  
end

DonÂ´t be scared about my code… 😉

Ok… normaly I think, I can read every image - given from the directoy  
in ARGV[0]. In C or C++ I know, that in every cicle of the loop img,  
img\_orient, img\_gallery will be overwritten. But after 12-15 image  
(appr. 2.5 MB =\> 30-40 MB ) the memory-allocation is incredible high…  
so why?!?

I hope, that anyone can help me.

thanks!

---

<div class="post-metadata">

**Author:** ![der\_guido](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@der\_guido](https://www.ruby-forum.com/u/der_guido)\
**Post date:** [January 30, 2008, 2:04pm UTC](https://www.ruby-forum.com/t/reading-images-via-rmagick-until-ruby-killed/127570/2 "2008-01-30T14:04:53Z")

</div>

Guido Holz wrote:

> img\_gallery = img\_orient.resize\_to\_fit(1024,1024) # scales a copy down  
> I hope, that anyone can help me.
> 
> thanks!

[http://rubyforge.org/forum/forum.php?thread\_id=1374&forum\_id=1618](http://rubyforge.org/forum/forum.php?thread_id=1374&forum_id=1618)

Also, if you’re using RMagick 2:  
[http://rmagick.rubyforge.org/rmagick2.html](http://rmagick.rubyforge.org/rmagick2.html).

---

<div class="post-metadata">

**Author:** ![der\_guido](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@der\_guido](https://www.ruby-forum.com/u/der_guido)\
**Post date:** [January 30, 2008, 3:01pm UTC](https://www.ruby-forum.com/t/reading-images-via-rmagick-until-ruby-killed/127570/3 "2008-01-30T15:01:09Z")

</div>

Thanks! that was the reason 🙂

cheers guido

Tim H. wrote:

> Guido Holz wrote:
> 
> > img\_gallery = img\_orient.resize\_to\_fit(1024,1024) # scales a copy down  
> > I hope, that anyone can help me.
> > 
> > thanks!
> 
> [http://rubyforge.org/forum/forum.php?thread\_id=1374&forum\_id=1618](http://rubyforge.org/forum/forum.php?thread_id=1374&forum_id=1618)
> 
> Also, if you’re using RMagick 2:  
> [http://rmagick.rubyforge.org/rmagick2.html](http://rmagick.rubyforge.org/rmagick2.html).
