converting from svg to png creates missing pixel clusters
converting from svg to png creates missing pixel clusters
Hello ,
I am converting an svg image to an png image programmatically as follows:
"convert": "-background transparent -size 600x600 svg:- -units PixelsPerInch -density 300 -alpha off -fill #FFFFFE -opaque #FFFFFF -alpha on -bordercolor #FFFFFF -border 15 png:-"
I am using the above command because the printer that prints the resulting png image does the two pass printing. In the first pass, it lays layer of white for each non-white pixel (color other than #FFFFFF). In the second pass, it prints all colored pixels.
The problem that I am experiencing is that the converted image http://sourcepin.com/converted.png DOES NOT print pixels that are clustering around the white pixels (color #FFFFFF). It almost looks like that the immediate perimeter of the white pixel regions do not get printed as if those pixels were transparent - http://sourcepin.com/printed.jpg shows both printer passes, white pass and color pass. The crazy thing is that if I open the converted png in photoshop, ALL the pixels are non-white which means the first printer pass should lay a solid white without skipping printing a single pixel.
Any thoughts on this would be greatly appreciated as I have been struggling to figure this out for days.
I am converting an svg image to an png image programmatically as follows:
"convert": "-background transparent -size 600x600 svg:- -units PixelsPerInch -density 300 -alpha off -fill #FFFFFE -opaque #FFFFFF -alpha on -bordercolor #FFFFFF -border 15 png:-"
I am using the above command because the printer that prints the resulting png image does the two pass printing. In the first pass, it lays layer of white for each non-white pixel (color other than #FFFFFF). In the second pass, it prints all colored pixels.
The problem that I am experiencing is that the converted image http://sourcepin.com/converted.png DOES NOT print pixels that are clustering around the white pixels (color #FFFFFF). It almost looks like that the immediate perimeter of the white pixel regions do not get printed as if those pixels were transparent - http://sourcepin.com/printed.jpg shows both printer passes, white pass and color pass. The crazy thing is that if I open the converted png in photoshop, ALL the pixels are non-white which means the first printer pass should lay a solid white without skipping printing a single pixel.
Any thoughts on this would be greatly appreciated as I have been struggling to figure this out for days.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: converting from svg to png creates missing pixel cluster
Try reading the input svg after specifying the background, the density and units . Also what delegate is being used to do the conversion? MSVG, RSVG or Inkscape? What version of IM and what platform are you using?
-size is not doing anything in your command. It can be removed. The output size is controlled by the density provided to the svg file.
If the svg file is CMYK, you may need to add -colorspace sRGB before reading the svg file. Note that PNG does not support pixelsperinch only pixelspercentimenter. But IM should do the conversion for your. So don't be surprised if the density is a different number.
try
convert -background transparent -units PixelsPerInch -density 300 image.svg -alpha off -fill #FFFFFE -opaque #FFFFFF -bordercolor #FFFFFF -border 15 -alpha on image.png
-size is not doing anything in your command. It can be removed. The output size is controlled by the density provided to the svg file.
If the svg file is CMYK, you may need to add -colorspace sRGB before reading the svg file. Note that PNG does not support pixelsperinch only pixelspercentimenter. But IM should do the conversion for your. So don't be surprised if the density is a different number.
try
convert -background transparent -units PixelsPerInch -density 300 image.svg -alpha off -fill #FFFFFE -opaque #FFFFFF -bordercolor #FFFFFF -border 15 -alpha on image.png
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: converting from svg to png creates missing pixel cluster
According to (8-bit) gimp, your converted.png has #ffffff where your printer doesn't print. I suspect the problem is that your image has transparency in these areas, which the final "-bordercolor #FFFFFF -border 15" makes white.
You can test this with:
Does out.png have any transparency? Do you really want it?
You can test this with:
Code: Select all
"convert": "-background transparent -size 600x600 svg:- -units PixelsPerInch -density 300 out.png
snibgo's IM pages: im.snibgo.com
Re: converting from svg to png creates missing pixel cluster
Thank you for your help clarifying my command. I am on CentOS release 6.4 (Final) using
ImageMagick 6.8.7-1 2013-10-20 Q16
$ convert -list configure | grep DELEGATES
DELEGATES bzlib djvu mpeg fontconfig freetype jng jpeg lcms openexr pango png ps tiff x xml zlib
Does this help? How can I confirm the svg file is CMYK and what result would the png produce if I do not specify -colorspace sRGB?
ImageMagick 6.8.7-1 2013-10-20 Q16
$ convert -list configure | grep DELEGATES
DELEGATES bzlib djvu mpeg fontconfig freetype jng jpeg lcms openexr pango png ps tiff x xml zlib
Does this help? How can I confirm the svg file is CMYK and what result would the png produce if I do not specify -colorspace sRGB?
Re: converting from svg to png creates missing pixel cluster
Hello snibgo,
Thank you for your help.
When I run "convert": "-background transparent -size 600x600 svg:- -units PixelsPerInch -density 300 out.png"
I get an image that has transparent background http://sourcepin.com/converted2.png around the rounded rectangle. This is what I would expect from the command above. The printer I am using does not print #FFFFFF pixels, so effectively I am trying to fake the printer by replacing all #FFFFFF pixels to #FFFFFE so that the printer prints those.
Since I also need to add the 15px border around the entire image, I am using #FFFFFF background as I know this will not be printed by the printer.
As a result I expect for the printer to lay solid white where the rounded rectangle will be. Currently some pixels within that rounded rectangle do not print and this is my dilemma.
Thank you for your help.
When I run "convert": "-background transparent -size 600x600 svg:- -units PixelsPerInch -density 300 out.png"
I get an image that has transparent background http://sourcepin.com/converted2.png around the rounded rectangle. This is what I would expect from the command above. The printer I am using does not print #FFFFFF pixels, so effectively I am trying to fake the printer by replacing all #FFFFFF pixels to #FFFFFE so that the printer prints those.
Since I also need to add the 15px border around the entire image, I am using #FFFFFF background as I know this will not be printed by the printer.
As a result I expect for the printer to lay solid white where the rounded rectangle will be. Currently some pixels within that rounded rectangle do not print and this is my dilemma.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: converting from svg to png creates missing pixel cluster
It does not list rsvg nor inkscape. I believe the xml indicates it is using IM's internal MSVG, which is the least flexible to the others. But I would not know if that is the problem or not. Sounds like you are doing something special to deal with printer issues. I am not sure I can help further.$ convert -list configure | grep DELEGATES
DELEGATES bzlib djvu mpeg fontconfig freetype jng jpeg lcms openexr pango png ps tiff x xml zlib
Try setting the density first before the svg so that your output image is larger and may maintain your pixel values better.
Code: Select all
convert -background transparent -units PixelsPerInch -density 300 image.svg -alpha off -fill #FFFFFE -opaque #FFFFFF -bordercolor #FFFFFF -border 15 -alpha on image.png
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: converting from svg to png creates missing pixel cluster
Fair enough, but what colour and transparency are the pixels within the image, where the printing goes wrong?rs13 wrote:I get an image that has transparent background http://sourcepin.com/converted2.png around the rounded rectangle.
snibgo's IM pages: im.snibgo.com
Re: converting from svg to png creates missing pixel cluster
Hello Snibgo,
That's the thing, I can't pinpoint which are the faulty pixels. If you look at http://www.sourcepin.com/printed.png you will see that the missing pixels are clustering around #FFFFFF regions within the image.
That's the thing, I can't pinpoint which are the faulty pixels. If you look at http://www.sourcepin.com/printed.png you will see that the missing pixels are clustering around #FFFFFF regions within the image.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: converting from svg to png creates missing pixel cluster
Your printed.png link is broken.
Your files are 16-bit/channel. Your colour specificatons are 8-bit/channel. Your printer may be 8-bit/channel.
When you specify a colour as 8-bit #FFFFFE, IM expands this to #FFffFFffFEfe. What does the printer driver do with that? It might round it to 8-bit #FFFFFF.
converted2.png has many colours around for example #FFEDFE9FFE7. These aren't white to 16-bit IM, but would be treated by an 8-bit printer as white.
You might find that if you convert to 8-bit, the printer does what you expect.
"convert": "-background transparent -size 600x600 svg:- -units PixelsPerInch -density 300 -depth 8 -alpha off -fill #FFFFFE -opaque #FFFFFF -alpha on -bordercolor #FFFFFF -border 15 png:-"
Your files are 16-bit/channel. Your colour specificatons are 8-bit/channel. Your printer may be 8-bit/channel.
When you specify a colour as 8-bit #FFFFFE, IM expands this to #FFffFFffFEfe. What does the printer driver do with that? It might round it to 8-bit #FFFFFF.
converted2.png has many colours around for example #FFEDFE9FFE7. These aren't white to 16-bit IM, but would be treated by an 8-bit printer as white.
You might find that if you convert to 8-bit, the printer does what you expect.
"convert": "-background transparent -size 600x600 svg:- -units PixelsPerInch -density 300 -depth 8 -alpha off -fill #FFFFFE -opaque #FFFFFF -alpha on -bordercolor #FFFFFF -border 15 png:-"
snibgo's IM pages: im.snibgo.com
Re: converting from svg to png creates missing pixel cluster
Hello Snibgo,
Sorry for responding so late on this but it took a while to be able to test your suggestion. It worked and it was exactly the problem. I really, really appreciate your help and hope others will benefit from your insight. It saved me major headache trying to figure what may just be wrong.
Best,
Rob
Sorry for responding so late on this but it took a while to be able to test your suggestion. It worked and it was exactly the problem. I really, really appreciate your help and hope others will benefit from your insight. It saved me major headache trying to figure what may just be wrong.
Best,
Rob
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: converting from svg to png creates missing pixel cluster
Excellent. Glad to help, and thanks for getting back to us.
snibgo's IM pages: im.snibgo.com