Error when generating image URL with portal.imageUrl

I am having some difficulties rendering images. I am using version 6.0.0-SNAPSHOT (downloaded from Github on Monday). I understand this version might not be stable, and may be the cause of the error, but here goes:

In my controller, I use the function “portal.imageUrl({id: component.config.image, scale: ‘scale(1,1)’})” to generate the URL for an image I add to a part. This works fine, generating the following URL: “/admin/portal/preview/draft/my-first-module/templates/test-page//image/ef288075-2f99-4475-ad47-059ed83be827/scale-1-1/penguins.jpg”.

I add this to my model, and insert it as the src for my image tag using data-th-src="${image}". Again, this works as intended, generating the expected markup.

However, the image doesn’t load, and when opening the image URL in a new tab, I get a 500 - Internal Server Error, with a nullpointer in the logs:
“java.lang.NullPointerException: null at com.enonic.xp.portal.impl.resource.image.ImageHandleResource.applyScaling(ImageHandleResource.java:109) ~[na:na]…”

Do you have any idea what I am doing wrong?

Hi

I might be wrong (since I have been away from my desk for some time now), but I don’t think there is any scale filter called “scale”. Try for example “block”, which formerly was known as “scaleblock”.

“portal.imageUrl({id: component.config.image, scale: ‘block(1,1)’})”

The available scaling functions should be:

height (formerly known as scaleheight)
max (scalemax)
square (scalesquare)
wide (scalewide)
width (scalewidth)
block (scaleblock)

Great, that worked! :smile:

I had tried scaleblock, etc. before as well, but not with the new names.
‘scale’ was something I believe I found references to a couple of places, but right now I can only find this occurence.

1 Like

Just a note for other users: The parameters for ‘block’ seem to be pixels, so ‘block(1,1)’ might me a bit too small for most uses… :wink:

I have updated the reference mentioned above in the doc now (in the master branch).

What about when you want the image to be the original size with no scaling? Then you don’t want any scaling, but “scale” is a required parameter. I tried using:

scale: ‘(1,1)’

And that seemed to work.

1 Like

Nice Tip @mla, very useful when adding images that you can click and open in lightbox or another window, then you need it in original size.