gpt4 book ai didi

ruby-on-rails - ActiveStorage 不会裁剪变体

转载 作者:行者123 更新时间:2023-12-02 11:23:17 25 4
gpt4 key购买 nike

我正在将 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 通过 gravitycrop在单个 ImageMagick 调用中一起使用参数:
@user.image.variant(combine_options: { gravity: 'Center', crop: '180x135+0+0' })

关于ruby-on-rails - ActiveStorage 不会裁剪变体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50547257/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com