0

Here is the path "M276,189h268c5.5,0,10,4.5,10,10v196c0,5.5-4.5,10-10,10H276 c-5.5,0-10-4.5-10-10V199C266,193.5,270.5,189,276,189z"

This is the input image:

Input image

After applying the path to the image by using the below code

draw = Magick::Draw.new
draw.fill 'red'
draw.path path
draw.clip_rule("evenodd")
draw.fill_rule("evenodd")
draw.fill_opacity(0)
draw.draw image
img.trim!
img.write('output.jpg')

This is the output image:

Output image

Now I want to cut the red color part of the image. This means expecting the brown color part only visible. I used the normal image-level crop method. with this Am able to extract the red color part only But I want to extract the image other than the red color from the output image.

Here is the sample output for the black image sample output for the black color

Maybe we have to reverse clip or reverse crop to get this ...

chaitu
  • 1
  • 2
  • Can you please add an image to the question which shows what the desired output is? Just use any image editor to create a mock so that we know what you're trying to achieve. Its very unclear what "But I want to extract the image other than the red color from the output image" actually entails. – max Jun 11 '20 at 10:08
  • Are you trying to make a transparent cutout? Cropping means to actually trim the size of an image. – max Jun 11 '20 at 10:09
  • added sample output https://i.stack.imgur.com/3m6dy.png – chaitu Jun 11 '20 at 10:45

1 Answers1

0

The method

img.paint_transparent

will make that red color part as transparent, but we have to pass the color as an argument to the above method. Initially, I tried by giving the color value as red. so it's not worked. Now am reading the one pixel from the image like

redPixel= img.get_pixels(300, 200, 1, 1)[0]

and getting the color from that pixel-like redPixel.to_color and passing the value to the above method ...

we have to set fuzz value to the image

img = Magick::Image.read("diecut.jpg").first

redPixel= img.get_pixels(300, 200, 1, 1)[0]

img.fuzz = '25%'

puts redPixel.to_color

newimage=img.paint_transparent(redPixel.to_color)

newimage.write("outPut.png")

newimage.display

chaitu
  • 1
  • 2