ghosta3 / thumbnailator

Automatically exported from code.google.com/p/thumbnailator
Other
0 stars 0 forks source link

Resize only if larger #11

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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 oliver.k...@gmail.com on 14 May 2011 at 8:57

GoogleCodeExporter commented 9 years ago
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 oliver.k...@gmail.com on 14 May 2011 at 12:09

GoogleCodeExporter commented 9 years ago
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 coobird...@gmail.com on 14 May 2011 at 1:05

GoogleCodeExporter commented 9 years ago

Original comment by coobird...@gmail.com on 14 May 2011 at 1:05

GoogleCodeExporter commented 9 years ago

Original comment by coobird...@gmail.com on 22 May 2011 at 2:44

GoogleCodeExporter commented 9 years ago
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 prakashJ...@gmail.com on 11 Jun 2011 at 9:31

GoogleCodeExporter commented 9 years ago

Original comment by coobird...@gmail.com on 28 Aug 2011 at 3:34

GoogleCodeExporter commented 9 years ago
I don't think .onlyIfLargerThan(200, 200) is necessary, a boolean value for 
onlyIfLargeThan is enough.

Original comment by tastypin...@gmail.com on 17 Oct 2011 at 8:24

GoogleCodeExporter commented 9 years ago

Original comment by coobird...@gmail.com on 5 Feb 2012 at 8:12

GoogleCodeExporter commented 9 years ago
hi, 

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

sincerely

Original comment by mail.mar...@gmail.com on 9 Dec 2013 at 1:36

GoogleCodeExporter commented 9 years ago
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 coobird...@gmail.com on 9 Dec 2013 at 1:44

GoogleCodeExporter commented 9 years ago
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 song...@gmail.com on 17 Jan 2014 at 5:42

GoogleCodeExporter commented 9 years ago
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 song...@gmail.com on 17 Jan 2014 at 6:06

GoogleCodeExporter commented 9 years ago
Sorry for the wrong word 'weight' :)
it should be 'width'

Original comment by song...@gmail.com on 17 Jan 2014 at 6:09

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Thumbnails.of(srcFile).width(maxWidth).toFiles(Rename.PREFIX_DOT_THUMBNAIL);
resolve the problem

Thanks for providing such awesome tool

Original comment by song...@gmail.com on 17 Jan 2014 at 6:13