图像在Rails上的ruby中调整大小 [英] Image resize in ruby on rails
本文介绍了图像在Rails上的ruby中调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
像这样,我目前正在我的ruby应用程序中上传文件(图像)..我需要在上传后调整图像大小...请帮助调整图像大小
Like this I am currently uploading a file ( image ) in my ruby application .. I need to resize the image after uploading ... please help for resizing the image
uploaded_io = params [:category] [:thumb]
uploaded_io = params[:category][:thumb]
if uploaded_io != ""
name = uploaded_io.original_filename
if(FileTest.exist?("#{RAILS_ROOT}/public/data/#{name}"))
id = Category.maximum('id').to_s
id = id.to_i+ 1
name =id.to_s+"_"+name
end
谢谢
推荐答案
如果您已经安装了imagemagick-则使用ImageScience或MiniMagick代替,它们使用的资源都少得多,工作速度也更快,并且就像普通的gem一样安装(其实对图像科学的安装要多一些
If you have imagemagick already installed - then use ImageScience or MiniMagick instead, they both use much less resources and work faster, and are installed just as a common gem (actually a little bit more installation for imagescience)
ImageScience:
ImageScience:
ImageScience.with_image("#{RAILS_ROOT}/public/data/#{name}") do |image|
image.thumbnail(100) do |thumb|
thumb.save <path_to_small_image to be saved>
end
end
MiniMagick:
MiniMagick:
MiniMagick::Image.new("#{RAILS_ROOT}/public/data/#{name}").resize "100x100"
这篇关于图像在Rails上的ruby中调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文