2015-11-19 34 views
2

我到處看看我無法理解如何使用回形針更改原稿的質量。如何使用回形針更改上傳質量?

在每個線程大家展示瞭如何做,與例如生成的縮略圖:

has_attached_file :img, styles: { thumb: "400x400#" }, convert_options: { thumb: '-quality 60 -strip'} 

那偉大工程。不過,我想對原始上傳進行此後處理。我試過

has_attached_file :img, styles: { thumb: "400x400#" }, convert_options: { thumb: '-quality 60 -strip', original: '-quality -50 -strip'} 

但是這不起作用,我的原始照片仍然很大。

謝謝!

+0

下面的答案是否適合您? –

+0

不,它不:) 看到我下面的評論 – Statyx

回答

1

要更改以下照片上傳try代碼質量:

has_attached_file :img, 
       :styles   => { :thumb => '400x400#' }, 
       :convert_options => { :thumb => '-quality 80' } 

你可以做的另一件事是創建多次與尺寸的變化相同的圖像,所以再調用圖像的大小你要。請參閱以下步驟:

  1. 使用指定所需品質的名稱在app/assets/images中創建文件夾。例如,你可以有:app/assets/images/large,app/assets/images/medium,app/assets/images/thumb(你已經有這個)和許多其他的你想要的。
  2. 在對象的模型已經附着做到以下幾點:

    has_attached_file :photo, 
        styles: { original: "4000x4000>", large:"2000x2000>" ,medium: "800x800>" ,thumb: "400x400>" }, 
        default_url: ":style/missing.png" 
    
  3. 然後在您的視圖,你可以這樣做:

    <%= image_tag(yourObjectWithImgHere.img.url(:thumb) %> 
    <%= image_tag(yourObjectWithImgHere.img.url(:medium) %> 
    

你可以走得更遠轉換選項或通過閱讀this tutorial of thumbnail generation in the official wiki of paperclip調整圖像大小。 也this question可能是有用的。

+0

你好,謝謝你的答案,但是這是,我知道:D。我知道如何改變拇指或中型或大型版本的上傳質量,但我想降低原件的質量。我找不到這樣做的方法,我不想保留原始的全高清圖像。 – Statyx

+0

您是否看過我分享的[問題](http://stackoverflow.com/questions/4988527/how-can-i-reduce-the-quality-of-an-uploading-image-using-paperclip)以上? –

+0

是的,我讀了整個東西 – Statyx