[英]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_fit
是ImageProcessing轉換。 Rails 5.2 不使用 ImageProcessing; 它直接使用MiniMagick代替。 Rails 6 將使用 ImageProcessing。
要調整大小以適應 Rails 5.2,請將>
附加到resize
參數:
@user.image.variant(resize: '180x135>')
要裁剪,請使用combine_options
以便 MiniMagick 在單個 ImageMagick 調用中將gravity
和crop
參數一起傳遞:
@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.