This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 3 - Pages: 1 - Last Post: 20 Apr 18, 09:18 Last Post By: davidekholm Threads: [ Previous | Next ]
JeffTucker

Posts: 8,039
Registered: 31-Jan-2006
Generating a fixed-shape image
Posted: 19 Apr 18, 22:50
 
  Click to reply to this thread Reply
Thrashing around in semi-familiar territory again. Let's say I've got thumbnail bounds of 1000x160 and image bounds of 1600x750, and I don't want to apply a fixed-shape filter to any of the generated thumbs or slides.

But I do want to generate a square 400x400 image for some other purpose.

(A bunch of misleading red herrings thrown back into the sea.)

Edited by: jGromit on 19-Apr-2018 18:55
JeffTucker

Posts: 8,039
Registered: 31-Jan-2006
Re: Generating a fixed-shape image
Posted: 19 Apr 18, 23:22   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
Belay all of that. It's CropFilter() that I want, and I'm closing in on how to wrangle it.
JeffTucker

Posts: 8,039
Registered: 31-Jan-2006
Re: Generating a fixed-shape image
Posted: 20 Apr 18, 00:28   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
OK. Leave me flopping around on the deck long enough, and I will get a result. This works nicely:
rif = currentObject.getRepresentingImageFile();
if(rif != null) {
	AlbumImage ai = new AlbumImage(rif, engine);
	minDim = Math.min(ai.getBufferedImage().getWidth(), ai.getBufferedImage().getHeight());
	JAFilter sq = new CropFilter();
	sq.setBounds(new Dimension(minDim, minDim));
	ai = ai.applyFilter(sq, new HashMap());
	ai = ai.scaleToFit(new Dimension(400,400));
	ai.saveImage(new File(outputDirectory, "folderthumb.jpg"));
}
David will probably pop up and show me what I'm doing the hard way, but at least this works.

This is for a square crop - to do something like a 3:2, you'd need to do a little math to get the setBounds() values. You need to crop the image to the desired aspect ratio before you scale the sucker, or you get very unpleasant results, and to do that, you need to know what its actual dimensions are.

And you might want to tinker with the setYWeight() and setXWeight() values on the filter. Lots of landmines with a mix of images.
davidekholm

Posts: 3,442
Registered: 18-Oct-2002
Re: Generating a fixed-shape image
Posted: 20 Apr 18, 09:18   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
No objections, but you should be able to simply call ai.applyFilter(sq); (i.e. leaving out new HashMap())
Legend
Forum admins
Helpful Answer
Correct Answer

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