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

simon simon at 333.ch
Wed Feb 10 16:49:17 CET 2010


Michael Wechner schrieb:
> 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 ;-)
thanks, will apply this soon.

BTW see 
http://mail-archives.apache.org/mod_mbox/xmlgraphics-batik-users/201002.mbox/%3C4B684B15.5010000@333.ch%3E 
about the headless problem, (still no solved). you also will find the 
test image there.

simon
>
> 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