簡體   English   中英

如何制作回形針而不縮放附件圖像?

[英]How to make Paperclip crop and NOT scale an attached image?

我希望回形針可以裁剪而不是縮放(請參見本摘錄中的:full1)

class Graphic < ActiveRecord::Base
  has_attached_file :image, :styles => { :full0 => "940x1000#" #want it to scale, and crop if neccessary
                                         :full1 => "940#", #want it to crop width, not scale
                                       }

我希望:full1可以工作,但事實並非如此。 “工作”是指它應裁剪圖像的寬度,但對圖像的高度不做任何事情。 原因是我正在上傳網絡屏幕截圖,並且希望將它們的寬度(從中心)調整為940像素,但高度應保持不變。 就我在回形針上的研究而言,我沒有找到如何做到這一點。

顯然,它受到ImageMagick的完全支持: http : //www.imagemagick.org/Usage/crop/#crop_strip但我不知道如何將其塞入導軌中的回形針中。

非常感謝!

您能將高度設置為一個大得令人難以置信的高度嗎?

class Graphic < ActiveRecord::Base
  has_attached_file :image, :styles => { :full0 => "940x1000#" #want it to scale, and crop if neccessary
                                         :full1 => "940x9999999#", #want it to crop width, not scale
                                       }

我認為這會裁切任何大於940px的內容。

您可以用戶轉換圖像處理選項,“跟隨”將集中裁剪圖像。

has_attached_file :profile_picture, :storage => :s3,                             
                                     :styles => { :medium => "", :thumb => ""},
                                      :convert_options => {
                                          :thumb => Proc.new { |instance| instance.thumnail_dimension },
                                          :medium => Proc.new { |instance| instance.thumnail_dimension(300) }
                                          }

def thumnail_dimension(size=100)
    dimensions = Paperclip::Geometry.from_file(profile_picture.queued_for_write[:original].path)
    min = dimensions.width > dimensions.height ? dimensions.height : dimensions.width
    "-gravity Center -crop #{min}x#{min}+0+0 +repage -resize #{size}x#{size}^"
  end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM