简体   繁体   中英

Rails, Heroku, Paperclip, S3 and cropping

For my application I need a cropping functionality for images. I followed the railscast http://railscasts.com/episodes/182-cropping-images

Aaaall works fine on my local machine. I have my owm paperclip processor, which extends from the Thumbnail processor. This processor is stored under lib/paperclip_processors/cropper.rb

module Paperclip
  class Cropper < Thumbnail

    def transformation_command
      if crop_command
        cmd = crop_command + super.join(" ").sub(/ -crop \S+/, '')
        cmd.split(" ")
      else
        super
      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

On my local machine it uses this processor for cropping. On heroku it seems that this module is completely ignored.

Yes, I searched around 6 hours for the solution...

1.

#application.rb
config.autoload_paths += %w(#{config.root}/lib)     
#or 
config.autoload_paths += Dir["#{config.root}/lib/**/"]
#or
config.autoload_paths += Dir["#{config.root}/lib/paperclip_processors/cropper.rb"]

#all not working

2.

#initializers/includes.rb
require "cropper"

#or

Dir[Rails.root + 'lib/**/*.rb'].each do |file|
  require file
end

Why the hell is my module not loading??

You might want to check if the condition is getting invoked.

    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

I had a similar trouble a few days back with cropping on heroku.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM