How to get the extension of the resolution of a picture

hoebbel
Crownpeak employee
Crownpeak employee
0 0 813

It seems to be an easy task to get the extension of the resolution of a picture, but there are some pitfalls you should be aware of.

First, you may try it by just getting the resolution of the picture and the appropriate extension. Works fine as long as the resolution of the picture has already been manually calculated or uploaded. If not, you will get null instead.

Secondly, you may try it by using the MediaMetaData of the picture. There you will always get an extension - but if the picture for the appropriate resolution has manually been uploaded, maybe you get the wrong extension.

So the correct way is to check, if you can directly get the extension of the resolution of the picture and if it is null, get the extension with the use of the MediaMetaData.

Here is a simple beanshell script [use it as a context menue script] which you can use to evaluate the difference between the two ways:

import de.espirit.firstspirit.access.store.mediastore.Picture;

project = context.getProject();

mediaContent = context.getStoreElement().getMediaContent( project.getMasterLanguage() );

if ( mediaContent != null && mediaContent instanceof Picture ) {

    picture = mediaContent;

    resolutions = project.getResolutions();

    for (res : resolutions) {

        if ( res != null ) {

            context.logInfo("Resolution: " + res.getUid());

            pictureRes = picture.getPictureResolution(res);

            if ( pictureRes != null ) {

                extension = pictureRes.getExtension();

                extMeta = picture.getPictureMetaData(res).getExtension();

                context.logInfo("extension: " + extension + " / " + extMeta);

            } else {

            context.logError( "Resolution " + resolution + " not found." );

        }

        } else {

            context.logError( "Resolution " + resolution + " not found." );

        }

    }

}

Best regards,

  Holger

Version history
Last update:
‎04-29-2011 03:25 AM
Updated by: