question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Resizing strategy

See original GitHub issue
I cannot use this lib which looks very good because of a missing functionnality 
: Resizing strategy.

I mean, that there is different way to generate a thumbnail, if I ask a 
thumbnail of 100x100
I'd like to choose if 
1. I will keep the ratio by fitting to the biggest dimension (but i will not 
have 100x100 result)
2. I will crop the image 
3. I will add empty area around to have exactly 100x100
4. I will not keep the ratio

As I have seen I can do 1. and 4. but I didn't see how to do 2. and/or 3.
If it exists, forgive me and please consider this as a documentation issue.

I'm sure I will use your lib later but without this functionnality I cannot in 
my current project and I'm going to code again some ugly code for resizing 
images

Original issue reported on code.google.com by brunopie...@gmail.com on 29 Aug 2011 at 3:24

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
GoogleCodeExportercommented, Jul 25, 2015
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

0reactions
GoogleCodeExportercommented, Jul 25, 2015
*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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resizing Arrays - math.oxford.emory.edu
Resizing Arrays. To eliminate the limitations of a fixed capacity stack, when there is no room left in the array when trying to...
Read more >
Array Resizing | Algorithms and Data Structures
Start with an appropriately capacity array,; Increase the array capacity when the array is full, and; Decrease the array capacity when the array...
Read more >
What is Resizing? - All About Images - Research Guides
Focuses on many common image questions in regards to image resolutions, resizing images, file types, vector and raster images, scanning, ...
Read more >
Leading a scaling business: Avoiding the pitfalls of reshaping ...
Ultimately, when scaling or resizing, businesses need a plan to get stuff done and need their people to make it happen… but it...
Read more >
Your Master Guide to Cropping and Resizing Images - BeFunky
Sometimes, knowing when to crop an image or resize it can be tricky – but it doesn't have to be. In this guide,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found