Skip to navigation
How to resize each image in a directory with rails?
07.12.13
this is example function to resize all images in the directory products_thumbs ############################################### # Image Resizer ############################################## def image_resizer require 'RMagick' files = Dir.entries("#{ RAILS_ROOT}/public/images/products_thumbs") files.delete(".") files.delete("..") files.delete(".svn") for i in 0..(files.length-1) do mona = Magick::Image.read("#{ RAILS_ROOT}/public/images/products_thumbs/#{files[i]}").first mona.change_geometry!('120x200') { |cols, rows, img| img.resize!(cols, rows) mona.write "#{ RAILS_ROOT}/public/images/products_thumbs/#{files[i]}" } end flash[:notice] = 'Images Successfully updated.' redirect_to :action => 'index' end
Reply
Anonymous
How to resize each image in a directory with rails?
this is example function to resize all images in the directory products_thumbs ############################################### # Image Resizer ############################################## def image_resizer require 'RMagick' files = Dir.entries("#{ RAILS_ROOT}/public/images/products_thumbs") files.delete(".") files.delete("..") files.delete(".svn") for i in 0..(files.length-1) do mona = Magick::Image.read("#{ RAILS_ROOT}/public/images/products_thumbs/#{files[i]}").first mona.change_geometry!('120x200') { |cols, rows, img| img.resize!(cols, rows) mona.write "#{ RAILS_ROOT}/public/images/products_thumbs/#{files[i]}" } end flash[:notice] = 'Images Successfully updated.' redirect_to :action => 'index' end
07.12.13
Reply
Anonymous
Information Epoch 1732394431
When in doubt, use brute force.
Home
Notebook
Contact us