首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >图像调整服务[Rails 5]

图像调整服务[Rails 5]
EN

Stack Overflow用户
提问于 2017-12-10 13:16:06
回答 1查看 350关注 0票数 0

我正在构建一个关于上传图像和调整大小的项目,目前我们正在使用gem FastImage,这是获取图像url的最佳选择。但我找不到任何Resizing Gem

我想要什么!

  • 获取图像的大小
  • 获得宽度
  • 获得高度
  • 调整该图像的大小(如果我可以缩放该图像,就会非常完美,不需要裁剪)。
EN

回答 1

Stack Overflow用户

发布于 2017-12-10 14:54:55

我建议你看看载波宝石。它提供您想要的一切,包括调整大小的部分。

您可以通过远程url上传图像如下:

代码语言:javascript
复制
<%= form_for @user, html: { multipart: true } do |f| %>
  <p>
    <label>My Avatar URL:</label>
    <%= image_tag(@user.avatar_url) if @user.avatar? %>
    <%= f.text_field :remote_avatar_url %>
  </p>
<% end %>

或者把它调整成:

代码语言:javascript
复制
class ImageUploader < CarrierWave::Uploader::Base

  version :resized do
    # returns an image with a maximum width of 100px 
    # while maintaining the aspect ratio
    # 10000 is used to tell CW that the height is free 
    # and so that it will hit the 100 px width first
    process :resize_to_fit => [100, 10000]
  end

end
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47739230

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档