Bug 44682 - TranscoderException and EnclosedException when transcoding SVG to JPEG
Summary: TranscoderException and EnclosedException when transcoding SVG to JPEG
Status: NEW
Alias: None
Product: Batik - Now in Jira
Classification: Unclassified
Component: SVG Rasterizer (show other bugs)
Version: 1.8
Hardware: PC Linux
: P2 critical
Target Milestone: ---
Assignee: Batik Developer's Mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-03-26 10:41 UTC by ks
Modified: 2010-10-30 05:25 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ks 2008-03-26 10:41:34 UTC
Hi,
when I try to follow the description on
http://xmlgraphics.apache.org/batik/using/transcoder.html#createImage
to create a jpg-image file from a svg-file in a JUnitTest, I get the following error message:
 
org.apache.batik.transcoder.TranscoderException: null
Enclosed Exception:
null
	at org.apache.batik.transcoder.image.ImageTranscoder.transcode(ImageTranscoder.java:132)
	at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstractTranscoder.java:142)
	at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:156)
	at de.vitronic.test.TestJPEGTranscoder.testJPEGTranscoder(TestJPEGTranscoder.java:57)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at junit.framework.TestCase.runTest(TestCase.java:154)
	at junit.framework.TestCase.runBare(TestCase.java:127)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:118)
	at junit.framework.TestSuite.runTest(TestSuite.java:208)
	at junit.framework.TestSuite.run(TestSuite.java:203)
	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)


The batik version I use is 1.7.

First I tried to transform a created svg-file into jpeg-file in my own application, but I get the same exception, so I copied the example code from the previous mentioned website in a JUnit-Testcase to figure out if I have done anything wrong in my application. But I got the same problem again, with the copied and pasted code (see above).

When I ran the rasterizer.jar file to convert the image, there is no such an exception thrown. I looked at the code from SVGGenerator from the Rasterizer application, but I doesn´t found a solution, so far to solve the problem.


So here is the code from my JUnitTest method:

    public void testJPEGTranscoder() {

	// Create a JPEG transcoder
	JPEGTranscoder t = new JPEGTranscoder();

	// Set the transcoding hints.
	t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(.8));

	// Create the transcoder input.
	String svgURI;
	try {
	    svgURI = new File("test/TestInput.svg").toURL().toString();

	    TranscoderInput input = new TranscoderInput(svgURI);

	    // Create the transcoder output.
	    OutputStream ostream = new FileOutputStream(
		    "test/TestOutput.jpg");
	    TranscoderOutput output = new TranscoderOutput(ostream);

	    // Save the image.
	    t.transcode(input, output);

	    // Flush and close the stream.
	    ostream.flush();
	    ostream.close();
	    // System.exit(0);

	} catch (MalformedURLException e) {
	    // TODO Auto-generated catch block
	    e.printStackTrace();
	} catch (FileNotFoundException e) {
	    // TODO Auto-generated catch block
	    e.printStackTrace();
	} catch (TranscoderException e) {
	    // TODO Auto-generated catch block
	    e.printStackTrace();
	} catch (IOException e) {
	    // TODO Auto-generated catch block
	    e.printStackTrace();
	}

    }


Thanks in advance for your help,
ks
Comment 1 ks 2008-03-27 05:33:31 UTC
Hi,
I found the cause for the resulting exception. It was a missed dependency for the transcoder.
The following dependency must be included in the "batik-transcoder-1.7.pom", to get the example work as expected (see
http://xmlgraphics.apache.org/batik/using/transcoder.html#createImage).

<dependency>
	<groupId>org.apache.xmlgraphics</groupId>
	<artifactId>batik-codec</artifactId>
	<version>1.7</version>
</dependency>


I´ve tried the transcoding of an png-image, insted of a jpeg-image, to see if I would run in the same problem. The problem showed up again, but the error-message, which was this time from the PNGTranscoder, gave me the hint I needed.

"Could not write PNG file because no WriteAdapter is availble".


Aha. A short search in the PNGTranscoder source led me to line 110.
WriteAdapter adapter = getWriteAdapter("org.apache.batik.ext.awt.image.codec.png.PNGTranscoderInternalCodecWriteAdapter");

And another short search in the libraries of my project, showed me that there was the batik-codec-1.7.jar library missing.
I added that one to my projects pom.xml, ran maven and the JUnitTest again, and the image was created. :-)


I currently use the repository http://repo1.maven.org/maven2/org/apache/xmlgraphics/.
I don´t know where the base-repo is. So could someone with write access to the base-repo add the dependency to the "batik-transcoder-1.7.pom"
and close this bug afterwards?

Thanks
Best regards
ks
Comment 2 Helder Magalhães 2010-10-30 05:25:21 UTC
(In reply to comment #1)
> Hi,
> I found the cause for the resulting exception.

Great! :-)


> I´ve tried the transcoding of an png-image, insted of a jpeg-image, to see if I
> would run in the same problem. The problem showed up again, but the
> error-message, which was this time from the PNGTranscoder, gave me the hint I
> needed.
> 
> "Could not write PNG file because no WriteAdapter is availble".

So a good fix for this "issue" would be a better error message (basically, mimic the PNG behavior) for the JPEG and possible other raster formats.

Patches are welcome! ;-)

(I've stated "issue" because, formally, this issue should be considered invalid due to the nature of the cause itself: a missing dependency. But, as we can do better - the PNG output is the example here - we then _should_ do it! :-) )