xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas E Deweese <thomas.dewe...@kodak.com>
Subject RE: SVG to GIF - Too many colors?!!
Date Fri, 10 Jan 2003 16:25:47 GMT
>>>>> "PM" == Philip Mackie <Philip.Mackie@RCP.co.uk> writes:

PM> Well, the coverter works now, except the white background isn't
PM> white, it seems to have a wierd pattern on it (is this a dithering
PM> problem?). Help appreciated.

    Yup this would be dithering (needed to reduce the image from
24bit to 8bit).

PM> Ideally I'd like the background of the GIF to be transparent
PM> anyway, but previous e-mails about this seem to suggest there is
PM> no easy way to do this using batik. Any pointers?

    Well Batik generates the transparent background, the problem is
that going to an 8bit image from the 32bit (24bit color + 8 bit
transparency) is hard, and anyway it would be up to the GIF encoder to
identify the transparent color(s).

    My suggestion is either to use PNG, most browsers support it and it
allows you to deliver 24bit image with alpha (so the background is
transparent), or turn off anti-aliasing and then get the GIF encoder
to make the background transparent.

    Anyway, good luck.

PM> -----Original Message----- From: Thomas E Deweese
PM> [mailto:thomas.deweese@kodak.com] Sent: 09 January 2003 12:31 To:
PM> Batik Users Subject: RE: SVG to GIF - Too many colors?!!


>>>>> "PM" == Philip Mackie <Philip.Mackie@RCP.co.uk> writes:

>>> I'm using Batik 1.5beta4 under JDK 1.4.1 on Windows 2000, and I'm
>>> trying to convert svg files to gif. The "ConvertSVGtoGIF" program
>>> works fine as long as I only have 3 colors in the svg file, any
>>> more and I get the following error:
>>> 
>>> Exception in thread "main"
>>> org.apache.batik.transcoder.TranscoderException: null
>>> 
>>> Enclosed Exception: null Enclosed Exception: too many colors for a
>>> GIF at
>>> org.apache.batik.transcoder.image.ImageTranscoder.transcode(Unknown
>>> Source) at
>>> org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(Unknown
>>> Source) at ConvertSVGtoGIF.main(ConvertSVGtoGIF.java:35)
>>> 
>>> It seems that the transcoder thinks there are more than 256 colors
>>> in the SVG file, but this is not so. I've used the ACME GIFEncoder
>>> and the following GIFTranscoder that I found posted on this
>>> mailing list (see the link below for the code for the
>>> GIFTranscoder:

PM>    I think you are overlooking the anti-aliasing Batik/Java2D do
PM> by default.  This uses a blend of the foreground color and the
PM> background color to make edges look smoother, it also greatly
PM> increases the number of colors used in the image.

PM>    You have two options to solve this problem:

PM>    1) Turn off anti-aliasing.  This can be done by setting the
PM> shape-rendering property to 'crispEdges' on say the root SVG
PM> element.  I suggest you review section 11.7 in the SVG
PM> specification for a description of all the rendering hints in SVG.

PM>    2) Make use of the IndexImage class to reduce the number of
PM> colors in your image to 256 automatically.  Check out the
PM> PNGTranscoder in the latest CVS Batik (I think there have been
PM> some minor changes since 1.5b4 although 1.5b4 may be good enough
PM> for you).

PM>    Good luck.

>>> http://koala.ilog.fr/batik/mlists/batik-users/archives/msg00753.html
>>> 
>>> I'll include all of the code that links to this problem now:
>>> 
>>> The code for my ConvertSVGtoGIF java program is shown below:
>>> 
>>> import java.io.*; import
>>> org.apache.batik.transcoder.image.JPEGTranscoder; import
>>> org.apache.batik.transcoder.TranscoderInput; import
>>> org.apache.batik.transcoder.*; import
>>> net.sourceforge.xweb.backend.images.*;
>>> 
>>> public class ConvertSVGtoGIF {
>>> 
>>> public static void main(String [] args) throws Exception { //
>>> create a GIF transcoder GIFTranscoder t = new GIFTranscoder();
>>> 
>>> /* create the transcoder input by taking the file name * given on
>>> the command line */ String svgURI = new
>>> File(args[0]).toURL().toString(); TranscoderInput input = new
>>> TranscoderInput(svgURI); // create the transcoder output
>>> 
>>> OutputStream ostream = new FileOutputStream("out.gif");
>>> TranscoderOutput output = new TranscoderOutput(ostream); // save
>>> the image t.transcode(input, output);
>>> 
>>> // flush and close the stream then exit ostream.flush();
>>> ostream.close(); System.exit(0); } }
>>> 
>>> The skeleton of the offending SVG file that gives the errors is
>>> listed bellow:
>>> 
>>> <?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet
>>> href="style1.css" type="text/css"?>
>>> 
>>> <svg width="1000" height="1000" viewBox="0 0 1000 1000"
>>> xmlns="http://www.w3.org/2000/svg"
>>> xmlns:xlink="http://www.w3.org/1999/xlink"> <defs> <path
>>> id="castle" class="castle" d="M 0 0 L 0 10 L 10 10 L 10 0 L 8 0 L
>>> 8 4 L 6 4 L 6 0 L 4 0 L 4 4 L 2 4 L 2 0 z" /> <path id="zoo"
>>> class="zoo" d="M 0 0 L 5 0 L 0 7 L 5 7" /> </defs> <g id="TOWNS">
>>> <polygon id="Didcot" class="town" points="515,481 528,484 540,490
>>> 543,500 538,508 517,510 510,508 515,481 515,481"/> </g><!-- End of
>>> Towns --> <g id="ROADS"> <polyline id="M40 Spur" class="motorway"
>>> points="635,357 618,350 635,357"/> </g><!-- End of roads --> <g
>>> id="ATTRACTIONS"> <use xlink:href="#castle" x="200" y="200"
>>> id="Blenheim"/> <use xlink:href="#zoo" x="250" y="250" id="AZoo"/>
>>> </g><!-- End of attractions --> <g id="LABELS"> <text id="Oxford"
>>> class="city" x="495" y="328">Oxford</text> </g><!-- End of
labels
--> </svg>
>>>  And the CSS Stylesheet just for reference .......
>>> 
>>> polyline.minorA { fill: none; stroke: crimson; stroke-width: 0.5 }
>>> polyline.majorA { fill: none; stroke: limegreen; stroke-width:
>>> 0.75 } polyline.motorway { fill: none; stroke: cornflowerblue;
>>> stroke-width: 0.5 } polygon.town { fill: grey; stroke-width: 4 }
>>> path.castle { fill: black; } path.zoo { stroke: black;
>>> stroke-width: 1; fill: none } text.city { fill: black; }
>>> 
>>> Hope someone can help me!!
>>> 
>>> Thanks, Phil
>>> 
>>> 
>>> 
>>> 
>>> 

PM> ---------------------------------------------------------------------
PM> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org For
PM> additional commands, e-mail: batik-users-help@xml.apache.org



PM> ---------------------------------------------------------------------
PM> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org For
PM> additional commands, e-mail: batik-users-help@xml.apache.org

PM> ---------------------------------------------------------------------
PM> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org For
PM> additional commands, e-mail: batik-users-help@xml.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org


Mime
View raw message