Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 回形针不替换裁剪的图像。在s3_Ruby On Rails 3_Ruby On Rails 4_Amazon S3_Paperclip_Jcrop - Fatal编程技术网

Ruby on rails 3 回形针不替换裁剪的图像。在s3

Ruby on rails 3 回形针不替换裁剪的图像。在s3,ruby-on-rails-3,ruby-on-rails-4,amazon-s3,paperclip,jcrop,Ruby On Rails 3,Ruby On Rails 4,Amazon S3,Paperclip,Jcrop,我用回形针上传图片。我的存储空间在S3。我使用Jcrop和回形针裁剪图像,并遵循#RailsCast182 一切都很顺利,我已经解决了铁路上的一些问题 我想处理裁剪文件并在s3上传它 这是我的日志,显示图像被裁剪 我的附件模型: class Attachment < ActiveRecord::Base has_attached_file :file, styles: { medium: "100x100>", thumb: "50x50#" }, :processor

我用回形针上传图片。我的存储空间在S3。我使用Jcrop和回形针裁剪图像,并遵循#RailsCast182

一切都很顺利,我已经解决了铁路上的一些问题

我想处理裁剪文件并在s3上传它

这是我的日志,显示图像被裁剪



我的附件模型:

class Attachment < ActiveRecord::Base 
    has_attached_file :file, styles: { medium: "100x100>", thumb: "50x50#" }, :processors => [:cropper]

    attr_accessor :crop_x, :crop_y, :crop_w, :crop_h

  def cropping?
    !crop_x.blank? && !crop_y.blank? && !crop_w.blank? && !crop_h.blank?
  end
end

#paperclip custom cropper

module Paperclip
  class Cropper < Thumbnail
    def transformation_command
      if crop_command
        crop_command + super.join(' ').sub(/ -crop \S+/, '').split(' ')
      else
        super
      end
    end

    def crop_command
      target = @attachment.instance
      if target.cropping?
        ["-crop", "#{target.crop_w}x#{target.crop_h}+#{target.crop_x}+#{target.crop_y}"]
      end
    end
  end
end
类附件”,thumb:“50x50”},:processors=>[:crapper]
属性访问器:裁剪x、:裁剪y、:裁剪w、:裁剪h
def裁剪?
!作物×空白?&&!裁剪y.blank?&&!作物w.blank?&!作物h.blank?
结束
结束
#回形针定制裁剪器
模块回形针
类裁剪器<缩略图
def转换命令
如果是命令
crop_命令+super.join(“”).sub(/-crop\S+/,“”).split(“”)
其他的
超级的
结束
结束
def crop_命令
target=@attachment.instance
如果目标是裁剪?
[“-crop”、“#{target.cropw}x#{target.crop_h}+#{target.crop_x}+#{target.crop_y}”]
结束
结束
结束
结束
但是回形针永远不会改变S3的图像

我经历了许多环节,但没有触及天空

期待来自伟大社区的帮助

问候
Adam

您需要更改库中的crapper.rb。裁剪器工作正常,但仅拍摄图像中心。如果您更改您的craper.rb,您的图像可以很好地保存

module Paperclip  
  class Cropper < Thumbnail  
    def transformation_command  
      if crop_command
        original_command = super
        if original_command.include?('-crop')
          original_command.delete_at(super.index('-crop') + 1)
          original_command.delete_at(super.index('-crop'))
        end
        crop_command + original_command
      else  
        super  
      end  
    end  

    def crop_command  
      target = @attachment.instance  
      if target.cropping?
        ["-crop", "#{target.crop_w}x#{target.crop_h}+#{target.crop_x}+#{target.crop_y}"]
      end  
    end  
  end  
end
如果s3将所有文件保存为一种大小,则需要将此代码更改为

has_attached_file :avatar, :styles => {
      :thumb => {:geometry => "90x50#", :processors => [:cropper, :thumbnail]},
注意!更改此文件后,需要重新启动服务器

def avatar_geometry(style = :original)
    @geometry ||= {}
    avatar_path = (avatar.options[:storage] == :s3) ? avatar.url(style) : avatar.path(style)
    @geometry[style] ||= Paperclip::Geometry.from_file(avatar_path)
  end
has_attached_file :avatar, :styles => {
      :thumb => {:geometry => "90x50#", :processors => [:cropper, :thumbnail]},