简体   繁体   English

Rails,Heroku,回形针,S3和裁切

[英]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 我遵循了railscast http://railscasts.com/episodes/182-cropping-images

Aaaall works fine on my local machine. Aaaall在我的本地计算机上运行良好。 I have my owm paperclip processor, which extends from the Thumbnail processor. 我有我的owm回形针处理器,该处理器是Thumbnail处理器的扩展。 This processor is stored under lib/paperclip_processors/cropper.rb 该处理器存储在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. 在heroku上,似乎完全忽略了此模块。

Yes, I searched around 6 hours for the solution... 是的,我搜索了大约6个小时的解决方案...

1. 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. 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. 几天前我在heroku上裁剪时遇到了类似的麻烦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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