Paperclip sharpening processor causes resizing styles not to work

只谈情不闲聊 提交于 2019-12-11 10:36:12

问题


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

Any thoughts?


回答1:


Try adding :thumbnail to processors list:

:processors => [:thumbnail, :sharpen]

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

"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."

  • https://github.com/thoughtbot/paperclip


来源:https://stackoverflow.com/questions/4801905/paperclip-sharpening-processor-causes-resizing-styles-not-to-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!