can't read image

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

Image.read() is relative not to your web root, but to your host
operating system's root.

Try something like:

def index
  fname = RAILS_ROOT + '/images/img2.jpg'
  img = Magick::Image.read(fname)
  img = img.first
  ...
end