Well, the coverter works now, except the white background isn't white, it seems to have a wierd pattern on it (is this a dithering problem?). Help appreciated. Ideally I'd like the background of the GIF to be transparent anyway, but previous e-mails about this seem to suggest there is no easy way to do this using batik. Any pointers? -----Original Message----- From: Thomas E Deweese [mailto:thomas.deweese@kodak.com] Sent: 09 January 2003 12:31 To: Batik Users Subject: RE: SVG to GIF - Too many colors?!! >>>>> "PM" == Philip Mackie 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: I think you are overlooking the anti-aliasing Batik/Java2D do by default. This uses a blend of the foreground color and the background color to make edges look smoother, it also greatly increases the number of colors used in the image. You have two options to solve this problem: 1) Turn off anti-aliasing. This can be done by setting the shape-rendering property to 'crispEdges' on say the root SVG element. I suggest you review section 11.7 in the SVG specification for a description of all the rendering hints in SVG. 2) Make use of the IndexImage class to reduce the number of colors in your image to 256 automatically. Check out the PNGTranscoder in the latest CVS Batik (I think there have been some minor changes since 1.5b4 although 1.5b4 may be good enough for you). 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: >> >> > href="style1.css" type="text/css"?> >> >> > xmlns="http://www.w3.org/2000/svg" >> xmlns:xlink="http://www.w3.org/1999/xlink"> > 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" /> > class="zoo" d="M 0 0 L 5 0 L 0 7 L 5 7" /> >> > points="635,357 618,350 635,357"/> > id="ATTRACTIONS"> > id="Blenheim"/> >> > class="city" x="495" y="328">Oxford >> >> 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 --------------------------------------------------------------------- To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org For 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