Thumbnailator - a thumbnail generation library for Java

Overview

March 11, 2021: Thumbnailator 0.4.14 has been released! See Changes for details.

Thumbnailator is now available through Maven!

What is Thumbnailator?

Thumbnailator is a thumbnail generation library for Java.

Why Thumbnailator?

Making high-quality thumbnails in Java can be a fairly difficult task.

Learning how to use the Image I/O API, Java 2D API, image processing, image scaling techniques, ... but fear not! Thumbnailator will take care of all those things for you!

Thumbnailator is a single JAR file with no dependencies to external libraries, making development and deployment simple and easy. It is also available on the Maven Central Repository for easy inclusion in Maven projects.

How simple is Thumbnailator?

Thumbnailator's fluent interface can be used to perform fairly complicated thumbnail processing task in one simple step.

For example, creating JPEG thumbnails of image files in a directory, all resized to a maximum dimension of 640 pixels by 480 pixels while preserving the aspect ratio of the original image can be performed by the following:

Thumbnails.of(new File("path/to/directory").listFiles())
    .size(640, 480)
    .outputFormat("jpg")
    .toFiles(Rename.PREFIX_DOT_THUMBNAIL);

The fluent interface provided by the Thumbnailator simplifies the task of making thumbnails into a single method call!

No need to access the Image I/O API and manually manipulate BufferedImages through Graphics2D objects. Thumbnailator does all of that for you.

What can Thumbnailator do?

The following pages have more information on what Thumbnailator can do:

Disclaimer

Thumbnailator is still early in its development, and the APIs are subject to change at any time.

License

Thumbnailtor is released under the MIT License.

Comments
  • Resize only if larger

    Resize only if larger

    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

    Type-Enhancement auto-migrated Priority-Low 
    opened by GoogleCodeExporter 16
  • Implement a workaround for common OutOfMemoryError cases

    Implement a workaround for common OutOfMemoryError cases

    There have been increasing number of reports of `OutOfMemoryError`s occurring 
    when using Thumbnailator. (Issue 1)
    
    In many cases, this is a result of trying to resize large input images, which 
    causes Thumbnailator to read the entire image to the JVM heap memory, resulting 
    in the `OutOfMemoryError`s due to the heap being filled up.
    
    A permanent fix to the problem is better achieved by changing the Thumbnailator 
    architecture to not require loading the entire image to memory before resizing 
    the image, but this will require a comprehensive rewrite, which is planned for 
    a later release.
    
    To address the `OutOfMemoryError` in a more timely manner, a temporary 
    workaround should be possible by examining the image metadata to find out the 
    image size, and accordingly apply a subsampling on the read operation to reduce 
    the amount of memory used when reading the image.
    

    Original issue reported on code.google.com by [email protected] on 4 May 2014 at 5:36

    auto-migrated Priority-High Type-Defect Milestone-0.4.8 
    opened by GoogleCodeExporter 15
  • Writing resized image issue on tomcat

    Writing resized image issue on tomcat

    What steps will reproduce the problem?
    1. Start Tomcat and Read source file at %tomcat%/bin/test_image.jpg
    2. Read source image and Create resized image by 
    Thumbnails.of("test_image.jpg").size(width, height).toFile("test_target.jpg");
    3. Console print out following error message and target image created 0 byte.
    
    What is the expected output? What do you see instead?
    2012-05-22 10:21:36,328 ERROR [http-8080-3] taglibs.ImageTag  
    (ImageTag.java:223)     - java.io.IOException: Could not open output file.
    java.io.IOException: Could not open output file.
        at net.coobird.thumbnailator.tasks.io.FileImageSink.write(Unknown Source)
        at net.coobird.thumbnailator.tasks.SourceSinkThumbnailTask.write(Unknown Source)
        at net.coobird.thumbnailator.Thumbnailator.createThumbnail(Unknown Source)
        at net.coobird.thumbnailator.Thumbnails$Builder.toFile(Unknown Source)
    
    
    What version of the product are you using? On what operating system? Which
    version of Java (Sun/Oracle? OpenJDK?) ?
    Thumbnailator 0.4.2
    Windows XP
    JDK 1.6 (Oracle)
    
    
    Please provide any additional information below.
    
    I tested this code with junit test module. But result of test was success. See 
    following code 
    
    BufferedImage image = Thumbnails.of(srcFile).size(width, 
    height).asBufferedImage();
    ImageIO.write(image, FilenameUtils.getExtension(targetPath), targetFile);
    
    This code run on tomcat was success.  
    
    
    I suggest that the message you rewrited in FileImageSink.write() will be change 
    by original message. 
    

    Original issue reported on code.google.com by [email protected] on 22 May 2012 at 2:18

    Attachments:

    Priority-Medium auto-migrated Type-Defect Milestone-0.4.3 
    opened by GoogleCodeExporter 15
  • Today, thumbnailator doesn't permit to create a thumbnail keeping aspect ratio AND forcing a defined size

    Today, thumbnailator doesn't permit to create a thumbnail keeping aspect ratio AND forcing a defined size

    I need to create thumbnails similar to the Facebook ones. What Facebook do is 
    maintain the aspect ratio, but forcing a defined size of thumbnail.
    
    It resizes the image to the defined size and then cuts what is left, forcing 
    the height or the width (and avoiding blank spaces around the image). For me is 
    the best approach when we talk about thumbnails.
    
    I tried to use something like this:
    
    Thumbnails.of(myInputStream).forceSize(width, 
    height).keepAspectRatio(true).outputFormat("jpg").outputQuality(1.0f).toOutputSt
    ream(myOutputStream);
    
    But it does not work. I think this approach is not possible yet with 
    thumbnailator so can you implement it? Just a suggestion to make this library 
    even better (it is definately the best and simplest all over the web).
    
    Thanks in advance.
    

    Original issue reported on code.google.com by [email protected] on 13 Oct 2011 at 8:06

    Priority-Medium Type-Enhancement auto-migrated Milestone-0.4.0 
    opened by GoogleCodeExporter 15
  • OutOfMemoryErrors (memory leak) when using latest versions of Java 6 and 7

    OutOfMemoryErrors (memory leak) when using latest versions of Java 6 and 7

    What steps will reproduce the problem?
    1. Unzip the attached maven project
    2. cd thumbnailator-test
    3. mvn test 
    
    Maven runs the test with -Xms256m -Xmx256m. It resizes a png file 100 times, 
    then resizes a jpg around 40 times before throwing an OOME. You can also build 
    and run an executable jar with 
    mvn -DskipTests=true package
    java -Xms256m -Xmx256m -jar target/jpegleaker.jar
    
    This fails on Ubuntu, java-version
    java version "1.7.0_21"
    Java(TM) SE Runtime Environment (build 1.7.0_21-b11)
    Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)
    
    This works on Ubuntu java -version
    java version "1.7.0_17"
    Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
    Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)
    
    
    
    

    Original issue reported on code.google.com by [email protected] on 16 May 2013 at 12:58

    Attachments:

    auto-migrated Type-Defect Milestone-0.4.4 Priority-Critical 
    opened by GoogleCodeExporter 14
  • ExifUtil.getExifOrientation does not work for images containing other exif data alongwith Orientation

    ExifUtil.getExifOrientation does not work for images containing other exif data alongwith Orientation

    314

    Expected behavior

    Give orientation for all the images with whatever exif data being present

    Actual behavior

    Currently it accepts only the images which contains EXIF data of orientation alone. It gives exception javax.imageio.IIOException: JFIF APP0 must be first marker after SOI at com.sun.imageio.plugins.jpeg.JPEGMetadata.(Unknown Source) at com.sun.imageio.plugins.jpeg.JPEGImageReader.getImageMetadata(Unknown Source) at net.coobird.thumbnailator.util.exif.ExifUtils.getExifOrientation(Unknown Source) at com.abk.ImageAutoRotate.main(ImageAutoRotate.java:24)

    Steps to reproduce the behavior

    Use any images taken using a mobile phone and you will face issues Attached the image for which it gives exception

    Environment

    JDK 8

    • OS vendor and version:Windows 7
    • JDK vendor and version: JDK 8 - Downloaded from Oracle.com
    • Thumbnailator version: 0.4.8
    bug 
    opened by datsabk 13
  • Add to the Maven Central Repository

    Add to the Maven Central Repository

    Thumbnailator should be available from the Maven Central Repository.
    
    There appears to be projects using Thumbnailator which are using Maven for 
    their build management.
    
    Therefore, it would be beneficial to users of Thumbnailator using Maven, if 
    adding a dependency didn't require adding the library in a local or internal 
    repository.
    
    Information on adding to the Central Repo can be found here:
    http://maven.apache.org/repository/index.html
    

    Original issue reported on code.google.com by [email protected] on 3 Apr 2011 at 11:25

    Priority-Medium auto-migrated Milestone-0.4.x Type-Task 
    opened by GoogleCodeExporter 13
  • Caption Image Distortion

    Caption Image Distortion

    I used caption for adding some text to the image which resulted in distortion 
    in image as well as added text seems to have some additional pixels around it. 
    It can be seen in the attachment here.
    

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

    Attachments:

    Priority-Medium auto-migrated Type-Other 
    opened by GoogleCodeExporter 11
  • Use rotation information in EXIF

    Use rotation information in EXIF

    Problem
    -------
    * Currently, Thumbnailator does not recognize information in JPEG EXIFs, which 
    can lead to photographs taken in portrait mode to be resized in landscape mode.
    
    
    Solution
    --------
    * Read the EXIF metadata present in JPEG files
    * If the EXIF metadata indicates that the image is in portrait mode, then 
    perform a rotation ahead of the thumbnail generation.
    
    
    Complications
    -------------
    * The behavior for handling portrait-oriented JPEGs in Thumbnailator will 
    change after the introduction of this feature.
    

    Original issue reported on code.google.com by [email protected] on 19 Jun 2011 at 2:35

    Priority-Medium Type-Enhancement auto-migrated Milestone-0.4.3 
    opened by GoogleCodeExporter 10
  • Images are larger in JDK 11

    Images are larger in JDK 11

    Expected behavior

    We upgraded our Project to JDK 11 and the thumbnail is getting created of size greater than the original image. Could you please let me know, is there any plan for JDK 11 support?

    Actual behavior

    Please describe the actual behavior you are experiencing, including stack trace and other information which would help diagnose the issue.

    Steps to reproduce the behavior

    Please enter step-by-step instructions for reproducing the actual behavior. Including code can be helpful in diagnosing issue, but please keep the code to a minimal that will reproduce the behavior.

    Environment

    Please provide vendor and version information for the Operating System, JDK, and Thumbnailator. Please feel free to add any other information which may be pertinent.

    • OS vendor and version:
    • JDK vendor and version:
    • Thumbnailator version:
    opened by bagavathi-er 9
  • Independently specify the scaling factors for width and height

    Independently specify the scaling factors for width and height

    Per request from a user, add a new `scale` method overload to specify the 
    scaling factor of the width and height independently, i.e.
    
      Thumbnails.of("path/to/image")
        .scale(0.6, 0.4)
        .toFile("path/to/thumbnail");
    
    In the above code, the width will be scaled by 0.6 times, and height will be 
    scaled by 0.4 times.
    
    For example, a source image with dimensions 100 x 100 will result in a 
    thumbnail that is 60 x 40. (The resulting image will not maintain the aspect 
    ratio of the original.)
    
    
    Background
    ---------------
    
    Currently, rescaling an image by a scaling factor will maintain the aspect 
    ratio of the width and height.
    
      Thumbnails.of("path/to/image")
        .scale(0.5)
        .toFile("path/to/thumbnail");
    
    In the above code, if the source image is 100 x 100, the resulting image will 
    be 50 x 50.
    
    If one wants to rescale the width to 0.5 and height to 0.6, there is no simple 
    one-liner that can be performed with Thumbnailator -- one would have to 
    calculate the thumbnail size for each source image, and use one of the `size` 
    methods to specify the final image size.
    
    
    API Design Consideration
    -------------------------
    
    This new `scale` method will not maintain the aspect ratio of the original 
    image unless the scaling factor for the width and height are equal. Therefore, 
    unless the two factors are equal, calling the `keepAspectRatio` method should 
    result in an `IllegalStateException`.
    

    Original issue reported on code.google.com by [email protected] on 13 Aug 2011 at 3:22

    Priority-Medium Type-Enhancement auto-migrated Milestone-0.3.10 
    opened by GoogleCodeExporter 9
  • Image color loss during conversion

    Image color loss during conversion

    Expected behavior

    Please describe what you are expecting the library to perform. The image does not lose color during conversion.

    Actual behavior

    Hello! I'm using the thumbnailator library to compress and convert customers images to png (to default size 200x200). One user came in with an image that was losing color (black gets lighter). Perhaps the error is due to the fact that the original image was 16 BitsPerPixel - the result is 32 BitsPerPixel. Perhaps I'm not using the library correctly. Help me to understand.

    Steps to reproduce the behavior

    My code:

        public static final Blob convertResizeImage(BufferedImage image, String formatName/*PNG*/, int targetWidth/*200*/, int targetHeight/*200*/) throws SQLException, IOException, InstantiationException, IllegalAccessException {
            int imgType = image.getType();
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            Thumbnails.of(image)
                    .size(targetWidth, targetHeight)
                    .outputFormat(formatName)
                    .imageType(imgType)
                    .outputQuality(1)
                    .toOutputStream(outputStream);
            byte[] data = outputStream.toByteArray();
            return bytes2Blob(data);
        }
    

    Source image: source

    Converted image: destination

    Environment

    • OS vendor and version: Windows 10
    • JDK vendor and version: Corretto 1.8
    • Thumbnailator version: 0.4.18
    opened by aleksanderFox 3
  • Jigsaw modules support

    Jigsaw modules support

    Hello, I'd like to use this library in one of my projects, though I noticed that it doesn't provide a module info. I was going to add one myself and create a PR, but as soon as I pulled the repo I noticed that the minimum version supported is Java 5. I'd still like to implement this feature and get it merged, so, if it's something that can be useful for the library, should I bump the minimum version to Java 11 or resort to some magic using moditect's plugin?

    enhancement breaking-change 
    opened by Auties00 4
  • Expose metrics for internal processes

    Expose metrics for internal processes

    Thumbnailator has several internal processes in a course of a single thumbnail operation: reading the image, resizing the image, applying filters and writing the image. Currently, there is no way to find out how much time is spent on each of these processes. Furthermore, there may be other metrics that would be interesting to keep track of, or obtain for debugging purposes.

    enhancement 
    opened by coobird 0
  • Require explicitly setting image type when outputting to BufferedImage(s)

    Require explicitly setting image type when outputting to BufferedImage(s)

    Currently, Thumbnailator does not require setting the BufferedImage type and will (attempt to) use the types as the input source. (More specifically, the image type that is used by the Image I/O ImageReader implementation used for the image.) This means that the type can differ depending on the image type or the image itself.

    By requiring the output type to be a certain type, the inconsistencies can be eliminated and also could avoid issues like "wrong colors in JPEG" issue that stems from handing a BufferedImage with an alpha channel to the default JPEG writer shipped with Java.

    Also consider limiting the use of imageType method to only use with methods that output BufferedImage(s) like asBufferedImage.

    breaking-change 
    opened by coobird 0
  • Option to ignore errors during bulk processing

    Option to ignore errors during bulk processing

    Currently, bulk processing like toFiles will halt as soon as any errors occur, such as file not existing. An option to ignore such errors (with a callback to provide which inputs failed) would be useful to continue processing input files in cases where it makes sense to continue processing the rest of the input.

    Maybe a mutually exclusive to #188.

    enhancement 
    opened by coobird 0
Owner
Chris Kroells
Chris Kroells
ZXing ("Zebra Crossing") barcode scanning library for Java, Android

Project in Maintenance Mode Only The project is in maintenance mode, meaning, changes are driven by contributed patches. Only bug fixes and minor enha

ZXing Project 30.5k Jan 4, 2023
Roman Beskrovnyi 250 Jan 9, 2023
Java library for remapper JARs

Pocolifo's JAR Remapper Making remapping JARs easy, organized, and painless Features Remapping Class remapping Method remapping Field remapping Parame

null 8 Oct 2, 2022
A Java Visualization Library based on Apache ECharts.

ECharts Java "We bring better visualization into Java with ECharts" ?? Introduction ECharts Java is a lightweight but comprehensive library for Java d

ECharts Java Open Source Project 171 Dec 31, 2022
Fast computer vision library for SFM, calibration, fiducials, tracking, image processing, and more.

Table of Contents Introduction Cloning Repository Quick Start Gradle and Maven Building from Source Dependencies Help/Contact Introduction BoofCV is a

Peter Abeles 916 Jan 6, 2023
Java interface to OpenCV, FFmpeg, and more

JavaCV Commercial support: Introduction JavaCV uses wrappers from the JavaCPP Presets of commonly used libraries by researchers in the field of comput

Bytedeco 6.4k Jan 4, 2023
Java JNA wrapper for Tesseract OCR API

Tess4J A Java JNA wrapper for Tesseract OCR API. Tess4J is released and distributed under the Apache License, v2.0. Features The library provides opti

Quan Nguyen 1.3k Dec 28, 2022
TwelveMonkeys ImageIO: Additional plug-ins and extensions for Java's ImageIO

About TwelveMonkeys ImageIO is a collection of plugins and extensions for Java's ImageIO. These plugins extend the number of image file formats suppor

Harald Kuhr 1.6k Jan 5, 2023
Creates ASCII art in Java from Images

Creates ASCII art in Java from Images. It can also save the ASCII art as image (.png) as well

Navjot Singh Rakhra 4 Jul 12, 2022
OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)

OpenAPI Generator Master (5.4.x): 6.0.x (6.0.x): ⭐ ⭐ ⭐ If you would like to contribute, please refer to guidelines and a list of open tasks. ⭐ ⭐ ⭐ ‼️

OpenAPI Tools 14.8k Dec 30, 2022
cglib - Byte Code Generation Library is high level API to generate and transform Java byte code. It is used by AOP, testing, data access frameworks to generate dynamic proxy objects and intercept field access.

cglib Byte Code Generation Library is high level API to generate and transform JAVA byte code. It is used by AOP, testing, data access frameworks to g

Code Generation Library 4.5k Jan 8, 2023
AllPairs4J - an open source Java library for generation of minimal set of test combinations

AllPairs4J AllPairs4J is an open source Java library for generation of minimal set of test combinations. AllPairs4J is a Java port of allpairspy proje

Pavel Nazimok 5 Dec 11, 2022
ORM16 is a library exploring code generation-based approach to ORM for Java 17 and focusing on records as persistent data model

About ORM16 ORM16 is a library exploring code generation-based approach to ORM for Java 17 and focusing on records as persistent data model. Example I

Ivan Gammel 1 Mar 30, 2022
sql2o is a small library, which makes it easy to convert the result of your sql-statements into objects. No resultset hacking required. Kind of like an orm, but without the sql-generation capabilities. Supports named parameters.

sql2o Sql2o is a small java library, with the purpose of making database interaction easy. When fetching data from the database, the ResultSet will au

Lars Aaberg 1.1k Dec 28, 2022
The Next Generation Logic Library

Introduction LogicNG is a Java Library for creating, manipulating and solving Boolean and Pseudo-Boolean formulas. It includes 100% Java implementatio

LogicNG 103 Nov 19, 2022
Automatic generation of the Builder pattern for Java

FreeBuilder Automatic generation of the Builder pattern for Java 1.8+ The Builder pattern is a good choice when designing classes whose constructors o

inferred.org 797 Dec 19, 2022
Java Code Generation Framework

Java::Geci Read "how to contribute". Java::Geci is a library for generating Java code. You can execute code generation programs using Java::Geci to ge

Peter Verhas 113 Dec 4, 2022
Runtime code generation for the Java virtual machine.

Byte Buddy runtime code generation for the Java virtual machine Byte Buddy is a code generation and manipulation library for creating and modifying Ja

Rafael Winterhalter 5.3k Dec 27, 2022