This question is answered.


Permlink Replies: 4 - Pages: 1 - Last Post: 21 Aug 22, 20:00 Last Post By: RobM
AndreWolff

Posts: 2,504
Registered: 14-Dec-2007
Is there a simple way to get the sizes in a srcset.
Posted: 20 Aug 22, 12:33
 
  Click to reply to this thread Reply
For a new skin I need to know all available widths in a. Srcset.
I can dot that with searching ‘xxxw,” substrings, but I hope there is a better method. It would be nice if the heights are also given.

So who can provide the code?
RobM

Posts: 4,383
Registered: 4-Aug-2006
Re: Is there a simple way to get the sizes in a srcset.
Posted: 20 Aug 22, 13:22   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
See the section on creating your own variations at
https://jalbum.net/help/en/Sample_scripts#Generating_extra_slide_images
davidekholm

Posts: 4,407
Registered: 18-Oct-2002
Re: Is there a simple way to get the sizes in a srcset.
Posted: 20 Aug 22, 17:49   in response to: AndreWolff in response to: AndreWolff
Correct
  Click to reply to this thread Reply
AndreWolff wrote:
For a new skin I need to know all available widths in a. Srcset.
I can dot that with searching ‘xxxw,” substrings, but I hope there is a better method. It would be nice if the heights are also given.

So who can provide the code?


The "imageRenditions" variable contains a list of Rendition objects. That should do it. Call getWidth() on each Rendition object.
AndreWolff

Posts: 2,504
Registered: 14-Dec-2007
Re: Is there a simple way to get the sizes in a srcset.
Posted: 21 Aug 22, 18:35   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Thanks Rob and David for your help.

As a first trial, I added in init.bsh:

import java.lang.net.jalbum.Rendition;
 
String getSrcSetSizes(AlbumObject ao)  {
  String sizesSet = "";
  if (ao.getVars().get("imageRenditions") != null) {
    ImageRenderer renderer = ao.getRenderer();
    sizesSet= renderer.getWidth().toString();
  }
  return sizesSet;
}


and added to index.htt inin the <ja:rowiterator><ja:coliterator> section:

<%
          System.out.println("getSrcSetSizes: " + getSrcSetSizes(currentObject));
%>


But that gives next error message:
bsh.ReflectError: Method getWidth() not found in class'se.datadosen.jalbum.ImageRenderer' in index.htt at line number 506


What do I wrongly?

I get the same error message if I remove
import java.lang.net.jalbum.Rendition;


Edit:

I found the problem, it should be:

  sizesSet= ao.getRenderer().getCloseupRenditions().get(0).getWidth().toString();


Edited by: AndreWolff on 21 Aug 2022, 19:11
RobM

Posts: 4,383
Registered: 4-Aug-2006
Re: Is there a simple way to get the sizes in a srcset.
Posted: 21 Aug 22, 20:00   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
AndreWolff wrote:
But that gives next error message:
bsh.ReflectError: Method getWidth() not found in class'se.datadosen.jalbum.ImageRenderer' in index.htt at line number 506

Edit:

I found the problem, it should be:

  sizesSet= ao.getRenderer().getCloseupRenditions().get(0).getWidth().toString();
Or use
ImageRenderer renderer = ao.getRenderer();
		for(r: renderer.getCloseupRenditions()) {
			System.out.println(r.getWidth());
		}
Legend
Forum admins
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums