I'm using Paperclip and Rails. Currently, if a user uploads a portrait image, Paperclip crops off the top and bottom of the image, and "forces" the middle section to fit my defined styles (provided below).
我用的是回形针和轨道。目前,如果用户上传了一幅肖像照,Paperclip就会从图片的顶部和底部出现,并且“强制”中间部分符合我定义的样式(如下所示)。
What I want, however, is the portrait image to be preserved, and add "spacing" to the left and right of the image. Basically, preserving the portrait image inside of a new landscape image. So far I can only find examples of simply rotating images. See examples below:
然而,我想要的是要保留的人像,并在图像的左右添加“间距”。基本上,在新的风景图像中保存肖像图像。到目前为止,我只能找到简单旋转图像的例子。请参见下面的例子:
Here's my styles info:
这是我的风格信息:
has_attached_file :image,
:styles => { thumb: "100x100#",
medium: "300x300>",
display: "759x506#" }
I currently don't have any pre/post processors or interpolations applied.
我目前没有应用任何前/后处理器或插值。
1 个解决方案
#1
3
According to the ImageMagick docs you can acheive this with the -extent
option, for example:
根据ImageMagick文档,你可以使用-区段选项来实现这个功能,例如:
convert input.jpg -resize 800x600 -background black -compose Copy \
-gravity center -extent 800x600 -quality 92 output.
According to the Paperclip docs, you could now add the relevant command line flags to paperclip the following way. For example, for :medium
:
根据Paperclip文档,您现在可以通过以下方式向Paperclip添加相关的命令行标志。例如,对于媒介:
has_attached_file :image, :styles => { thumb: "100x100#",
medium: "300x300>",
display: "759x506#" },
:convert_options => { all: "-background black -compose Copy -gravity center"
medium: "-extent 300x300"}
#1
3
According to the ImageMagick docs you can acheive this with the -extent
option, for example:
根据ImageMagick文档,你可以使用-区段选项来实现这个功能,例如:
convert input.jpg -resize 800x600 -background black -compose Copy \
-gravity center -extent 800x600 -quality 92 output.
According to the Paperclip docs, you could now add the relevant command line flags to paperclip the following way. For example, for :medium
:
根据Paperclip文档,您现在可以通过以下方式向Paperclip添加相关的命令行标志。例如,对于媒介:
has_attached_file :image, :styles => { thumb: "100x100#",
medium: "300x300>",
display: "759x506#" },
:convert_options => { all: "-background black -compose Copy -gravity center"
medium: "-extent 300x300"}