Open GoogleCodeExporter opened 9 years ago
Thank you for the feedback.
There definitely should be more documentation for Thumbnailator, especially
when it comes to how to deal with certain use cases.
> 2. I will crop the image
If you want to specify a section of an image before creating a thumbnail, one
can use the `sourceRegion` method:
Thumbnails.of("path/to/image")
.sourceRegion(200, 200, Positions.CENTER)
.size(100, 100)
.toFile("path/to/thumbnail");
The above code will take the center 200x200 region, and resize it to a
thumbnail that is 100x100.
If what is desired is to merely crop an image, Thumbnailator does not provide a
direct way to do so, however there is a `Canvas` image filter which can perform
image cropping. (Please refer the javadocs at
http://thumbnailator.googlecode.com/hg/javadoc/net/coobird/thumbnailator/filters
/Canvas.html)
> 3. I will add empty area around to have exactly 100x100
The aforementioned `Canvas` image filter has a feature to forcefully make
thumbnails a certain size.
For example, say we take a 200x400 image and scale it down to 50x100, then we
want to have an empty area to make a 100x100 thumbnail. The code can be written
as follows:
Thumbnails.of("path/to/image-200x400")
.size(100, 100)
.addFilter(new Canvas(100, 100, Positions.CENTER))
.toFile("path/to/thumbnail");
Note: `size(100, 100)` will preserve the aspect ratio of the original, so the
thumbnail without the `Canvas` filter would be 50x100.
Please let me know if there's anything I missed or anything else I can help you
with.
Original comment by coobird...@gmail.com
on 29 Aug 2011 at 3:53
Thaks for your help.
I understand the point 3. and it seams good
but about the point 2. I want to take the maximum area as sourceRegion (because
my thumbnail should look like the original by the better way) and I dont know
the dimension of the original image.
Imagine I want a thumbnail of 100x100
if the original is 600*400 I want a sourceRegion of 400x400
if it is 200x800 I want 200x200
And without loading the image before to get its dimensions I don't see how to
do such a thing.
maybe a method like
.croppedSourceRegion(Positions.CENTER)
the true size of the sourceRegion will have to be calculated by using the ratio
height/width given by .size and the true size of the image when loaded.
I'm sad, not having time to look more into your code and propose a true solution
Original comment by brunopie...@gmail.com
on 30 Aug 2011 at 9:48
If I understand you correctly, perhaps having a way to specify the *minimum*
dimensions* that the thumbnail should be could help in your situation?
For example, let's say you want a thumbnail that is 100x100, and the original
image is 400x200.
If Thumbnailator could resize the image to have the *minimum dimensions* of
100x100, it should first resize the image to 200x100. Then, if the 100x100
thumbnail should be created by cropping the image, the `Canvas` filter could be
used to achieve that.
Hypothetically, the call could be like the following:
Thumbnails.of("path/to/image")
.minimumSize(100, 100)
.addFilter(new Canvas(100, 100, Positions.CENTER))
.toFile("path/to/thumbnail");
Original comment by coobird...@gmail.com
on 1 Sep 2011 at 3:47
Yes it would do the job.
If it was me, I would set direct methods to the 4 way simple way of
thumbnailing. But maybe good documentation about this may be enougth.
Thank again for your replies
Original comment by brunopie...@gmail.com
on 1 Sep 2011 at 4:15
*Note to self*
I'm going to add this as a note that Issue 24 seems to be a similar request to
the resizing strategy #2.
Maybe adding a `crop` method to handle a call to the `Canvas` filter would be a
better solution.
Original comment by coobird...@gmail.com
on 29 Oct 2011 at 3:36
The Thumbnailator project will move to GitHub due to Google Project Hosting
going read-only in one month.
http://google-opensource.blogspot.jp/2015/03/farewell-to-google-code.html
This issue has been migrated to GitHub at the following URL:
https://github.com/coobird/thumbnailator/issues/22
Original comment by coobird...@gmail.com
on 25 Jul 2015 at 11:38
Original issue reported on code.google.com by
brunopie...@gmail.com
on 29 Aug 2011 at 3:24