Image size [WAS: Re: [Yanel-dev] svg and svg-edit resource-type

Michael Wechner michael.wechner at wyona.com
Wed Feb 10 10:31:55 CET 2010


simon wrote:
> Michael Wechner schrieb:
>> Hi
>>
>> How can one set the width (or height) of the generated jpg?
> not yet, but should be easy to implement. wanted to do this.

done:

Index: src/java/com/litwan/yanel/impl/resources/svg/SVGResource.java
===================================================================
--- src/java/com/litwan/yanel/impl/resources/svg/SVGResource.java    
(revision 405)
+++ src/java/com/litwan/yanel/impl/resources/svg/SVGResource.java    
(working copy)
@@ -92,6 +92,9 @@
         return pathParts[pathParts.length - 1];
     }       
 
+    /**
+     * Generate images (jpg or png) from svg
+     */
     protected View renderCustomView(ConfigurableViewDescriptor 
viewDescriptor) throws UsecaseException {
         View view = null;
         String viewId = viewDescriptor.getId();
@@ -104,11 +107,22 @@
             float jpgQualitiy = 1;
             try {
                 jpgQualitiy = 
Float.parseFloat(getResourceConfigProperty(RESOURCE_PROP_JPG_QUALITY));
+                t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, 
jpgQualitiy);
             } catch (Exception e) {
-                // TODO: handle exception
+                log.error(e, e);
             }
-            t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, jpgQualitiy);
 
+            try {
+                String width = getResourceConfigProperty("image-width");
+                if (width != null) {
+                    t.addTranscodingHint(JPEGTranscoder.KEY_WIDTH, 
Float.parseFloat(width));
+                } else {
+                    log.warn("No width specified, hence will use 
default width"); // 
http://xmlgraphics.apache.org/batik/javadoc/org/apache/batik/transcoder/SVGAbstractTranscoder.html#width
+                }
+            } catch (Exception e) {
+                log.error(e, e);
+            }
+
             // Create the transcoder input.
             try {
                 View viewJPEG = new View();

and it's backwards compatible ;-)

Cheers

Michi
>>
>> What is jpg-quality good for? Is this the resolution?
> no the quality. how much it will be compressed.
>
> cheers
> simon
>>
>> (http://trac.yanel-contribution.3k3.org/wiki/svg)
>>
>> Thanks
>>
>> Michi
>>
>



More information about the Yanel-development mailing list