云函数 Circle Image Imagemagick

Cloud functions Circle Image Imagemagick

我想使用云功能将上传到 Firebase 存储的图片转换为带圆圈的图片并调整它们的大小。 查看 ImageMagick 的文档后,我想知道用于此任务的语法。使用下面的方法调整图像大小,效果很好。但是我如何将命令添加到其中以及哪些命令最好使用?

return spawn('convert', [tmpFilePath, '-resize', '250x250', tmpFilePath]);

我不知道 'circle image' 是什么意思,但也许应用了 Vignette 效果?

convert -size 250x250 plasma: -background white -vignette 0x0 output.png

所以你的命令可能是...

return spawn('convert', [
    tmpFilePath,
    '-resize', '250x250',
    '-background', 'white',
    '-vignette', '0x0',
    tmpFilePath
]);

emcconville可能是最简单的方法。您可能只需要使背景透明并将等离子图像替换为真实图像。

如果您希望外部透明,请务必将输出保存为 PNG 或 TIFF 而不是 JPG。 JPG 不支持透明度。

输入:

convert lena.jpg -background none -vignette 0x0 output.png


但是,圆的周长不会延伸到图像的边缘。

要做到这一点,您必须按如下方式更改参数:

convert lena.jpg -background none -vignette 0x0+0+0 output2.png

但这里有另一种方法,它更长更复杂(假设您有方形图像)。

如果 "circled images" 你的意思是让圆圈的外面变成图像大小的透明,你可以在 ImageMagick 命令行中这样做:

1) Read the image (and somehow get its size)
2) Then create a new image the same size and fill with black and draw a white circle supplying the center point and any point on the perimeter
3) Put the circle image into the alpha channel of the original


原文:

Unix 语法。 (对于Windows去掉下面的\s)

convert lena.jpg \( -size 256x256 xc:black -fill white -draw "circle 128,128 128,255" \) -alpha off -compose copy_opacity -composite result.png


在Unix语法中可以得到输入图像的尺寸如下:

WxH=`convert -ping lena.jpg -format "%wx%h" info:`
ww=`echo $WxH | cut -dx -f1`
hh=`echo $WxH | cut -dx -f2`
ww2=`convert xc: -format "%[fx:$ww/2]" info:`
hh2=`convert xc: -format "%[fx:$hh/2]" info:`
hhm1=$((hh-1))
convert lena.jpg \( -size ${ww}x${hh} xc:black -fill white -draw "circle $ww2,$hh2 $ww2,$hhm1" \) -alpha off -compose copy_opacity -composite result2.png


如果你没有方形图片,那么你必须使用输入图片的最小尺寸作为圆的直径。这也适用于方形图像。

输入:

dim=`convert -ping monet2.jpg -format "%[fx:min(w,h)]" info:`
dim2=`convert xc: -format "%[fx:$dim/2]" info:`
dimm1=$((dim-1))
convert monet2.jpg \( -size ${dim}x${dim} xc:black -fill white -draw "circle $dim2,$dim2 $dim2,$dimm1" \) -alpha off -gravity center -compose copy_opacity -composite result4.png


如果我们在非正方形图像上使用晕影方法,那么您将得到一个椭圆区域。

convert monet2.jpg -background none -vignette 0x0+0+0 output3.png