Message Boards

How to show adaptive image in template / structured web content?

Daniel Niklas, modified 5 Years ago.

How to show adaptive image in template / structured web content?

Junior Member Posts: 46 Join Date: 11/8/10 Recent Posts
Hi,

i'am migrating from liferay 6.1 to 7.1. I have some problems with images in structured web content, https://community.liferay.com/forums/-/message_boards/message/112706369.

I think it could be a solution, to use the new feature "adaptive images". How can i use them in templates? My Templates looks actually like this:

$curImage.getData()&imageThumbnail=2

How can i get the corresponding url for the adapted version of this image?

Best regards
Daniel
thumbnail
Christoph Rabel, modified 5 Years ago.

RE: How to show adaptive image in template / structured web content?

Liferay Legend Posts: 1554 Join Date: 9/24/09 Recent Posts
Well, there are two way to do that. For one, you could use the taglib.
https://dev.liferay.com/de/develop/tutorials/-/knowledge_base/7-1/displaying-adapted-images-in-your-app

The problem with that approach is that it just inserts the image src and some media queries. While this may sound nice and clever, it is actually quite useless. It inserts a link based on the resolution of your screen. So, want to show a tiny thumbnail there and the user has a 4K monitor? Gratulations, he gets 4K icons.


The other way is a bit annoying. I'd recommend to write your own service to do that and do just a call like
<#assign imageurl = myImageFinder.getImageForResolution(fileEntryId, resolution) />
in the template. Writing the image finding code in a template is probably more effort. In the Java code of your imagefinder component, you would need to use MediaQuery to find the configured resolutions:

List<mediaquery> mediaq = _mediaQueryProvider.getMediaQueries(fileEntryId);</mediaquery>

And now iterate through the list to get the images for the resolutions you need.
hth to set you on the right track.