[opencms-dev] Reading dimensions of an image

Achim Westermann Achim.Westermann at gmx.de
Fri Nov 30 15:52:46 CET 2012


Hi Robert,

your code uses readResource. Therefore only the information of CMS_<PROJECT>_RESOURCES / CMS_<PROJECT>_STRUCTURE is read but not the content from CMS_CONTENTS. You could use cms.readFile instead.

However I would not execute that code per request. As Rüdiger wrote: The property is an efficient way to get the info.

HTH,
Achim 

-------- Original-Nachricht --------
> Datum: Fri, 30 Nov 2012 15:43:23 +0100
> Von: Robert Weber <rw at clt.ag>
> An: "Rüdiger Kurz" <r.kurz at alkacon.com>
> CC: The OpenCms mailing list <opencms-dev at opencms.org>
> Betreff: Re: [opencms-dev] Reading dimensions of an image

> Hi Rüdiger,
> 
> thanks - I just found this :)
> 
> Anyway I would like to know what is wrong with my code.
> 
> Cheers
> Robert
> 
> Am 30.11.2012 um 15:40 schrieb Rüdiger Kurz:
> 
> > Hi Robert,
> > 
> > by default OpenCms stores the dimension into the property 'image.size'
> after uploading a image.
> > 
> > Maybe that will help ...
> > 
> > regards
> > Rüdiger
> > 
> > On 30.11.2012 15:36, Robert Weber wrote:
> >> Hi List,
> >> 
> >> I am trying to read the dimensions of an image within VFS, but this
> code:
> >> 
> >> CmsResource res =
> cmso.readResource(pageContext.getAttribute("image").toString());
> >> CmsFile file = new CmsFile(res);
> >> InputStream in = new ByteArrayInputStream(file.getContents());
> >> BufferedImage bimg = ImageIO.read(in);
> >> int width          = bimg.getWidth();
> >> 
> >> 
> >> Is not working as I get an NullPointerException. Can anyone help?
> >> 
> >> Cheers
> >> Robert
> > 
> > 
> > -- 
> > Kind Regards,
> > Rüdiger.
> > 
> > -------------------
> > 
> > Rüdiger Kurz
> > 
> > Alkacon Software GmbH  - The OpenCms Experts
> > http://www.alkacon.com - http://www.opencms.org
> 
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev
> 
> 
> 



More information about the opencms-dev mailing list