【问题标题】:Rails and Paperclip, use a different image, not an uploaded one to be processedRails 和 Paperclip,使用不同的图像,而不是上传的要处理的图像
【发布时间】:2011-01-03 12:00:32
【问题描述】:

我想知道有没有一种方法可以为要由回形针处理的图像指定不同的图像?

所以不是用户上传图片,而是使用图片网址,或者您认为可以指向服务器上现有的不同图片?

干杯。

编辑: 为了清楚起见,我正在寻找的是,当图像被上传、处理、移动到文件夹并附加到文件夹时。该基础图片不是通过表单上传的,而是从 URL 中获取的,然后对其进行处理、移动等

【问题讨论】:

    标签: ruby-on-rails image-processing components ruby-on-rails-3 paperclip


    【解决方案1】:

    这是一种使用 RemoteFile 代替上传文件的方法...查看博客文章了解如何创建 RemoteFile,它是 TempFile 的子类

    #console
    remote_file = RemoteFile.new("http://www.google.com/intl/en_ALL/images/logo.gif")
    remote_file.original_filename #=> logo.gif
    remote_file.content_type #= image/gif
    
    #controller
    def import
      #...snip
      @imported_user.images.create(:file => RemoteFile.new( url_to_image ))
      #...snip
    end
    

    http://coryodaniel.com/index.php/2010/03/05/attaching-local-or-remote-files-to-paperclip-and-milton-models-in-rails-mocking-content_type-and-original_filename-in-a-tempfile/

    【讨论】:

      【解决方案2】:

      我不确定您是否要求用户提供此图像,但如果他们不提供默认图像,则可以使用一种方法。这是使用 default_url 和默认样式选项完成的,如下所示:

      has_attached_image :my_image
                         :default_url => "/path/to/default_image.jpg",
                         :default_style => :thumb
      

      【讨论】:

      • 不抱歉,我正在寻找其他内容,我将编辑问题以使其更清晰。
      猜你喜欢
      • 2018-06-26
      • 2015-03-10
      • 2016-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-16
      • 2011-01-14
      相关资源
      最近更新 更多