Permlink Replies: 23 - Pages: 2 [ 1 2 | Next ] - Last Post: 16 Jul 21, 20:38 Last Post By: AndreWolff
davidekholm

Posts: 3,442
Registered: 18-Oct-2002
ConstrainRatioFilter
Posted: 7 Feb 19, 19:15
  Click to reply to this thread Reply
Here's a new image filter for you guys. It's called ConstrainRatioFilter and is similar to FixedShapeFilter in that it crops images but instead of a fixed shape, you set min and max bounds for the aspect ratio (the width / height ratio). The purpose of this is to allow most images to have their thumbnails remain their natural aspect ratio, but make exceptions for panorama images, which tends to look like tiny film strips if they have a really large aspect ratio.

Here's a usage example from a user variable:
filter1 | class=ConstrainRatioFilter maxRatio=2 thumbnails prescale
That will ensure that no thumbnail has an aspect (width/height ratio) higher than 2.

Here's an example from init.bsh:
engine.addFilter(new ConstrainRatioFilter(0.5F, 2F), JAFilter.THUMBNAILS_PRESCALE_STAGE);

where 0.5F and 2.0F are the min and max ratios. Those values also happen to be the default.
To get squary thumbnails, simply set min and max to 1.
There are also the same xWeight and yWeight variables as FixedShapeFilter has if you wish to adjust the focus when cropping.

To try this filter, put the attached code in a "plugins" folder of your skin. Future jAlbum versions will include it in the shared "plugins" folder.

Edited by: jGromit on 15-Feb-2019 21:09, to fix syntax of sample usage
JeffTucker

Posts: 8,039
Registered: 31-Jan-2006
Re: ConstrainRatioFilter
Posted: 11 Feb 19, 23:10   in response to: davidekholm in response to: davidekholm
  Click to reply to this thread Reply
I hadn't paid much attention to this - I've been up to my whatzit in some other skin improvements (and I'm still wrestling with one of them).

Where this could be a big help is in skins that use a justified gallery of thumbnails. Including a pano in the mix really throws the justified gallery script for a loop. It doesn't malfunction, but it produces an undesirable effect.

A quick comparison.... In the "regular" screenshot, look at what the presence of the pano does to that second row of thumbnails - by necessity, it makes the row very short, vertically. In the "constrained" screenshot, I've restricted the aspect ratio to 2.0.

I think this feature is destined for inclusion in Mercury, Neptune, and Pluto.
AndreWolff

Posts: 1,289
Registered: 14-Dec-2007
Re: ConstrainRatioFilter
Posted: 13 Feb 19, 00:11   in response to: davidekholm in response to: davidekholm
  Click to reply to this thread Reply
davidekholm wrote:
To try this filter, put the attached code in a "plugins" folder of your skin. Future jAlbum versions will include it in the shared "plugins" folder.
Only the .class file or both files?
davidekholm

Posts: 3,442
Registered: 18-Oct-2002
Re: ConstrainRatioFilter
Posted: 13 Feb 19, 13:21   in response to: AndreWolff in response to: AndreWolff
  Click to reply to this thread Reply
Happy to hear it's appreciated! The .class file is enough to include, and as soon as the next jAlbum release is out, it won't be needed to include by skins, but it doesn't hurt to keeping it included either.
JeffTucker

Posts: 8,039
Registered: 31-Jan-2006
Re: ConstrainRatioFilter
Posted: 13 Feb 19, 13:38   in response to: davidekholm in response to: davidekholm
  Click to reply to this thread Reply
davidekholm wrote:
...as soon as the next jAlbum release is out, it won't be needed to include by skins....

The catch is that if the skin has some sort of checkbox to invoke the new filter, but doesn't include it in its own files, that version of the skin is then restricted to the newest release.

My skins are all still usable with jAlbum 15.2 (15.4 in one case). I don't hesitate to push users to a newer jAlbum version when it's needed, but with something like this, the skin can cut the users a break. ;)
davidekholm

Posts: 3,442
Registered: 18-Oct-2002
Re: ConstrainRatioFilter
Posted: 13 Feb 19, 13:46   in response to: JeffTucker in response to: JeffTucker
  Click to reply to this thread Reply
I agree. This is just a minor improvement that shouldn't force users to update.
AndreWolff

Posts: 1,289
Registered: 14-Dec-2007
Re: ConstrainRatioFilter
Posted: 13 Feb 19, 22:04   in response to: davidekholm in response to: davidekholm
  Click to reply to this thread Reply
Well I added file ConstrainRatioFilter.class to my already existing plugins folder and added line
engine.addFilter(new ConstrainRatioFilter(0.5F, 2F, JAFilter.THUMBNAILS_PRESCALE_STAGE));
to the top of my init,bsh file.
But it is not working for me, I get next error message:
Stack trace for jAlbum 18 using skin FancyBox 1.3.4:
 
se.datadosen.util.ScriptException: Sourced file: inline evaluation of: ``/*   * init.bsh last change: 2018-11-09   * Executed only once before the creati . . . '' : Constructor error: Can't find constructor: ConstrainRatioFilter( float, float, int ) in class: ConstrainRatioFilter : at Line: 18 : in file: inline evaluation of: ``/*   * init.bsh last change: 2018-11-09   * Executed only once before the creati . . . '' : new ConstrainRatioFilter ( 0.5F , 2F , JAFilter .THUMBNAILS_PRESCALE_STAGE ) 
 in init.bsh at line number 18
	at se.datadosen.util.ScriptException.of(ScriptException.java:59)
	at se.datadosen.jalbum.AlbumBean.processScript(AlbumBean.java:2471)
	at se.datadosen.jalbum.AlbumBean.prepareMakeAlbum(AlbumBean.java:2951)
	at se.datadosen.jalbum.AlbumBean.makeAlbum(AlbumBean.java:2694)
	at se.datadosen.jalbum.AlbumBean.smartMakeAlbum(AlbumBean.java:2658)
	at se.datadosen.jalbum.JAlbumFrame$6.run(JAlbumFrame.java:1091)
Caused by: javax.script.ScriptException: Sourced file: inline evaluation of: ``/*   * init.bsh last change: 2018-11-09   * Executed only once before the creati . . . '' : Constructor error: Can't find constructor: ConstrainRatioFilter( float, float, int ) in class: ConstrainRatioFilter : at Line: 18 : in file: inline evaluation of: ``/*   * init.bsh last change: 2018-11-09   * Executed only once before the creati . . . '' : new ConstrainRatioFilter ( 0.5F , 2F , JAFilter .THUMBNAILS_PRESCALE_STAGE ) 
 in inline evaluation of: ``/*   * init.bsh last change: 2018-11-09   * Executed only once before the creati . . . '' at line number 18
	at bsh.BshScriptEngine.evalSource(BshScriptEngine.java:96)
	at bsh.BshScriptEngine.eval(BshScriptEngine.java:57)
	at java.scripting/javax.script.AbstractScriptEngine.eval(Unknown Source)
	at se.datadosen.jalbum.AlbumBean.doProcessExpression(AlbumBean.java:2521)
	at se.datadosen.jalbum.AlbumBean.processExpression(AlbumBean.java:2513)
	at se.datadosen.jalbum.AlbumBean.processScript(AlbumBean.java:2469)
	... 4 more

What do I wrongly?
davidekholm

Posts: 3,442
Registered: 18-Oct-2002
Re: ConstrainRatioFilter
Posted: 13 Feb 19, 22:34   in response to: AndreWolff in response to: AndreWolff
  Click to reply to this thread Reply
Move the closing parenthesis:
engine.addFilter(new ConstrainRatioFilter(0.5F, 2F), JAFilter.THUMBNAILS_PRESCALE_STAGE);
AndreWolff

Posts: 1,289
Registered: 14-Dec-2007
Re: ConstrainRatioFilter
Posted: 13 Feb 19, 23:34   in response to: davidekholm in response to: davidekholm
  Click to reply to this thread Reply
Yes, that works now:

Compare this original album with this album with the new filter.

It is indeed an improvement, thanks!
davidekholm

Posts: 3,442
Registered: 18-Oct-2002
Re: ConstrainRatioFilter
Posted: 14 Feb 19, 09:44   in response to: AndreWolff in response to: AndreWolff
  Click to reply to this thread Reply
Yes, looks better for sure, and people still understand they are panoramas. If you're happy with the 0.5 - 2 range, then you don't need to pass those parameters at all. They are the default.
JeffTucker

Posts: 8,039
Registered: 31-Jan-2006
Re: ConstrainRatioFilter
Posted: 15 Feb 19, 22:27   in response to: davidekholm in response to: davidekholm
  Click to reply to this thread Reply
I hesitate even to suggest this, because it would mean some laborious rewriting of every one of my skins (not difficult - just boring). But given that a lot of the other "filter" stuff is now accessible elsewhere, like on the Effects tab, shouldn't the fixed-shape and constrain-ratio filters be settable on the Images tab, along with the thumbnail bounds? They'd need to be "one or the other or neither," of course, perhaps with a couple of spinners for the constrain-ratio limits.
davidekholm

Posts: 3,442
Registered: 18-Oct-2002
Re: ConstrainRatioFilter
Posted: 16 Feb 19, 12:02   in response to: JeffTucker in response to: JeffTucker
  Click to reply to this thread Reply
Yeah, somehow I should unify the 3 APIs we have today for basically doing the same thing - manipulating images.
AndreWolff

Posts: 1,289
Registered: 14-Dec-2007
Re: ConstrainRatioFilter
Posted: 16 Feb 19, 16:54   in response to: davidekholm in response to: davidekholm
  Click to reply to this thread Reply
davidekholm wrote:
Yeah, somehow I should unify the 3 APIs we have today for basically doing the same thing - manipulating images.
No need to do that, it costs only development time of you and the skin developers and it offers nothing new for the Users!

You beter improve uploading and implements your to do list and the feature requests which are not yet on your todo list, because in that case do Users do get new features!
JeffTucker

Posts: 8,039
Registered: 31-Jan-2006
Re: ConstrainRatioFilter
Posted: 16 Feb 19, 17:16   in response to: AndreWolff in response to: AndreWolff
  Click to reply to this thread Reply
AndreWolff wrote:
davidekholm wrote:
Yeah, somehow I should unify the 3 APIs we have today for basically doing the same thing - manipulating images.
No need to do that, it costs only development time of you and the skin developers and it offers nothing new for the Users!

It would, for example, allow users to choose fixed-shape thumbnails or constrained aspect ratio thumbnails for any skin, not just the ones where the skin developer has built it in, without sending them into the messy "user variables" world.

After porting the same code into six different skins (and I'm not even touching Matrix and MatrixSlide, or it would be eight skins), it occurred to me that this shouldn't be necessary for something that really is a core image-processing feature, not something skin-specific.
JeffTucker

Posts: 8,039
Registered: 31-Jan-2006
Re: ConstrainRatioFilter
Posted: 16 Feb 19, 17:20   in response to: AndreWolff in response to: AndreWolff
  Click to reply to this thread Reply
I find it almost comical that you're suggesting that there's no reason to improve the jAlbum core to take over something a skin developer can just as well do on his own. Your history of asking for exactly such changes is a long one.

This is just the short list - I got tired of looking:

https://jalbum.net/forum/thread.jspa?threadID=49452
https://jalbum.net/forum/thread.jspa?threadID=51698
https://jalbum.net/forum/thread.jspa?threadID=53400
https://jalbum.net/forum/thread.jspa?threadID=53348
https://jalbum.net/forum/thread.jspa?threadID=53341
https://jalbum.net/forum/thread.jspa?threadID=52968
https://jalbum.net/forum/thread.jspa?threadID=49624
https://jalbum.net/forum/thread.jspa?threadID=49608
Legend
Forum admins
Helpful Answer
Correct Answer

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