我有一个带有has_one_attached :file的模型,我想用一个定制的crop参数来处理这个模型。附带的文件是我用来测试的jpg格式的照片。
在此之前,我用这种方式缩放和裁剪图像,这是按预期工作的。
my_model.file.variant(resize_to_fill: [1440, 560, { gravity: 'Center' }])现在,我希望将图像裁剪的中心/焦点更改为自定义位置。普通的imagemagick命令将是convert input.jpg -crop 1440x560+580+120 output.jpg,按照命令行的要求工作。
docs声明您可以将几乎任何imagemagick逗号传递给.variant(),这导致我尝试如下:
my_model.file.variant(crop: '1440x560+580+120')这将引发以下错误:
ImageProcessing::Error - Source format is multi-layer, but destination format is
single-layer. If you care only about the first layer, add `.loader(page: 0)` to
your pipeline. If you want to process each layer,
see https://github.com/janko/image_processing/wiki/Splitting-a-PDF-into-multiple-images
or use `.saver(allow_splitting: true)`.我阅读了image_processing的手册并了解了管道的工作原理,但我忽略了如何通过.variant()来调整管道以获得结果的部分。
我是不是做错了什么,还是我只是错过了一些简单的部分?否则,我会用image_processing管道原始地编写它,然后绕过它。
我的环境包括:
v6.0.2.2
发布于 2020-04-02 13:30:20
试试my_model.file.variant(combine_options: { crop: '1440x560+580+120')
https://stackoverflow.com/questions/60989655
复制相似问题