切圈出与RMagick
问题描述:
形象我想砍了一圈出来使用rmagick图像。切圈出与RMagick
这里是想我能够做到的例子:
好像我想用http://studio.imagemagick.org/RMagick/doc/draw.html#circle削减了一圈,然后clip_path掩盖它,但文件不是很清楚。任何人都可以指出我正确的方向吗?
答
require 'rmagick'
im = Magick::Image.read('walter.jpg').first
circle = Magick::Image.new 200, 200
gc = Magick::Draw.new
gc.fill 'black'
gc.circle 100, 100, 100, 1
gc.draw circle
mask = circle.blur_image(0,1).negate
mask.matte = false
im.matte = true
im.composite!(mask, Magick::CenterGravity, Magick::CopyOpacityCompositeOp)
im.write 'walter_circle.png'
答
这是我如何与ImageMagick的和PHP做到这一点:
// Canvas the same size as the final image
exec("convert -size 800x533 xc:white white.jpg");
// The mask
exec("convert -size 800x533 xc:none -draw \"fill black circle 400,265 400,50\" write_mask.png");
// Cut the whole out of the canvas
exec("composite -compose Dst_Out write_mask.png white.jpg -matte step.png");
// Put the canvas over the image and trim off excess white background
exec("convert IMG_5745.jpg step.png -composite -trim final.jpg");
你应该能够遵循的流程?
清理tempory图像之后 - 我倾向于保存tempory图像在.miff格式,然后写一个循环来后删除所有.miff图像。 Alternativly刚刚离开他们,如果你使用相同的名称为tempory图像他们会在每次代码运行时被覆盖。
+0
您能给一个Rmagic参考吗? – Almaron
你会如何做到这两个图像?相反的圆的,具有透明图像 –
此解决方案不与alpha通道PNG图像工作 – Dmitry