Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 用RMagick从图像中切出圆_Ruby_Image Processing_Imagemagick_Rmagick - Fatal编程技术网

Ruby 用RMagick从图像中切出圆

Ruby 用RMagick从图像中切出圆,ruby,image-processing,imagemagick,rmagick,Ruby,Image Processing,Imagemagick,Rmagick,我想用rmagick从图像中剪出一个圆 以下是我希望能够完成的一个示例: --> 似乎我想用它来切割一个圆,然后剪辑路径来掩盖它,但是文档不是很清楚。有人能给我指出正确的方向吗?这是我使用Imagemagick和php的方法: // Canvas the same size as the final image exec("convert -size 800x533 xc:white white.jpg"); // The mask exec("convert -size 800x533 x

我想用rmagick从图像中剪出一个圆

以下是我希望能够完成的一个示例:

-->


似乎我想用它来切割一个圆,然后剪辑路径来掩盖它,但是文档不是很清楚。有人能给我指出正确的方向吗?

这是我使用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");
你应该能够遵循这个过程吗


之后清理临时图像-我倾向于以.miff格式保存临时图像,然后编写一个循环来删除所有.miff图像。另外,如果您对临时图像使用相同的名称,则每次运行代码时,它们都会被覆盖。

如何处理两个图像?使用透明图像而不是圆形此解决方案不适用于带有alpha通道的png图像
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'