GithubHelp home page GithubHelp logo

Resize only if larger about thumbnailator HOT 15 OPEN

gigazhang avatar gigazhang commented on May 21, 2024
Resize only if larger

from thumbnailator.

Comments (15)

GoogleCodeExporter avatar GoogleCodeExporter commented on May 21, 2024
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

from thumbnailator.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 21, 2024
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

from thumbnailator.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 21, 2024

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

from thumbnailator.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 21, 2024

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

  • Changed state: Started

from thumbnailator.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 21, 2024
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

from thumbnailator.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 21, 2024

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

  • Added labels: Milestone-0.4.0

from thumbnailator.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 21, 2024
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

from thumbnailator.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 21, 2024

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

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

from thumbnailator.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 21, 2024
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

from thumbnailator.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 21, 2024
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

from thumbnailator.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 21, 2024
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

from thumbnailator.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 21, 2024
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

from thumbnailator.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 21, 2024
Sorry for the wrong word 'weight' :)
it should be 'width'

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

from thumbnailator.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 21, 2024
[deleted comment]

from thumbnailator.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 21, 2024
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

from thumbnailator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.