簡體   English   中英

ActiveStorage 不會裁剪變體

[英]ActiveStorage wont crop variants

我正在將我的 rails 應用程序從回形針遷移到 ActiveStorage,它只是不接受變體中的crop參數

這一行:

@user.image.variant(crop: [180,135])

導致此錯誤:

Errno::ENOENT (No such file or directory @ rb_sysopen - /var/folders/dd/dy3xgqrs2vv6h97ckrtmrb4m0000gn/T/mini_magick20180526-14598-njz21n.jpg):

activestorage (5.2.0) app/models/active_storage/variant.rb:130:in `initialize'
activestorage (5.2.0) app/models/active_storage/variant.rb:130:in `open'
activestorage (5.2.0) app/models/active_storage/variant.rb:130:in `upload'
activestorage (5.2.0) app/models/active_storage/variant.rb:88:in `block in process'
activestorage (5.2.0) app/models/active_storage/variant.rb:110:in `open_image'
activestorage (5.2.0) app/models/active_storage/variant.rb:85:in `process'
activestorage (5.2.0) app/models/active_storage/variant.rb:53:in `processed'
activestorage (5.2.0) app/controllers/active_storage/representations_controller.rb:12:in `show'

而例如。 這有效:

@user.image.variant(resize: '180x135')

resize_to_fitImageProcessing轉換。 Rails 5.2 不使用 ImageProcessing; 它直接使用MiniMagick代替。 Rails 6 將使用 ImageProcessing。

要調整大小以適應 Rails 5.2,請將>附加到resize參數:

@user.image.variant(resize: '180x135>')

要裁剪,請使用combine_options以便 MiniMagick 在單個 ImageMagick 調用中將gravitycrop參數一起傳遞:

@user.image.variant(combine_options: { gravity: 'Center', crop: '180x135+0+0' })

對於 Rails 6.0 用戶:

object.image.variant(resize_to_fill: [180, 135, { gravity: 'North' }])

我是為那些像我一樣不知道如何在變體中使用選項的人寫這篇文章的。

暫無
暫無

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

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