# Can't read image

**URL:** <https://www.ruby-forum.com/t/cant-read-image/117515>\
**Category:** Rails\
**Created:** [October 17, 2007, 5:26pm UTC](https://www.ruby-forum.com/t/cant-read-image/117515 "2007-10-17T17:26:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shafi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@shafi](https://www.ruby-forum.com/u/shafi)\
**Post date:** [October 17, 2007, 5:26pm UTC](https://www.ruby-forum.com/t/cant-read-image/117515/1 "2007-10-17T17:26:46Z")

</div>

hi all,

i wanna generate thumbnail from image

i found RMagick and found this code but i can’t run it, so please anyone  
help me in this issue.

my code

def index  
img = Magick::Image.read (’/images/img2.jpg’).first  
width, height = 100, 100  
thumb = img.resize(width, height)  
thumb.write(’/images/mythumbnail.jpg’)  
end

but it throws this exception

unable to open image `/images/img2.jpg’: No such file or directory

thanks

---

<div class="post-metadata">

**Author:** ![shafi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@shafi](https://www.ruby-forum.com/u/shafi)\
**Post date:** [October 17, 2007, 7:40pm UTC](https://www.ruby-forum.com/t/cant-read-image/117515/2 "2007-10-17T19:40:52Z")

</div>

On Oct 17, 2007, at 11:26 AM, Mohamed S. wrote:

> def index
> 
> ## thanks
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

You probably need to File.expand\_path(‘public’ + ‘/images/img2.jpg’,  
RAILS\_ROOT)

to get a real file name on your system. I presume that the ‘/images/  
img2.jpg’ will be replaced with some variable that is meant to be an  
absolute “web” path, but you need a “file system” path.

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid
