Crazy Easy Intro to RMagick – Ruby on Rails Image Manipulation

ruby image manipulationSo, you’ve go ruby on rails up and running, and now you’ve installed Rmagick, and you want to manipulate some images. Grab an image, throw it in your public folder, lets call it myimage.jpg. Run script/server to start your server, and in a controller somewhere put this:

def show

image  = Magick::ImageList.new(”public/images/myimage.jpg”)
image   = image.rotate(90)
image.write(”public/images/myimage.jpg”)

end

then in your show.html.erb you can show your picture:


< img src = "/images/myimage.jpg" />

Every time you load the page you should see your image rotated by 90 degrees. This tutorial actually took me longer to write out then to complete, even so I hope this maybe helps someone else getting started out with this powerful program.

READ  Loops in Java

Leave a Reply

Your email address will not be published. Required fields are marked *