Hi magick,
I would like to change the background of an image by applying its clipping path. That is to say that the current image has a white background and a clipping path which describes a part of this image.
The resulting image should be the same image containing the image part with the clipping part on a blue background.
I've tried many combinations of "-clip", "-clip-path id" etc., but nothing seems to work.
Any help is appreciated!
Thanks a lot!
Sven
Change background by applying clipping path
Re: Change background by applying clipping path
Hi Sven
I has a similar problem and solved it using something like:
I am no expert in ImageMagick, so this is only a qualified guess:)
I has a similar problem and solved it using something like:
Code: Select all
+clip-path #1 -fill blue -draw "color 0,0 reset"
Re: Change background by applying clipping path
Hi
I also have a related question which I hope anyone can help me with:
I want to give a picture a white background by using the clipping path.
This works great if i'm using a RGB image or converting from CMYK to RGB using color profiles, but in this case i only want to make the background white on a CMYK image - nothing else. Using the above command on a CMYK image gives me a black background instead of white
Any help is appreciated.
I also have a related question which I hope anyone can help me with:
I want to give a picture a white background by using the clipping path.
Code: Select all
"c:\Program Files\ImageMagick-6.3.8-Q16\convert.exe" +clip-path #1 -fill white -draw "color 0,0 reset" 18.tif 18.jpg
Any help is appreciated.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Change background by applying clipping path
The -draw operation and most colors handling is done in RGB space.
However I have found that many other operations also do handle things properly, but not with enough certainty to give a bug report.
For example I have found that using -opaque to replace a particular color with the current -fill color on a CMYK image often results in the color being applied as if, both color specifications were being mis-read as a CMYK color, when the color was given as a RGB color.
For example using the IM examples "colorwheel.png" image, works fine for RGB images.But goes bad when the image is converted to either CMY or CMYK in memory.
The result looks to be as if the given RGB 'red' color was being looked at as a CMYK cyan (which has the same memory bit pattern). Clearly a bug.
Actually viewing a CMY colorspace image on screen using the special "x:" output format is displays incorrectly!
However back you your problem...
I would first try to switch to using -opaque with a -fuzz factor of more than 100% (all colors, masked by clipping path) to -draw. But as you saw that will also fail, which should be reported as BUG for CMYK images.
Sorry.
Alternative...
The only other solution I can see is to use the clipping path to create a transparency mask. This could then be colorized to white, converted to CMYK and overlaid on the original image, using alpha composition.
There is always more than one way to do anything in image processing.
However I have found that many other operations also do handle things properly, but not with enough certainty to give a bug report.
For example I have found that using -opaque to replace a particular color with the current -fill color on a CMYK image often results in the color being applied as if, both color specifications were being mis-read as a CMYK color, when the color was given as a RGB color.
For example using the IM examples "colorwheel.png" image, works fine for RGB images.
Code: Select all
convert colorwheel.png -fuzz 50% -fill red -opaque red replace_red.png
Code: Select all
convert colorwheel.png -colorspace CMY -fuzz 50% -fill red -opaque red -colorspace RGB replace_red_2.png
Actually viewing a CMY colorspace image on screen using the special "x:" output format is displays incorrectly!
However back you your problem...
I would first try to switch to using -opaque with a -fuzz factor of more than 100% (all colors, masked by clipping path) to -draw. But as you saw that will also fail, which should be reported as BUG for CMYK images.
Sorry.
Alternative...
The only other solution I can see is to use the clipping path to create a transparency mask. This could then be colorized to white, converted to CMYK and overlaid on the original image, using alpha composition.
There is always more than one way to do anything in image processing.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Change background by applying clipping path
Hello anthony
Thank you for your feedback. Could you please give me an example of your alternative solution. I'm not sure i understand how this is done.
Thanks again!
Thank you for your feedback. Could you please give me an example of your alternative solution. I'm not sure i understand how this is done.
Thanks again!
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Change background by applying clipping path
I do not have a image with a clipping path!! Making it difficult to test and debug the solution.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Change background by applying clipping path
For some reason, the suggested solution:
only works for me on a windows machine - when I try the same command on Linux (have tried with several different versions of ImageMagick) I get all sorts of errors. Earlier versions won't accept it as a valid command, while later versions create a file named +clip-path.
What am I doing wrong?
Code: Select all
convert +clip-path #1 -fill blue -draw "color 0,0 reset" in.jpg out.jpg
What am I doing wrong?
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Change background by applying clipping path
Start a new topic
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/