gpt4 book ai didi

ruby-on-rails - 使用 Paperclip/Rails 将纵向转换为横向,并将左右填充转换为新图像

转载 作者:数据小太阳 更新时间:2023-10-29 07:59:53 26 4
gpt4 key购买 nike

我正在使用 Paperclip 和 Rails。目前,如果用户上传肖像图像,Paperclip 会裁剪图像的顶部和底部,并“强制”中间部分适合我定义的样式(如下所示)。

然而,我想要的是要保留的肖像图像,并在图像的左侧和右侧添加“间距”。基本上,将肖像图像保留在新的风景图像中。到目前为止,我只能找到简单旋转图像的例子。请参阅以下示例:

enter image description here

enter image description here

enter image description here

这是我的样式信息:

has_attached_file :image,
:styles => { thumb: "100x100#",
medium: "300x300>",
display: "759x506#" }

我目前没有应用任何前/后处理器或插值。

最佳答案

根据 the ImageMagick docs您可以使用 -extent 选项实现此目的,例如:

convert input.jpg -resize 800x600 -background black -compose Copy \ 
-gravity center -extent 800x600 -quality 92 output.

According to the Paperclip docs ,您现在可以通过以下方式将相关的命令行标志添加到回形针。例如,对于 :medium:

has_attached_file :image, :styles => { thumb: "100x100#",
medium: "300x300>",
display: "759x506#" },
:convert_options => { all: "-background black -compose Copy -gravity center"
medium: "-extent 300x300"}

关于ruby-on-rails - 使用 Paperclip/Rails 将纵向转换为横向,并将左右填充转换为新图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23880726/

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