Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resize only if larger #11

Closed
GoogleCodeExporter opened this issue Jul 25, 2015 · 16 comments
Closed

Resize only if larger #11

GoogleCodeExporter opened this issue Jul 25, 2015 · 16 comments

Comments

@GoogleCodeExporter
Copy link

Would it be possible to add an option to performs the a resize command only if 
the original file is larger than the dimensions specified. i.e. similar to the 
ImageMagick / GraphicsMagick angle bracket use, e.g.

-size '200x200>'

Original issue reported on code.google.com by [email protected] on 14 May 2011 at 8:57

@GoogleCodeExporter
Copy link
Author

As a workaround, I've used this:


                        BufferedImage originalImage = ImageIO.read(selectedFile);
                        int height = originalImage.getHeight();
                        int width = originalImage.getWidth();
                        // Conditional resize
                        if ((height > 500) || (width > 500)) {
                            Thumbnails.of(selectedFile).size(500, 500).toFile(thumb500File);
                        } else {
                            FileUtils.copyFile(selectedFile, thumb500File);
                        }

Original comment by [email protected] on 14 May 2011 at 12:09

@GoogleCodeExporter
Copy link
Author

Thank you for taking the time to file an issue and posting a workaround.

Currently, the back-end of Thumbnailator is undergoing design changes which 
would allow for such a feature.
The changes are due to be part of the Thumbnailator 0.4.0 release, which I hope 
to get out in a week or so.

The actual API might be something along the line of the following:

  // Option 1
  // Simply specifying the minimum dimensions
  // *Actual method names are subject to further consideration
  Thumbnails.of("path/to/image")
    .size(200, 200)
    .onlyIfLargerThan(200, 200)
    .toFile("path/to/thumbnail")

  // Option 2
  // Building an expression to when to perform the resize.
  // This would be more verbose, but could allow more flexible expressions for
  // specifying when the resize should be performed.
  // *Actual method names are subject to further consideration
  Thumbnails.of("path/to/image")
    .size(200, 200)
    .onlyIf(Condition.widthLargerThan(200), Condition.HeightLargerThan(200))
    .toFile("path/to/thumbnail")

I'd appreciate any input on other options and use cases for this issue.

I will be changing the ticket type to "Type-Enhancement" as this is a request 
for a feature enhancement.

----------------------------------------

Note:

ImageMagick command-line option for specifying conditional resizing is listed 
in the 
section titled "Image Geometry" in the following URL:

* http://www.imagemagick.org/script/command-line-processing.php

Original comment by [email protected] on 14 May 2011 at 1:05

  • Changed state: Accepted
  • Added labels: Type-Enhancement
  • Removed labels: Type-Defect

@GoogleCodeExporter
Copy link
Author

Original comment by [email protected] on 14 May 2011 at 1:05

@GoogleCodeExporter
Copy link
Author

Original comment by [email protected] on 22 May 2011 at 2:44

  • Changed state: Started

@GoogleCodeExporter
Copy link
Author

what if image size is smaller than the given thumbnail size. is there any way 
to convert  that image in thumbnail size without any distortion or is there any 
method for adding some background image around it and providing the same size 
image. 

Original comment by [email protected] on 11 Jun 2011 at 9:31

@GoogleCodeExporter
Copy link
Author

Original comment by [email protected] on 28 Aug 2011 at 3:34

  • Added labels: Milestone-0.4.0

@GoogleCodeExporter
Copy link
Author

I don't think .onlyIfLargerThan(200, 200) is necessary, a boolean value for 
onlyIfLargeThan is enough.

Original comment by [email protected] on 17 Oct 2011 at 8:24

@GoogleCodeExporter
Copy link
Author

Original comment by [email protected] on 5 Feb 2012 at 8:12

  • Added labels: Milestone-0.4.x
  • Removed labels: Milestone-0.4.0

@GoogleCodeExporter
Copy link
Author

hi, 

is this option implemented yet (the last msg here is from feb 2012) or should i 
use the workaround? 

sincerely

Original comment by [email protected] on 9 Dec 2013 at 1:36

@GoogleCodeExporter
Copy link
Author

This feature is not implemented yet, and no real work has been performed on 
this for the past couple of years.

So, at the moment, the workaround is the only option.

If you have any input about how this function should be implemented (in terms 
of the API, as seen in comment #2), I'd be more than glad to hear them!

-----

Note: I'm changing the status, priority, and milestone to better reflect the 
current status.

Original comment by [email protected] on 9 Dec 2013 at 1:44

  • Changed state: Accepted
  • Added labels: Priority-Low
  • Removed labels: Milestone-0.4.x, Priority-Medium

@GoogleCodeExporter
Copy link
Author

Hi,

if I want to get image's height and weight
the only way is:
final Thumbnails.Builder<File> src = Thumbnails.of(srcImage);
final BufferedImage bufferedImage = src.asBufferedImage();
System.out.println(bufferedImage.getHeight());
System.out.println(bufferedImage.getWidth());
?

:)

Original comment by [email protected] on 17 Jan 2014 at 5:42

@GoogleCodeExporter
Copy link
Author

Oops, ran my code got one exception:
Exception in thread "main" java.lang.IllegalStateException: size is not set.
    at net.coobird.thumbnailator.Thumbnails$Builder.checkReadiness(Unknown Source)
    at net.coobird.thumbnailator.Thumbnails$Builder.asBufferedImage(Unknown Source)

seems I should call size method first

how can I resize image strategy?
I want to get original image's height and weight and compare with limit
and then resize the image

e.g., original image size is 200 * 400, max weight is 100
so the thumbnail size is 100 * 200

Original comment by [email protected] on 17 Jan 2014 at 6:06

@GoogleCodeExporter
Copy link
Author

Sorry for the wrong word 'weight' :)
it should be 'width'

Original comment by [email protected] on 17 Jan 2014 at 6:09

@GoogleCodeExporter
Copy link
Author

[deleted comment]

@GoogleCodeExporter
Copy link
Author

Thumbnails.of(srcFile).width(maxWidth).toFiles(Rename.PREFIX_DOT_THUMBNAIL);
resolve the problem

Thanks for providing such awesome tool

Original comment by [email protected] on 17 Jan 2014 at 6:13

@coobird
Copy link
Owner

coobird commented May 31, 2020

Supersede with #152.
(The automatically imported issues are a little hard to read..)

@coobird coobird closed this as completed May 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants