質問

xxxの画像処理プロセッサ、およびIは、モデル内の2つのスタイルがあります:

私が持っている大きくて:親指

私はどのように処理することができます:XXXのみ:残して親指の画像:?そのまま大きな画像を

役に立ちましたか?

解決

デフォルトでは、rakeタスクは、すべてのサムネイルを更新します。それは/プロセスに、元の画像には手を触れないことに注意してください。

あなたはRakefileするでを見ている可能性があり、 アタッチメントのクラスとあなたが指定できるように修正特定のサムネイルのサイズが、現在の設計では、元を取ると、元からすべてのサムネイルをやり直したいことを前提としています。

他のヒント

私は最近、同様の問題があったとのメッセージボードにこの解決策を見つけました。それが役に立てば幸い!

has_attached_file :screenshot,
 :default_style => :full,
 :styles => {
   :full => "280x210",
   :cropped => { :processors => [:screenshot_crop] }
 }

あなたのpaperclip.rakeファイルにこのコードを追加します:

   desc "Reprocesses your attachments style (set CLASS, ATTACHMENT and STYLE)"
    task :style => :environment do
      module JustForOneDay
        NAME = ENV['STYLE']
      end

      module ::Paperclip
        class Attachment
          def post_process_styles #:nodoc:
            @styles.each do |name, args|
              if JustForOneDay::NAME == name
                begin
                  raise RuntimeError.new("Style #{name} has no processors defined.") if args[:processors].blank?
                  @queued_for_write[name] = args[:processors].inject(@queued_for_write[:original]) do |file, processor|
                    Paperclip.processor(processor).make(file, args, self)
                  end
                rescue PaperclipError => e
                  log("An error was received while processing: #{e.inspect}")
                  (@errors[:processing] ||= []) << e.message if @whiny
                end
              end
            end
          end
        end
      end

      for_all_attachments do |instance, name|
        result = instance.send(name).reprocess!
      end
    end
  end

ペーパークリップ2.3.1.1でテスト

ペーパークリップ2.3.3では、このする必要があります:

def post_process_styles #:nodoc:
  styles.each do |name, style|
    if JustForOneDay::NAME == name
    begin
      raise RuntimeError.new("Style #{name} has no processors defined.") if style.processors.blank?
      @queued_for_write[name] = style.processors.inject(@queued_for_write[:original]) do |file, processor|
        Paperclip.processor(processor).make(file, style.processor_options, self)
      end
    rescue PaperclipError => e
      log("An error was received while processing: #{e.inspect}")
      (@errors[:processing] ||= []) << e.message if @whiny
    end
    end
  end
end

それは簡単です、ちょうどあなたのクリップのバージョンでファイルをattachment.rbに行きます。

それはエレガントではないが、それは私のために働いていた。

-

私は、この適当に組みあわせました。

あなたのスタイルの一つは、他のすべてのスタイルは異なる寸法を有していなければなりません。コマンド文字列の内容が与えられた寸法が含まれている場合は、この方法では、カスタムペーパークリッププロセッサに、あなたが見ることができます。あなたがいない場合は、特別な処理を行うだろうもしそうなら、あなたはないでしょう。

(私はこのコードをクリッピング - 、それを修正 - ライアンベイトのRailscastエピソード182から)

module Paperclip
  class Cropper < Thumbnail
    def transformation_command
      SPECIAL_PROCESSING_FLAG = "150x150"
      if crop_command && super.include?(SPECIAL_PROCESSING_FLAG)
        crop_command + super.sub(/ -crop \S+/, '')
      else
        super 'do nothing fancy
      end
    end

    def crop_command
      target = @attachment.instance
      if target.cropping?
        " -crop '#{target.crop_w.to_i}x#{target.crop_h.to_i}+#{target.crop_x.to_i}+#{target.crop_y.to_i}'"
      end
    end
  end
end

は、私のような状況では、それが最終的な結果は何も変わっていないので、我々は、あまりにも非特殊なケースで再処理することを問題ではありませんでした。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top