回形针锐化处理器导致调整大小样式不起作用 [英] Paperclip sharpening processor causes resizing styles not to work

查看:46
本文介绍了回形针锐化处理器导致调整大小样式不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试锐化通过回形针上传的图像.锐化代码正在工作,但它导致样式不起作用.代码是这样的:

I'm trying to sharpen images uploaded through paperclip. The sharpen code is working but it causes the styles to not work. The code is like this:

 has_attached_file :photo,
    :styles => {
                :thumb => {:geometry => "100x100>"},
                :medium => {:geometry => "300x300>"},
                :original => {:geometry => "1024x1024>"}
                },
    :processors => [:sharpen],
    :storage => :s3,
    :s3_credentials => "#{Rails.root}/config/s3.yml",
    :path => "/:style/:id/:filename"

现在,如果我删除处理器选项,上传的图像将按指定大小调整.但是,如果我包含处理器选项,则所有生成的图像都是原始大小.

Now if I remove the processors option, the uploaded images are resized as specified. However if I include the processors option, all the resulting images are of original size.

我的锐化处理器如下所示:

My sharpen processor looks like this:

module Paperclip
  class Sharpen < Paperclip::Processor
    def initialize file, options = {}, attachment = nil
      super
      @file = file
      @current_format = File.extname(@file.path)
      @basename = File.basename(@file.path, @current_format)
    end

    def make
      dst = Tempfile.new(@basename)
      dst.binmode

      command = "#{File.expand_path(@file.path)} -unsharp 1.5×1.0+1.5+0.02 #{File.expand_path(dst.path)}"

      begin
        success = Paperclip.run("convert", command)
      rescue PaperclipCommandLineError
        raise PaperclipError, "There was an error converting sharpening the image for #{@basename}"
      end

      dst
    end
  end
end

有什么想法吗?

推荐答案

尝试将 :thumbnail 添加到处理器列表:

Try adding :thumbnail to processors list:

:processors => [:thumbnail, :sharpen]

默认情况下 :thumbnail 存在,但现在您要覆盖该设置.

By default :thumbnail is there but now you are overriding that setting.

"可以指定多个处理器,它们将按照它们在 :processors 数组中定义的顺序被调用.每个连续的处理器将被赋予前一个处理器的执行结果.所有处理器将收到相同的参数,即是您在 :styles 哈希中定义的内容."

"Multiple processors can be specified, and they will be invoked in the order they are defined in the :processors array. Each successive processor will be given the result of the previous processor's execution. All processors will receive the same parameters, which are what you define in the :styles hash."

这篇关于回形针锐化处理器导致调整大小样式不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆