在 ruby​​ on Rails 中调整图像大小

发布于 2024-12-21 06:47:41 字数 362 浏览 3 评论 0原文

像这样,我目前正在我的 ruby​​ 应用程序中上传一个文件(图像)..我需要在上传后调整图像大小...请帮助调整图像大小

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

谢谢

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]

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

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

醉城メ夜风 2024-12-28 06:47:41

如果您已经安装了 imagemagick - 那么请使用 ImageScience 或 MiniMagick,它们都使用更少的资源并且工作速度更快,并且安装就像一个常见的 gem(实际上 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::Image.new("#{RAILS_ROOT}/public/data/#{name}").resize "100x100"

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.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::Image.new("#{RAILS_ROOT}/public/data/#{name}").resize "100x100"
把人绕傻吧 2024-12-28 06:47:41

尝试 RMagick!

require 'RMagick'

img = Image.new name
thumb = img.scale(125, 125)
thumb.write "thumb.gif"

http://www.imagemagick.org/RMagick/doc/comtasks.html#thumb

Try RMagick!

require 'RMagick'

img = Image.new name
thumb = img.scale(125, 125)
thumb.write "thumb.gif"

http://www.imagemagick.org/RMagick/doc/comtasks.html#thumb

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文