Uses -fill white -fuzz 11% +opaque "#000000" to fill in the fox's head with white (so we can see most of the original image). (Effectively) inverts the colors for masking purposes ( -negate). If necessary, we can do something similar in two steps: convert fox.jpg -type Grayscale -negate -fill white -fuzz 11% +opaque "#000000" -blur 0x1 fox_blur_mask.jpgĬonvert fox.jpg fox_blur_mask.jpg -compose copy_opacity -composite fox_transparent_blur_mask_result.pngĬreates a black and white version of the image ( -type Grayscale). You can see that the edges are softer now: This command creates a blurred mask which is then composited with the original image. To do this in one step, we can take some code from this forum post and use it like so: convert fox.jpg ( -clone 0 -fuzz 11% -transparent white -blur 0x1 ) -compose copy_opacity -composite fox_transparent_fuzzed_blurry_mask.png To address this issue, we can use a mask that has been blurred to help soften the edges of the image. While a simple use of -fuzz may work well enough, there can still be undesired roughness: To fix this, one possible option is to use -fuzz to select pixels that are almost (nearly) white: convert fox.jpg -fuzz 11% -transparent white fox_transparent_fuzzed.png This is because the areas in white (above) are not really white (they are off-white, mostly due to anti-aliasing as you've noted). However, this yields the same results as your bad image, which is undesirable: background) to be transparent, you can use: convert fox.jpg -transparent white fox_transparent.png Please forgive any mistakes, omissions or things I may have overlooked. Though I give my suggestions below, there are likely much better ways to do things which I am currently unaware of. That said, for the example you posted, here are some approaches that may be more satisfactory. so there may not be a single "good" solution. I am on Mac OSX Sierra with Imagemagick 7.0.8.35 Q16.Unfortunately, unlike your previous question regarding icons, there are many ways to approach background removal with more complex images. So I assume you are using MSVG, but it could be Inkscape if you have installed that on your system. Mine is 1.6.36įrom your version information, I do not see rsvp listed. You cannot tell about Inkscape with this method.Ĭheck to see what you are using for your SVG renderer and its version. At the end of that line it will either say XML or RSVG. You can tell if your Imagemagick has MSVG/XML or RSVG by magick -list formatĪnd look for the line starting with SVG. Or magick -background none RSVG:test.svg test3.png When I force the use of RSVG 2.44.12 by creating an entry in the delegates.xml file, I get a white triangle on a transparent background, which I assume is what you want. But I suspect the white triangle is slightly smaller from the black border it had. I then get a white triangle on a black background. magick -background none MSVG:test.svg test2.pngīut if I just want a black background, then magick -background black MSVG:test.svg test2.png If I add -background none, then I get white triangle with black outline on a transparent background. When I force Imagemagick to use MSVG, I get a white triangle with a simple black outline on a white background. Or if I want a black background magick -background black test.svg test2.png I get a white triangle on a transparent background. magick test.svg test2.pngīut it works fine if I added -background none magick -background none test.svg test2.png But in this case it is not working well with that file. If Inkscape is installed Imagemagick will use it automatically. I just tried the following command with Inkscape 0.92.4 and it comes out totally white. In ImageMagick, SVG files can be rendered by any one of three tools: Imagemagick's MSVG/XML, RSVG delegate and Inkscape, usually in order of increasing accuracy. I tried just about every variation of command options for imagemagick that had to do with color or black and sadly it never comes out with what i want - transparent background, solid white path (as described by fill on the SVG). I get a perfect image, except it has a black border: Now when i convert it to png like so: convert -background none -density 9600 -resize 32x "myFile.svg" "myFile.png" I have a basic svg (adopted from W3Schools example): ![]() Version: ImageMagick 7.0.8-35 Q16 x86_64 Ĭopyright: © 1999-2019 ImageMagick Studio LLCĭelegates (built-in): bzlib freetype heic jng jp2 jpeg lcms ltdl lzma openexr png tiff webp xml zlib ![]() My imagemagick details (installed with brew) convert -version
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |