├── .gitattributes ├── .github ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── LICENSE ├── README.md ├── pom.xml └── src ├── main ├── java │ └── net │ │ └── coobird │ │ └── thumbnailator │ │ ├── ThumbnailParameter.java │ │ ├── Thumbnailator.java │ │ ├── Thumbnails.java │ │ ├── builders │ │ ├── BufferedImageBuilder.java │ │ ├── ThumbnailParameterBuilder.java │ │ └── package-info.java │ │ ├── filters │ │ ├── Canvas.java │ │ ├── Caption.java │ │ ├── Colorize.java │ │ ├── Flip.java │ │ ├── ImageFilter.java │ │ ├── Pipeline.java │ │ ├── Rotation.java │ │ ├── SwapDimensions.java │ │ ├── Transparency.java │ │ ├── Watermark.java │ │ └── package-info.java │ │ ├── geometry │ │ ├── AbsoluteSize.java │ │ ├── Coordinate.java │ │ ├── Position.java │ │ ├── Positions.java │ │ ├── Region.java │ │ ├── RelativeSize.java │ │ ├── Size.java │ │ └── package-info.java │ │ ├── makers │ │ ├── FixedSizeThumbnailMaker.java │ │ ├── ScaledThumbnailMaker.java │ │ ├── ThumbnailMaker.java │ │ └── package-info.java │ │ ├── name │ │ ├── ConsecutivelyNumberedFilenames.java │ │ ├── Rename.java │ │ └── package-info.java │ │ ├── package-info.java │ │ ├── resizers │ │ ├── AbstractResizer.java │ │ ├── BicubicResizer.java │ │ ├── BilinearResizer.java │ │ ├── DefaultResizerFactory.java │ │ ├── FixedResizerFactory.java │ │ ├── NullResizer.java │ │ ├── ProgressiveBilinearResizer.java │ │ ├── Resizer.java │ │ ├── ResizerFactory.java │ │ ├── Resizers.java │ │ ├── configurations │ │ │ ├── AlphaInterpolation.java │ │ │ ├── Antialiasing.java │ │ │ ├── Dithering.java │ │ │ ├── Rendering.java │ │ │ ├── ResizerConfiguration.java │ │ │ ├── ScalingMode.java │ │ │ └── package-info.java │ │ └── package-info.java │ │ ├── tasks │ │ ├── FileThumbnailTask.java │ │ ├── SourceSinkThumbnailTask.java │ │ ├── StreamThumbnailTask.java │ │ ├── ThumbnailTask.java │ │ ├── UnsupportedFormatException.java │ │ ├── io │ │ │ ├── AbstractImageSink.java │ │ │ ├── AbstractImageSource.java │ │ │ ├── BufferedImageSink.java │ │ │ ├── BufferedImageSource.java │ │ │ ├── FileImageSink.java │ │ │ ├── FileImageSource.java │ │ │ ├── ImageSink.java │ │ │ ├── ImageSource.java │ │ │ ├── InputStreamImageSource.java │ │ │ ├── OutputStreamImageSink.java │ │ │ ├── URLImageSource.java │ │ │ └── package-info.java │ │ └── package-info.java │ │ └── util │ │ ├── BufferedImages.java │ │ ├── Configurations.java │ │ ├── ThumbnailatorUtils.java │ │ ├── exif │ │ ├── ExifFilterUtils.java │ │ ├── ExifUtils.java │ │ ├── IfdStructure.java │ │ ├── IfdType.java │ │ ├── Orientation.java │ │ └── package-info.java │ │ └── package-info.java └── resources │ └── META-INF │ └── LICENSE └── test ├── java └── net │ └── coobird │ └── thumbnailator │ ├── TestUtils.java │ ├── ThumbnailatorTest.java │ ├── ThumbnailatorTranscodeTest.java │ ├── ThumbnailatorUtilsTest.java │ ├── ThumbnailsBuilderInputOutputTest.java │ ├── ThumbnailsBuilderNullEmptyInputTest.java │ ├── ThumbnailsBuilderNullEmptyOutputTest.java │ ├── ThumbnailsBuilderTest.java │ ├── builders │ └── ThumbnailParameterBuilderTest.java │ ├── filters │ ├── CanvasTest.java │ ├── CaptionTest.java │ ├── ColorizeTest.java │ ├── FlipTest.java │ ├── ImageFilterTestUtils.java │ ├── PipelineTest.java │ ├── RotationTest.java │ ├── TransparencyTest.java │ └── WatermarkTest.java │ ├── makers │ ├── FixedSizeThumbnailMakerTest.java │ └── ScaledThumbnailMakerTest.java │ ├── name │ ├── ConsecutiveNumbersTest.java │ └── RenameTest.java │ ├── resizers │ ├── DefaultResizerFactoryTest.java │ ├── FixedResizerFactoryTest.java │ ├── NullResizerTest.java │ └── ProgressiveBilinearResizerTest.java │ ├── tasks │ ├── FileThumbnailTaskTest.java │ ├── SourceSinkThumbnailTaskTest.java │ ├── StreamThumbnailTaskTest.java │ └── io │ │ ├── BufferedImageSinkTest.java │ │ ├── BufferedImageSourceTest.java │ │ ├── FileImageSinkTest.java │ │ ├── FileImageSourceTest.java │ │ ├── InputStreamImageSourceMalformedTest.java │ │ ├── InputStreamImageSourceTest.java │ │ ├── Issue156OutputStreamImageSinkTest.java │ │ ├── Issue69FileImageSourceTest.java │ │ ├── Issue69InputStreamImageSourceTest.java │ │ ├── OutputStreamImageSinkTest.java │ │ └── URLImageSourceTest.java │ ├── test │ ├── BufferedImageAssert.java │ └── BufferedImageComparer.java │ └── util │ ├── ConfigurationsTest.java │ └── exif │ ├── ExifFilterUtilsTest.java │ ├── ExifUtilsTest.java │ └── ExifWorkaroundTest.java └── resources ├── Configurations ├── all_false.txt └── all_true.txt ├── Exif ├── fragments │ ├── README │ ├── app0.segment │ ├── exif.segment │ ├── rest │ ├── soi.segment │ └── xmp.segment ├── orientation_1.jpg ├── orientation_2.jpg ├── orientation_3.jpg ├── orientation_4.jpg ├── orientation_5.jpg ├── orientation_6.jpg ├── orientation_7.jpg ├── orientation_8.jpg ├── original.jpg ├── original.png ├── sourceTall_1.jpg ├── sourceTall_2.jpg ├── sourceTall_3.jpg ├── sourceTall_4.jpg ├── sourceTall_5.jpg ├── sourceTall_6.jpg ├── sourceTall_7.jpg ├── sourceTall_8.jpg ├── sourceWide_1.jpg ├── sourceWide_2.jpg ├── sourceWide_3.jpg ├── sourceWide_4.jpg ├── sourceWide_5.jpg ├── sourceWide_6.jpg ├── sourceWide_7.jpg ├── sourceWide_8.jpg ├── source_1.jpg ├── source_2.jpg ├── source_3.jpg ├── source_4.jpg ├── source_5.jpg ├── source_6.jpg ├── source_7.jpg ├── source_8.jpg └── stretch.png └── Thumbnailator ├── grid.bmp ├── grid.gif ├── grid.jpg ├── grid.png └── igrid.png /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Expected behavior 2 | _Please describe what you are expecting the library to perform._ 3 | 4 | 5 | 6 | ## Actual behavior 7 | _Please describe the actual behavior you are experiencing, including stack 8 | trace and other information which would help diagnose the issue._ 9 | 10 | 11 | 12 | ## Steps to reproduce the behavior 13 | _Please enter step-by-step instructions for reproducing the actual behavior. 14 | Including code can be helpful in diagnosing issue, but please keep the code to 15 | a minimal that will reproduce the behavior._ 16 | 17 | 18 | 19 | ## Environment 20 | _Please provide vendor and version information for the Operating System, 21 | JDK, and Thumbnailator. Please feel free to add any other information 22 | which may be pertinent._ 23 | 24 | - OS vendor and version: 25 | - JDK vendor and version: 26 | - Thumbnailator version: -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | **Hello! Thank you for your interest in contributing to Thumbnailator!** 2 | 3 | Unfortunately, I'm not accepting pull requests at this moment. 4 | 5 | Contributions in the form of bugs reports or feature enhancements through 6 | [issues](https://github.com/coobird/thumbnailator/issues) are appreciated. 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .classpath 2 | .project 3 | .settings 4 | .idea/ 5 | thumbnailator.iml 6 | bin/ 7 | target/ 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2008-2023 Chris Kroells 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | _*June 28, 2023: Thumbnailator 0.4.20 has been released! 2 | See [Changes](https://github.com/coobird/thumbnailator/wiki/Changes) for details.*_ 3 | 4 | _*Thumbnailator is now available through 5 | [Maven](https://github.com/coobird/thumbnailator/wiki/Maven)!*_ 6 | 7 | # What is Thumbnailator? 8 | 9 | ![](https://raw.githubusercontent.com/wiki/coobird/thumbnailator/img/home/home-image.png) 10 | 11 | _Thumbnailator_ is a thumbnail generation library for Java. 12 | 13 | # Why Thumbnailator? 14 | Making high-quality thumbnails in Java can be a fairly difficult task. 15 | 16 | Learning how to use the Image I/O API, Java 2D API, image processing, 17 | image scaling techniques, ... but fear not! _Thumbnailator_ will take care 18 | of all those things for you! 19 | 20 | Thumbnailator is a single JAR file with no dependencies to external libraries, 21 | making development and deployment simple and easy. It is also available on 22 | the Maven Central Repository for easy inclusion in Maven projects. 23 | 24 | # How simple is Thumbnailator? 25 | 26 | _Thumbnailator_'s fluent interface can be used to perform fairly complicated 27 | thumbnail processing task in one simple step. 28 | 29 | For example, creating JPEG thumbnails of image files in a directory, all 30 | resized to a maximum dimension of 640 pixels by 480 pixels while preserving 31 | the aspect ratio of the original image can be performed by the following: 32 | 33 | ``` 34 | Thumbnails.of(new File("path/to/directory").listFiles()) 35 | .size(640, 480) 36 | .outputFormat("jpg") 37 | .toFiles(Rename.PREFIX_DOT_THUMBNAIL); 38 | ``` 39 | 40 | The fluent interface provided by the _Thumbnailator_ simplifies the task of 41 | making thumbnails into a single method call! 42 | 43 | No need to access the Image I/O API and manually manipulate `BufferedImage`s 44 | through `Graphics2D` objects. _Thumbnailator_ does all of that for you. 45 | 46 | # What can Thumbnailator do? 47 | 48 | The following pages have more information on what _Thumbnailator_ can do: 49 | 50 | * [Features](https://github.com/coobird/thumbnailator/wiki/Features) 51 | * [Examples](https://github.com/coobird/thumbnailator/wiki/Examples) 52 | * [Thumbnailator API Documentation](https://coobird.github.io/thumbnailator/javadoc/0.4.20/) 53 | * [Frequently Asked Questions](https://github.com/coobird/thumbnailator/wiki/FAQ) 54 | 55 | # Disclaimer 56 | *Thumbnailator is still early in its development, and the APIs are subject to 57 | change at any time.* 58 | 59 | # License 60 | Thumbnailtor is released under the MIT License. 61 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/builders/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2022 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * This package provides classes which provides convenient builders for classes 27 | * which are used by Thumbnailator. These classes are used mostly for internal 28 | * processing. 29 | */ 30 | package net.coobird.thumbnailator.builders; 31 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/filters/Colorize.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.filters; 26 | 27 | import java.awt.Color; 28 | import java.awt.Graphics2D; 29 | import java.awt.image.BufferedImage; 30 | 31 | import net.coobird.thumbnailator.builders.BufferedImageBuilder; 32 | import net.coobird.thumbnailator.util.BufferedImages; 33 | 34 | /** 35 | * An image filter which will add a color tint to an image. 36 | * 37 | * @author coobird 38 | * 39 | */ 40 | public final class Colorize implements ImageFilter { 41 | /** 42 | * The color to tint a target image with. 43 | */ 44 | private final Color c; 45 | 46 | /** 47 | * Instantiates this filter with the color to use to tint the target image 48 | * with. 49 | *

50 | * Note: If the provided {@link Color} does not have an alpha channel 51 | * (transparency channel), then the target image will be painted with an 52 | * opaque color, resulting in an image with only the specified color. 53 | * 54 | * @param c Color to tint with. 55 | */ 56 | public Colorize(Color c) { 57 | this.c = c; 58 | } 59 | 60 | /** 61 | * Instantiates this filter with the color to use to tint the target image 62 | * with and the transparency level provided as a {@code float} ranging from 63 | * {@code 0.0f} to {@code 1.0f}, where {@code 0.0f} indicates completely 64 | * transparent, and {@code 1.0f} indicates completely opaque. 65 | * 66 | * @param c Color to tint with. 67 | * @param alpha The opacity of the tint. 68 | */ 69 | public Colorize(Color c, float alpha) { 70 | this(c, (int)(255 * alpha)); 71 | } 72 | 73 | /** 74 | * Instantiates this filter with the color to use to tint the target image 75 | * with and the transparency level provided as a {@code int} ranging from 76 | * {@code 0} to {@code 255}, where {@code 0} indicates completely 77 | * transparent, and {@code 255} indicates completely opaque. 78 | * 79 | * @param c Color to tint with. 80 | * @param alpha The opacity of the tint. 81 | */ 82 | public Colorize(Color c, int alpha) { 83 | if (alpha > 255 || alpha < 0) { 84 | throw new IllegalArgumentException( 85 | "Specified alpha value is outside the range of allowed " + 86 | "values."); 87 | } 88 | 89 | int r = c.getRed(); 90 | int g = c.getGreen(); 91 | int b = c.getBlue(); 92 | int a = alpha; 93 | 94 | this.c = new Color(r, g, b, a); 95 | } 96 | 97 | public BufferedImage apply(BufferedImage img) { 98 | int width = img.getWidth(); 99 | int height = img.getHeight(); 100 | 101 | BufferedImage newImage = new BufferedImageBuilder(width, height).build(); 102 | 103 | Graphics2D g = newImage.createGraphics(); 104 | g.drawImage(img, 0, 0, null); 105 | g.setColor(c); 106 | g.fillRect(0, 0, width, height); 107 | g.dispose(); 108 | 109 | if (img.getType() != newImage.getType()) { 110 | return BufferedImages.copy(newImage, img.getType()); 111 | } 112 | 113 | return newImage; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/filters/Flip.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.filters; 26 | 27 | import java.awt.Graphics; 28 | import java.awt.image.BufferedImage; 29 | 30 | import net.coobird.thumbnailator.builders.BufferedImageBuilder; 31 | 32 | /** 33 | * A class containing flip transformation filters. 34 | * 35 | * @author coobird 36 | * 37 | */ 38 | public class Flip { 39 | 40 | /** 41 | * An image filter which performs a horizontal flip of the image. 42 | */ 43 | public static final ImageFilter HORIZONTAL = new ImageFilter() { 44 | public BufferedImage apply(BufferedImage img) { 45 | int width = img.getWidth(); 46 | int height = img.getHeight(); 47 | 48 | BufferedImage newImage = 49 | new BufferedImageBuilder(width, height, img.getType()).build(); 50 | 51 | Graphics g = newImage.getGraphics(); 52 | g.drawImage(img, width, 0, 0, height, 0, 0, width, height, null); 53 | g.dispose(); 54 | 55 | return newImage; 56 | } 57 | }; 58 | 59 | /** 60 | * An image filter which performs a vertical flip of the image. 61 | */ 62 | public static final ImageFilter VERTICAL = new ImageFilter() { 63 | public BufferedImage apply(BufferedImage img) { 64 | int width = img.getWidth(); 65 | int height = img.getHeight(); 66 | 67 | BufferedImage newImage = 68 | new BufferedImageBuilder(width, height, img.getType()).build(); 69 | 70 | Graphics g = newImage.getGraphics(); 71 | g.drawImage(img, 0, height, width, 0, 0, 0, width, height, null); 72 | g.dispose(); 73 | 74 | return newImage; 75 | } 76 | }; 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/filters/ImageFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.filters; 26 | 27 | import java.awt.image.BufferedImage; 28 | 29 | /** 30 | * This interface is to be implemented by classes which performs an image 31 | * filtering operation on a {@link BufferedImage}. 32 | *

33 | * The general contract for classes implementing {@link ImageFilter} is that 34 | * they should not change the contents of the {@link BufferedImage} which is 35 | * given as the argument for the {@link #apply(BufferedImage)} method. 36 | *

37 | * The filter should make a copy of the given {@link BufferedImage}, and 38 | * perform the filtering operations on the copy, then return the copy. 39 | * 40 | * @author coobird 41 | * 42 | */ 43 | public interface ImageFilter { 44 | /** 45 | * Applies a image filtering operation on an image. 46 | * 47 | * @param img The image to apply the filtering on. 48 | * @return The resulting image after applying this filter. 49 | */ 50 | public BufferedImage apply(BufferedImage img); 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/filters/Pipeline.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.filters; 26 | 27 | import java.awt.image.BufferedImage; 28 | import java.util.ArrayList; 29 | import java.util.Arrays; 30 | import java.util.Collections; 31 | import java.util.List; 32 | 33 | import net.coobird.thumbnailator.util.BufferedImages; 34 | 35 | /** 36 | * An {@link ImageFilter} which will apply multiple {@link ImageFilter}s in a 37 | * specific order. 38 | * 39 | * @author coobird 40 | * 41 | */ 42 | public final class Pipeline implements ImageFilter { 43 | /** 44 | * A list of image filters to apply. 45 | */ 46 | private final List filtersToApply; 47 | 48 | /** 49 | * An unmodifiable list of image filters to apply. 50 | * Used by the {@link #getFilters()} method. 51 | * 52 | * This object is created by Collections.unmodifiableList which provides 53 | * an unmodifiable view of the original list. 54 | * 55 | * Therefore, any changes to the original list will also be "visible" from 56 | * this list as well. 57 | */ 58 | private final List unmodifiableFiltersToApply; 59 | 60 | /** 61 | * Instantiates a new {@link Pipeline} with no image filters to apply. 62 | */ 63 | public Pipeline() { 64 | this(Collections.emptyList()); 65 | } 66 | 67 | /** 68 | * Instantiates a new {@link Pipeline} with an array of {@link ImageFilter}s 69 | * to apply. 70 | * 71 | * @param filters An array of {@link ImageFilter}s to apply. 72 | */ 73 | public Pipeline(ImageFilter... filters) { 74 | this(Arrays.asList(filters)); 75 | } 76 | 77 | /** 78 | * Instantiates a new {@link Pipeline} with a list of {@link ImageFilter}s 79 | * to apply. 80 | * 81 | * @param filters A list of {@link ImageFilter}s to apply. 82 | */ 83 | public Pipeline(List filters) { 84 | if (filters == null) { 85 | throw new NullPointerException("Cannot instantiate with a null" + 86 | "list of image filters."); 87 | } 88 | 89 | filtersToApply = new ArrayList(filters); 90 | unmodifiableFiltersToApply = 91 | Collections.unmodifiableList(filtersToApply); 92 | } 93 | 94 | /** 95 | * Adds an {@code ImageFilter} to the pipeline. 96 | * 97 | * @param filter An {@code ImageFilter}. 98 | */ 99 | public void add(ImageFilter filter) { 100 | if (filter == null) { 101 | throw new NullPointerException("An image filter must not be null."); 102 | } 103 | 104 | filtersToApply.add(filter); 105 | } 106 | 107 | /** 108 | * Adds an {@code ImageFilter} to the beginning of the pipeline. 109 | * 110 | * @param filter An {@code ImageFilter}. 111 | */ 112 | public void addFirst(ImageFilter filter) { 113 | if (filter == null) { 114 | throw new NullPointerException("An image filter must not be null."); 115 | } 116 | 117 | filtersToApply.add(0, filter); 118 | } 119 | 120 | /** 121 | * Adds a {@code List} of {@code ImageFilter}s to the pipeline. 122 | * 123 | * @param filters A list of filters to add to the pipeline. 124 | */ 125 | public void addAll(List filters) { 126 | if (filters == null) { 127 | throw new NullPointerException("A list of image filters must not be null."); 128 | } 129 | 130 | filtersToApply.addAll(filters); 131 | } 132 | 133 | /** 134 | * Returns a list of {@link ImageFilter}s which will be applied by this 135 | * {@link Pipeline}. 136 | * 137 | * @return A list of filters which are applied by this 138 | * pipeline. 139 | */ 140 | public List getFilters() { 141 | return unmodifiableFiltersToApply; 142 | } 143 | 144 | public BufferedImage apply(BufferedImage img) { 145 | if (filtersToApply.isEmpty()) { 146 | return img; 147 | } 148 | 149 | BufferedImage image = BufferedImages.copy(img); 150 | 151 | for (ImageFilter filter : filtersToApply) { 152 | image = filter.apply(image); 153 | } 154 | 155 | return image; 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/filters/SwapDimensions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2022 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.filters; 26 | 27 | import java.awt.image.BufferedImage; 28 | 29 | /** 30 | * This is a no-op filter that acts as a "flag" to enable proper handling of 31 | * dimensions for images that will be oriented by using Exif metadata. 32 | *

33 | * This is an internal filter that should not be used by consumers of 34 | * Thumbnailator. 35 | */ 36 | public class SwapDimensions implements ImageFilter { 37 | private static final SwapDimensions INSTANCE = new SwapDimensions(); 38 | private SwapDimensions() {} 39 | 40 | public static SwapDimensions getInstance() { 41 | return INSTANCE; 42 | } 43 | 44 | public BufferedImage apply(BufferedImage img) { 45 | return img; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/filters/Transparency.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.filters; 26 | 27 | import net.coobird.thumbnailator.builders.BufferedImageBuilder; 28 | import net.coobird.thumbnailator.util.BufferedImages; 29 | 30 | import java.awt.AlphaComposite; 31 | import java.awt.Graphics2D; 32 | import java.awt.image.BufferedImage; 33 | 34 | /** 35 | * An image filter which will make an image transparent. 36 | *

37 | * The resulting image will always have an image type of 38 | * {@link BufferedImage#TYPE_INT_ARGB}. 39 | * 40 | * @author coobird 41 | * 42 | */ 43 | public class Transparency implements ImageFilter { 44 | /** 45 | * The alpha composite to use when drawing the transparent image. 46 | */ 47 | private final AlphaComposite composite; 48 | 49 | /** 50 | * Instantiates a {@link Transparency} filter with the specified opacity. 51 | * 52 | * @param alpha The opacity of the resulting image. The value should be 53 | * between {@code 0.0f} (transparent) to {@code 1.0f} 54 | * (opaque), inclusive. 55 | * @throws IllegalArgumentException If the specified opacity is outside of 56 | * the range specified above. 57 | */ 58 | public Transparency(float alpha) { 59 | super(); 60 | 61 | if (alpha < 0.0f || alpha > 1.0f) { 62 | throw new IllegalArgumentException( 63 | "The alpha must be between 0.0f and 1.0f, inclusive."); 64 | } 65 | 66 | this.composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha); 67 | } 68 | 69 | /** 70 | * Instantiates a {@link Transparency} filter with the specified opacity. 71 | *

72 | * This is a convenience constructor for the 73 | * {@link Transparency#Transparency(float)} constructor. 74 | * 75 | * @param alpha The opacity of the resulting image. The value should be 76 | * between {@code 0.0f} (transparent) to {@code 1.0f} 77 | * (opaque), inclusive. 78 | * @throws IllegalArgumentException If the specified opacity is outside of 79 | * the range specified above. 80 | */ 81 | public Transparency(double alpha) { 82 | this((float)alpha); 83 | } 84 | 85 | public BufferedImage apply(BufferedImage img) { 86 | int width = img.getWidth(); 87 | int height = img.getHeight(); 88 | 89 | BufferedImage finalImage = new BufferedImageBuilder( 90 | width, 91 | height, 92 | BufferedImage.TYPE_INT_ARGB 93 | ).build(); 94 | 95 | Graphics2D g = finalImage.createGraphics(); 96 | g.setComposite(composite); 97 | g.drawImage(img, 0, 0, null); 98 | g.dispose(); 99 | 100 | if (img.getType() != finalImage.getType()) { 101 | return BufferedImages.copy(finalImage, img.getType()); 102 | } 103 | 104 | return finalImage; 105 | } 106 | 107 | /** 108 | * Returns the opacity of this filter. 109 | * 110 | * @return The opacity in the range of {@code 0.0f} (transparent) to 111 | * {@code 1.0f} (opaque). 112 | */ 113 | public float getAlpha() { 114 | return composite.getAlpha(); 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/filters/Watermark.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.filters; 26 | 27 | import java.awt.AlphaComposite; 28 | import java.awt.Graphics2D; 29 | import java.awt.Point; 30 | import java.awt.image.BufferedImage; 31 | 32 | import net.coobird.thumbnailator.builders.BufferedImageBuilder; 33 | import net.coobird.thumbnailator.geometry.Position; 34 | 35 | /** 36 | * This class applies a watermark to an image. 37 | * 38 | * @author coobird 39 | * 40 | */ 41 | public class Watermark implements ImageFilter { 42 | /** 43 | * The position of the watermark. 44 | */ 45 | private final Position position; 46 | 47 | /** 48 | * The watermark image. 49 | */ 50 | private final BufferedImage watermarkImg; 51 | 52 | /** 53 | * The opacity of the watermark. 54 | */ 55 | private final float opacity; 56 | 57 | /** 58 | * The insets for the watermark. 59 | */ 60 | private final int insets; 61 | 62 | /** 63 | * Instantiates a filter which applies a watermark to an image. 64 | * 65 | * @param position The position of the watermark. 66 | * @param watermarkImg The watermark image. 67 | * @param opacity The opacity of the watermark. 68 | *

69 | * The value should be between {@code 0.0f} and 70 | * {@code 1.0f}, where {@code 0.0f} is completely 71 | * transparent, and {@code 1.0f} is completely 72 | * opaque. 73 | * @param insets Inset size around the watermark. 74 | * Cannot be negative. 75 | */ 76 | public Watermark(Position position, BufferedImage watermarkImg, float opacity, int insets) { 77 | if (position == null) { 78 | throw new NullPointerException("Position is null."); 79 | } 80 | if (watermarkImg == null) { 81 | throw new NullPointerException("Watermark image is null."); 82 | } 83 | if (opacity > 1.0f || opacity < 0.0f) { 84 | throw new IllegalArgumentException("Opacity is out of range of " + 85 | "between 0.0f and 1.0f."); 86 | } 87 | if (insets < 0) { 88 | throw new IllegalArgumentException("Insets cannot be negative."); 89 | } 90 | 91 | this.position = position; 92 | this.watermarkImg = watermarkImg; 93 | this.opacity = opacity; 94 | this.insets = insets; 95 | } 96 | 97 | /** 98 | * Instantiates a filter which applies a watermark to an image. 99 | * 100 | * @param position The position of the watermark. 101 | * @param watermarkImg The watermark image. 102 | * @param opacity The opacity of the watermark. 103 | *

104 | * The value should be between {@code 0.0f} and 105 | * {@code 1.0f}, where {@code 0.0f} is completely 106 | * transparent, and {@code 1.0f} is completely 107 | * opaque. 108 | */ 109 | public Watermark(Position position, BufferedImage watermarkImg, float opacity) { 110 | this(position, watermarkImg, opacity, 0); 111 | } 112 | 113 | public BufferedImage apply(BufferedImage img) { 114 | int width = img.getWidth(); 115 | int height = img.getHeight(); 116 | int type = img.getType(); 117 | 118 | BufferedImage imgWithWatermark = 119 | new BufferedImageBuilder(width, height, type).build(); 120 | 121 | int watermarkWidth = watermarkImg.getWidth(); 122 | int watermarkHeight = watermarkImg.getHeight(); 123 | 124 | Point p = position.calculate( 125 | width, height, watermarkWidth, watermarkHeight, 126 | insets, insets, insets, insets 127 | ); 128 | 129 | Graphics2D g = imgWithWatermark.createGraphics(); 130 | 131 | // Draw the actual image. 132 | g.drawImage(img, 0, 0, null); 133 | 134 | // Draw the watermark on top. 135 | g.setComposite( 136 | AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity) 137 | ); 138 | 139 | g.drawImage(watermarkImg, p.x, p.y, null); 140 | 141 | g.dispose(); 142 | 143 | return imgWithWatermark; 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/filters/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * This package provides classes which perform filtering operations on images, 27 | * such as adding watermark, text captions, and color tints. 28 | */ 29 | package net.coobird.thumbnailator.filters; 30 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/geometry/AbsoluteSize.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.geometry; 26 | 27 | import java.awt.Dimension; 28 | 29 | /** 30 | * A {@link Size} object which indicates that the size of the enclosed object 31 | * should be the specified absolute size. 32 | * 33 | * @author coobird 34 | * @since 0.3.4 35 | * 36 | */ 37 | public class AbsoluteSize implements Size { 38 | /** 39 | * The size of the object. 40 | */ 41 | private final Dimension size; 42 | 43 | /** 44 | * Instantiates an object which indicates size of an object. 45 | * 46 | * @param size Size of the enclosed object. 47 | * @throws NullPointerException If the size is {@code null}. 48 | */ 49 | public AbsoluteSize(Dimension size) { 50 | if (size == null) { 51 | throw new NullPointerException("Size cannot be null."); 52 | } 53 | this.size = new Dimension(size); 54 | } 55 | 56 | /** 57 | * Instantiates an object which indicates size of an object. 58 | * 59 | * @param width Width of the enclosed object. 60 | * @param height Height of the enclosed object. 61 | * @throws IllegalArgumentException If the width and/or height is less 62 | * than or equal to {@code 0}. 63 | */ 64 | public AbsoluteSize(int width, int height) { 65 | if (width <= 0 || height <= 0) { 66 | throw new IllegalArgumentException( 67 | "Width and height must be greater than 0." 68 | ); 69 | } 70 | this.size = new Dimension(width, height); 71 | } 72 | 73 | public Dimension calculate(int width, int height) { 74 | if (width <= 0 || height <= 0) { 75 | throw new IllegalArgumentException( 76 | "Width and height must be greater than 0." 77 | ); 78 | } 79 | return new Dimension(size); 80 | } 81 | 82 | /** 83 | * Returns a {@code String} representation of this object. 84 | * 85 | * @return {@code String} representation of this object. 86 | */ 87 | @Override 88 | public String toString() { 89 | return "AbsoluteSize [width=" + size.width + ", height=" + size.height + "]"; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/geometry/Coordinate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.geometry; 26 | 27 | import java.awt.Point; 28 | 29 | /** 30 | * This class calculates the position of an image which is to be enclosed, 31 | * using an absolute coordinate at which the image should be located. 32 | * 33 | * @author coobird 34 | * 35 | */ 36 | public final class Coordinate implements Position { 37 | /** 38 | * The horizontal position of the image to be enclosed. 39 | */ 40 | private final int x; 41 | 42 | /** 43 | * The vertical position of the image to be enclosed. 44 | */ 45 | private final int y; 46 | 47 | /** 48 | * Instantiates an object which calculates the position of an image, using 49 | * the given coordinates. 50 | * 51 | * @param x The horizontal component of the top-left corner of the 52 | * image to be enclosed. 53 | * @param y The vertical component of the top-left corner of the 54 | * image to be enclosed. 55 | */ 56 | public Coordinate(int x, int y) { 57 | this.x = x; 58 | this.y = y; 59 | } 60 | 61 | public Point calculate(int enclosingWidth, int enclosingHeight, int width, 62 | int height, int insetLeft, int insetRight, int insetTop, 63 | int insetBottom) { 64 | 65 | int x = this.x + insetLeft; 66 | int y = this.y + insetTop; 67 | 68 | return new Point(x, y); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/geometry/Position.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.geometry; 26 | 27 | import java.awt.Point; 28 | 29 | /** 30 | * This interface is implemented by classes which calculate how to position an 31 | * object inside of an enclosing object. 32 | * 33 | * @author coobird 34 | * 35 | */ 36 | public interface Position { 37 | /** 38 | * Calculates the position of an object enclosed by an enclosing object. 39 | * 40 | * @param enclosingWidth The width of the enclosing object that is 41 | * to contain the enclosed object. 42 | * @param enclosingHeight The height of the enclosing object that is 43 | * to contain the enclosed object. 44 | * @param width The width of the object that is to be 45 | * placed inside an enclosing object. 46 | * @param height The height of the object that is to be 47 | * placed inside an enclosing object. 48 | * @param insetLeft The inset on the left-hand side of the 49 | * object to be enclosed. 50 | * @param insetRight The inset on the right-hand side of the 51 | * object to be enclosed. 52 | * @param insetTop The inset on the top side of the 53 | * object to be enclosed. 54 | * @param insetBottom The inset on the bottom side of the 55 | * object to be enclosed. 56 | * @return The position to place the object. 57 | */ 58 | public Point calculate( 59 | int enclosingWidth, int enclosingHeight, int width, int height, 60 | int insetLeft, int insetRight, int insetTop, int insetBottom 61 | ); 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/geometry/Region.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2023 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.geometry; 26 | 27 | import java.awt.Dimension; 28 | import java.awt.Point; 29 | import java.awt.Rectangle; 30 | 31 | /** 32 | * A representation of a region, using a {@link Position} object and a 33 | * {@link Dimension} object. 34 | * 35 | * @author coobird 36 | * @since 0.3.4 37 | * 38 | */ 39 | public final class Region { 40 | /** 41 | * Position of the region. 42 | */ 43 | private final Position position; 44 | 45 | /** 46 | * Size of the region. 47 | */ 48 | private final Size size; 49 | 50 | /** 51 | * Instantiates a representation of a region from a {@link Position} and 52 | * {@link Size}. 53 | * 54 | * @param position Position of the region. 55 | * @param size Size of the region. 56 | * @throws NullPointerException When the position and/or the size is 57 | * {@code null}. 58 | */ 59 | public Region(Position position, Size size) { 60 | super(); 61 | if (position == null) { 62 | throw new NullPointerException("Position cannot be null."); 63 | } 64 | if (size == null) { 65 | throw new NullPointerException("Size cannot be null."); 66 | } 67 | 68 | this.position = position; 69 | this.size = size; 70 | } 71 | 72 | /** 73 | * Returns the position of the region. 74 | * 75 | * @return Position of the region. 76 | */ 77 | public Position getPosition() { 78 | return position; 79 | } 80 | 81 | /** 82 | * Returns the size of the region. 83 | * 84 | * @return Size of the region. 85 | */ 86 | public Size getSize() { 87 | return size; 88 | } 89 | 90 | /** 91 | * Calculates the position and size of the enclosed region, relative to the 92 | * enclosing region. 93 | *

94 | * The portions of the enclosed region which lies outside the enclosing 95 | * region are ignored. Effectively, the {@link Rectangle} returned by this 96 | * method is an intersection of the enclosing and enclose regions. 97 | * 98 | * @param outerWidth Width of the enclosing region. 99 | * @param outerHeight Height of the enclosing region. 100 | * @param flipHorizontal Whether enclosed region should flip 101 | * horizontally within the enclosing region. 102 | * @param flipVertical Whether enclosed region should flip 103 | * vertically within the enclosing region. 104 | * @param swapDimensions Whether the components of the point and 105 | * dimension of the enclosed region should be 106 | * swapped. 107 | * @return Position and size of the enclosed region. 108 | */ 109 | public Rectangle calculate( 110 | int outerWidth, 111 | int outerHeight, 112 | boolean flipHorizontal, 113 | boolean flipVertical, 114 | boolean swapDimensions 115 | ) { 116 | Dimension innerDimension = size.calculate(outerWidth, outerHeight); 117 | 118 | Point innerPoint = position.calculate( 119 | outerWidth, outerHeight, innerDimension.width, innerDimension.height, 0, 0, 0, 0 120 | ); 121 | 122 | if (swapDimensions) { 123 | innerDimension = new Dimension(innerDimension.height, innerDimension.width); 124 | innerPoint = new Point(innerPoint.y, innerPoint.x); 125 | } 126 | 127 | if (flipHorizontal) { 128 | int newX = outerWidth - innerPoint.x - innerDimension.width; 129 | innerPoint.setLocation(newX, innerPoint.y); 130 | } 131 | if (flipVertical) { 132 | int newY = outerHeight - innerPoint.y - innerDimension.height; 133 | innerPoint.setLocation(innerPoint.x, newY); 134 | } 135 | 136 | Rectangle outerRectangle = new Rectangle(0, 0, outerWidth, outerHeight); 137 | Rectangle innerRectangle = new Rectangle(innerPoint, innerDimension); 138 | 139 | return outerRectangle.intersection(innerRectangle); 140 | } 141 | 142 | /** 143 | * Returns a {@code String} representation of this region. 144 | * 145 | * @return {@code String} representation of this region. 146 | */ 147 | @Override 148 | public String toString() { 149 | return "Region [position=" + position + ", size=" + size + "]"; 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/geometry/RelativeSize.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.geometry; 26 | 27 | import java.awt.Dimension; 28 | 29 | /** 30 | * Calculates the size of an enclosed object relative to the enclosing object. 31 | * 32 | * @author coobird 33 | * @since 0.3.4 34 | * 35 | */ 36 | public class RelativeSize implements Size { 37 | /** 38 | * The scaling factor to use for the enclosed object. 39 | */ 40 | private final double scalingFactor; 41 | 42 | /** 43 | * Instantiates an object which calculates the size of an object, using 44 | * the given scaling factor. 45 | * 46 | * @param scalingFactor The scaling factor to use to determine the 47 | * size of the enclosing object. 48 | * @throws IllegalArgumentException When the scaling factor is not within 49 | * the range of {@code 0.0d} and 50 | * {@code 1.0d}, inclusive. 51 | */ 52 | public RelativeSize(double scalingFactor) { 53 | super(); 54 | if (scalingFactor < 0.0d || scalingFactor > 1.0d) { 55 | throw new IllegalArgumentException( 56 | "The scaling factor must be between 0.0d and 1.0d, inclusive." 57 | ); 58 | } 59 | this.scalingFactor = scalingFactor; 60 | } 61 | 62 | public Dimension calculate(int width, int height) { 63 | if (width <= 0 || height <= 0) { 64 | throw new IllegalArgumentException( 65 | "Width and height must be greater than 0." 66 | ); 67 | } 68 | int newWidth = (int)Math.round(width * scalingFactor); 69 | int newHeight = (int)Math.round(height * scalingFactor); 70 | return new Dimension(newWidth, newHeight); 71 | } 72 | 73 | /** 74 | * Returns a {@code String} representation of this object. 75 | * 76 | * @return {@code String} representation of this object. 77 | */ 78 | @Override 79 | public String toString() { 80 | return "RelativeSize [scalingFactor=" + scalingFactor + "]"; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/geometry/Size.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.geometry; 26 | 27 | import java.awt.Dimension; 28 | 29 | /** 30 | * This interface is implemented by classes which calculate the size of an 31 | * object inside of an enclosing object. 32 | * 33 | * @author coobird 34 | * @since 0.3.4 35 | * 36 | */ 37 | public interface Size { 38 | /** 39 | * Calculates the size of the object. 40 | * 41 | * @param width Width of the object which encloses the object 42 | * for which the size should be determined. 43 | * @param height Height of the object which encloses the object 44 | * for which the size should be determined. 45 | * @return Calculated size of the object. 46 | * @throws IllegalArgumentException If the width and/or height is less than 47 | * or equal to {@code 0}. 48 | */ 49 | public Dimension calculate(int width, int height); 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/geometry/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * This package contains classes used to specify positioning of watermarks and 27 | * other objects in Thumbnailator. 28 | */ 29 | package net.coobird.thumbnailator.geometry; 30 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/makers/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * This package provides classes which can be used to make thumbnails given 27 | * parameters to create the images. 28 | */ 29 | package net.coobird.thumbnailator.makers; 30 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/name/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * This package contains classes used to generate file names when saving 27 | * thumbnail images to files. 28 | */ 29 | package net.coobird.thumbnailator.name; 30 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2022 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * This package contains classes which provide the core functionalities of 27 | * Thumbnailator, including {@link net.coobird.thumbnailator.Thumbnails}, 28 | * the entry point for most use cases of Thumbnailator. 29 | */ 30 | package net.coobird.thumbnailator; 31 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/resizers/BicubicResizer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.resizers; 26 | 27 | import java.awt.RenderingHints; 28 | import java.awt.image.BufferedImage; 29 | import java.util.Collections; 30 | import java.util.Map; 31 | 32 | /** 33 | * Image resizer class using bicubic interpolation for the resizing operation. 34 | * 35 | * @author coobird 36 | * 37 | */ 38 | public class BicubicResizer extends AbstractResizer { 39 | /** 40 | * Instantiates a {@link BicubicResizer} with default rendering hints. 41 | */ 42 | public BicubicResizer() { 43 | this(Collections.emptyMap()); 44 | } 45 | 46 | /** 47 | * Instantiates a {@link BicubicResizer} with the specified rendering hints. 48 | * 49 | * @param hints Additional rendering hints to apply. 50 | */ 51 | public BicubicResizer(Map hints) { 52 | super(RenderingHints.VALUE_INTERPOLATION_BICUBIC, hints); 53 | } 54 | 55 | /** 56 | *

57 | * Resizes an image using bicubic interpolation. 58 | *

59 | *

60 | * If the source and/or destination image is {@code null}, then a 61 | * {@link NullPointerException} will be thrown. 62 | *

63 | * 64 | * @param srcImage The source image. 65 | * @param destImage The destination image. 66 | * 67 | * @throws NullPointerException When the source and/or the destination 68 | * image is {@code null}. 69 | */ 70 | @Override 71 | public void resize(BufferedImage srcImage, BufferedImage destImage) 72 | throws NullPointerException { 73 | super.resize(srcImage, destImage); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/resizers/BilinearResizer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.resizers; 26 | 27 | import java.awt.RenderingHints; 28 | import java.awt.image.BufferedImage; 29 | import java.util.Collections; 30 | import java.util.Map; 31 | 32 | /** 33 | * Image resizer class using bilinear interpolation for the resizing operation. 34 | * 35 | * @author coobird 36 | * 37 | */ 38 | public class BilinearResizer extends AbstractResizer { 39 | /** 40 | * Instantiates a {@link BilinearResizer} with default rendering hints. 41 | */ 42 | public BilinearResizer() { 43 | this(Collections.emptyMap()); 44 | } 45 | 46 | /** 47 | * Instantiates a {@link BilinearResizer} with the specified rendering 48 | * hints. 49 | * 50 | * @param hints Additional rendering hints to apply. 51 | */ 52 | public BilinearResizer(Map hints) { 53 | super(RenderingHints.VALUE_INTERPOLATION_BILINEAR, hints); 54 | } 55 | 56 | /** 57 | *

58 | * Resizes an image using bilinear interpolation. 59 | *

60 | *

61 | * If the source and/or destination image is {@code null}, then a 62 | * {@link NullPointerException} will be thrown. 63 | *

64 | * 65 | * @param srcImage The source image. 66 | * @param destImage The destination image. 67 | * 68 | * @throws NullPointerException When the source and/or the destination 69 | * image is {@code null}. 70 | */ 71 | @Override 72 | public void resize(BufferedImage srcImage, BufferedImage destImage) 73 | throws NullPointerException { 74 | super.resize(srcImage, destImage); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/resizers/FixedResizerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.resizers; 26 | 27 | import java.awt.Dimension; 28 | 29 | /** 30 | * A {@link ResizerFactory} that returns a specific {@link Resizer} 31 | * unconditionally. 32 | * 33 | * @author coobird 34 | * @since 0.4.0 35 | */ 36 | public class FixedResizerFactory implements ResizerFactory { 37 | /** 38 | * The resizer which is to be returned unconditionally by this class. 39 | */ 40 | private final Resizer resizer; 41 | 42 | /** 43 | * Creates an instance of the {@link FixedResizerFactory} which returns 44 | * the speicifed {@link Resizer} under all circumstances. 45 | * 46 | * @param resizer The {@link Resizer} instance that is to be returned 47 | * under all circumstances. 48 | */ 49 | public FixedResizerFactory(Resizer resizer) { 50 | this.resizer = resizer; 51 | } 52 | 53 | public Resizer getResizer() { 54 | return resizer; 55 | } 56 | 57 | public Resizer getResizer(Dimension originalSize, Dimension thumbnailSize) { 58 | return resizer; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/resizers/NullResizer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.resizers; 26 | 27 | import java.awt.Graphics; 28 | import java.awt.RenderingHints; 29 | import java.awt.RenderingHints.Key; 30 | import java.awt.image.BufferedImage; 31 | import java.util.Collections; 32 | import java.util.Map; 33 | 34 | /** 35 | * A {@link Resizer} which does not actually resize the image. 36 | *

37 | * The source image will be drawn at the origin of the destination image. 38 | * 39 | * @author coobird 40 | * @since 0.4.0 41 | * 42 | */ 43 | public class NullResizer extends AbstractResizer { 44 | /** 45 | * Instantiates the {@code NullResizer} which draws the source image at 46 | * the origin of the destination image. 47 | */ 48 | public NullResizer() { 49 | this( 50 | RenderingHints.VALUE_INTERPOLATION_BILINEAR, 51 | Collections.emptyMap() 52 | ); 53 | } 54 | 55 | /** 56 | * This constructor is {@code private} to prevent the rendering hints 57 | * from being set, as this {@link Resizer} does not perform any resizing. 58 | * 59 | * @param interpolationValue Not used. 60 | * @param hints Not used. 61 | */ 62 | private NullResizer(Object interpolationValue, Map hints) { 63 | super(interpolationValue, hints); 64 | } 65 | 66 | public void resize(BufferedImage srcImage, BufferedImage destImage) { 67 | super.performChecks(srcImage, destImage); 68 | 69 | Graphics g = destImage.getGraphics(); 70 | g.drawImage(srcImage, 0, 0, null); 71 | g.dispose(); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/resizers/Resizer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.resizers; 26 | 27 | import java.awt.image.BufferedImage; 28 | 29 | /** 30 | * This interface is implemented by classes which perform resizing operations. 31 | * 32 | * @author coobird 33 | * 34 | */ 35 | public interface Resizer { 36 | /** 37 | * Resizes an image. 38 | *

39 | * The source image is resized to fit the dimensions of the destination 40 | * image and drawn. 41 | * 42 | * @param srcImage The source image. 43 | * @param destImage The destination image. 44 | */ 45 | public void resize(BufferedImage srcImage, BufferedImage destImage); 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/resizers/ResizerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.resizers; 26 | 27 | import java.awt.Dimension; 28 | 29 | /** 30 | * This interface is implemented by all classes which will return a 31 | * {@link Resizer} that should be used when creating a thumbnail. 32 | * 33 | * @author coobird 34 | * @since 0.4.0 35 | * 36 | */ 37 | public interface ResizerFactory { 38 | /** 39 | * Returns the default {@link Resizer}. 40 | * 41 | * @return The default {@code Resizer}. 42 | */ 43 | public Resizer getResizer(); 44 | 45 | /** 46 | * Returns a suitable {@link Resizer}, given the {@link Dimension}s of the 47 | * original image and the thumbnail image. 48 | * 49 | * @param originalSize The size of the original image. 50 | * @param thumbnailSize The size of the thumbnail. 51 | * @return The suitable {@code Resizer} to perform the 52 | * resizing operation for the given condition. 53 | */ 54 | public Resizer getResizer(Dimension originalSize, Dimension thumbnailSize); 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/resizers/Resizers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.resizers; 26 | 27 | import java.awt.image.BufferedImage; 28 | 29 | /** 30 | *

31 | * This enum can be used to select a specific {@link Resizer} in order 32 | * to perform a resizing operation. 33 | *

34 | *

35 | * The instance held by a value of this enum is a single instance. When using 36 | * specific implementations of {@link Resizer}s, it is preferable to obtain 37 | * an instance of a {@link Resizer} through this enum or the 38 | * {@link DefaultResizerFactory} class in order to prevent many instances of the 39 | * {@link Resizer} class implementations from being instantiated. 40 | *

41 | *
42 | *
Usage:
43 | *
44 | *

45 | * The following example code demonstrates how to use the {@link Resizers} enum 46 | * in order to resize an image using bilinear interpolation: 47 | *

48 | *
 49 | BufferedImage sourceImage = new BufferedImageBuilder(400, 400).build();
 50 | BufferedImage destImage = new BufferedImageBuilder(200, 200).build();
 51 | 
 52 | Resizers.BILINEAR.resize(sourceImage, destImage);
 53 |  * 
54 | *
55 | *
56 | * 57 | * @see DefaultResizerFactory 58 | * 59 | * @author coobird 60 | * 61 | */ 62 | public enum Resizers implements Resizer { 63 | /** 64 | * A {@link Resizer} which does not perform resizing operations. The source 65 | * image will be drawn at the origin of the destination image. 66 | */ 67 | NULL(new NullResizer()), 68 | 69 | /** 70 | * A {@link Resizer} which performs resizing operations using 71 | * bilinear interpolation. 72 | */ 73 | BILINEAR(new BilinearResizer()), 74 | 75 | /** 76 | * A {@link Resizer} which performs resizing operations using 77 | * bicubic interpolation. 78 | */ 79 | BICUBIC(new BicubicResizer()), 80 | 81 | /** 82 | * A {@link Resizer} which performs resizing operations using 83 | * progressive bilinear scaling. 84 | *

85 | * For details on this technique, refer to the documentation of the 86 | * {@link ProgressiveBilinearResizer} class. 87 | */ 88 | PROGRESSIVE(new ProgressiveBilinearResizer()) 89 | ; 90 | 91 | private final Resizer resizer; 92 | 93 | private Resizers(Resizer resizer) { 94 | this.resizer = resizer; 95 | } 96 | 97 | public void resize(BufferedImage srcImage, BufferedImage destImage) { 98 | resizer.resize(srcImage, destImage); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/resizers/configurations/AlphaInterpolation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * 27 | */ 28 | package net.coobird.thumbnailator.resizers.configurations; 29 | 30 | import java.awt.RenderingHints; 31 | import java.awt.RenderingHints.Key; 32 | 33 | /** 34 | * An enum which is used to specify the alpha interpolation settings of the 35 | * resizing operations. 36 | * 37 | * @author coobird 38 | * 39 | */ 40 | public enum AlphaInterpolation implements ResizerConfiguration { 41 | /** 42 | * A hint used to emphasize speed when performing alpha interpolation. 43 | */ 44 | SPEED(RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED), 45 | 46 | /** 47 | * A hint used to emphasize quality when performing alpha interpolation. 48 | */ 49 | QUALITY(RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY), 50 | 51 | /** 52 | * A hint which indicates to use the default alpha interpolation settings. 53 | */ 54 | DEFAULT(RenderingHints.VALUE_ALPHA_INTERPOLATION_DEFAULT), 55 | ; 56 | 57 | /** 58 | * The field used to hold the rendering hint. 59 | */ 60 | private final Object value; 61 | 62 | /** 63 | * Instantiates this enum. 64 | * 65 | * @param value The rendering hint value. 66 | */ 67 | private AlphaInterpolation(Object value) { 68 | this.value = value; 69 | } 70 | 71 | public Key getKey() { 72 | return RenderingHints.KEY_ALPHA_INTERPOLATION; 73 | } 74 | 75 | public Object getValue() { 76 | return value; 77 | } 78 | } -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/resizers/configurations/Antialiasing.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * 27 | */ 28 | package net.coobird.thumbnailator.resizers.configurations; 29 | 30 | import java.awt.RenderingHints; 31 | import java.awt.RenderingHints.Key; 32 | 33 | /** 34 | * An enum which is used to specify the antialiasing settings of the 35 | * resizing operations. 36 | * 37 | * @author coobird 38 | * 39 | */ 40 | public enum Antialiasing implements ResizerConfiguration { 41 | /** 42 | * A hint to enable antialiasing. 43 | */ 44 | ON(RenderingHints.VALUE_ANTIALIAS_ON), 45 | 46 | /** 47 | * A hint to disable antialiasing. 48 | */ 49 | OFF(RenderingHints.VALUE_ANTIALIAS_OFF), 50 | 51 | /** 52 | * A hint to use the default antialiasing settings. 53 | */ 54 | DEFAULT(RenderingHints.VALUE_ANTIALIAS_DEFAULT), 55 | ; 56 | 57 | /** 58 | * The field used to hold the rendering hint. 59 | */ 60 | private final Object value; 61 | 62 | /** 63 | * Instantiates this enum. 64 | * 65 | * @param value The rendering hint value. 66 | */ 67 | private Antialiasing(Object value) { 68 | this.value = value; 69 | } 70 | 71 | public Key getKey() { 72 | return RenderingHints.KEY_ANTIALIASING; 73 | } 74 | 75 | public Object getValue() { 76 | return value; 77 | } 78 | } -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/resizers/configurations/Dithering.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * 27 | */ 28 | package net.coobird.thumbnailator.resizers.configurations; 29 | 30 | import java.awt.RenderingHints; 31 | import java.awt.RenderingHints.Key; 32 | 33 | /** 34 | * An enum which is used to specify the dithering settings of the 35 | * resizing operations. 36 | * 37 | * @author coobird 38 | * 39 | */ 40 | public enum Dithering implements ResizerConfiguration { 41 | /** 42 | * A hint used to enable dithering. 43 | */ 44 | ENABLE(RenderingHints.VALUE_DITHER_ENABLE), 45 | 46 | /** 47 | * A hint used to disable dithering. 48 | */ 49 | DISABLE(RenderingHints.VALUE_DITHER_DISABLE), 50 | 51 | /** 52 | * A hint to use the default dithering settings. 53 | */ 54 | DEFAULT(RenderingHints.VALUE_DITHER_DEFAULT), 55 | ; 56 | 57 | /** 58 | * The field used to hold the rendering hint. 59 | */ 60 | private final Object value; 61 | 62 | /** 63 | * Instantiates this enum. 64 | * 65 | * @param value The rendering hint value. 66 | */ 67 | private Dithering(Object value) { 68 | this.value = value; 69 | } 70 | 71 | public Key getKey() { 72 | return RenderingHints.KEY_DITHERING; 73 | } 74 | 75 | public Object getValue() { 76 | return value; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/resizers/configurations/Rendering.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * 27 | */ 28 | package net.coobird.thumbnailator.resizers.configurations; 29 | 30 | import java.awt.RenderingHints; 31 | import java.awt.RenderingHints.Key; 32 | 33 | /** 34 | * An enum which is used to specify the dithering settings of the 35 | * resizing operations. 36 | * 37 | * @author coobird 38 | * 39 | */ 40 | public enum Rendering implements ResizerConfiguration { 41 | /** 42 | * A hint used to emphasize speed when rendering. 43 | */ 44 | SPEED(RenderingHints.VALUE_RENDER_SPEED), 45 | 46 | /** 47 | * A hint used to emphasize quality when rendering. 48 | */ 49 | QUALITY(RenderingHints.VALUE_RENDER_QUALITY), 50 | 51 | /** 52 | * A hint to use the default rendering settings. 53 | */ 54 | DEFAULT(RenderingHints.VALUE_RENDER_DEFAULT), 55 | ; 56 | 57 | /** 58 | * 59 | */ 60 | private final Object value; 61 | 62 | /** 63 | * @param value 64 | */ 65 | private Rendering(Object value) { 66 | this.value = value; 67 | } 68 | 69 | public Key getKey() { 70 | return RenderingHints.KEY_ALPHA_INTERPOLATION; 71 | } 72 | 73 | public Object getValue() { 74 | return value; 75 | } 76 | } -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/resizers/configurations/ResizerConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.resizers.configurations; 26 | 27 | import java.awt.RenderingHints; 28 | 29 | import net.coobird.thumbnailator.resizers.Resizer; 30 | 31 | /** 32 | * An interface which are implemented by classes and enums which provide 33 | * configuration information for {@link Resizer}s. 34 | * 35 | * @author coobird 36 | * 37 | */ 38 | public interface ResizerConfiguration { 39 | /** 40 | * Returns a rendering hint key. 41 | * 42 | * @return Rendering hint key. 43 | */ 44 | public RenderingHints.Key getKey(); 45 | 46 | /** 47 | * Returns a rendering hint value. 48 | * 49 | * @return Rendering hint value. 50 | */ 51 | public Object getValue(); 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/resizers/configurations/ScalingMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * 27 | */ 28 | package net.coobird.thumbnailator.resizers.configurations; 29 | 30 | import net.coobird.thumbnailator.resizers.ProgressiveBilinearResizer; 31 | 32 | /** 33 | * An enum which is used to specify how to scale images when creating 34 | * thumbnails. 35 | * 36 | * @author coobird 37 | * 38 | */ 39 | public enum ScalingMode { 40 | /** 41 | * A hint to use bilinear interpolation when resizing images. 42 | */ 43 | BILINEAR, 44 | 45 | /** 46 | * A hint to use bicubic interpolation when resizing images. 47 | */ 48 | BICUBIC, 49 | 50 | /** 51 | * A hint to use progressing bilinear interpolation when resizing images. 52 | *

53 | * For details on this technique, refer to the documentation of the 54 | * {@link ProgressiveBilinearResizer} class. 55 | */ 56 | PROGRESSIVE_BILINEAR, 57 | ; 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/resizers/configurations/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * This package provides enums which are used to set rendering hints used when 27 | * using {@link net.coobird.thumbnailator.resizers.Resizers} to create 28 | * thumbnails. 29 | */ 30 | package net.coobird.thumbnailator.resizers.configurations; 31 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/resizers/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * This package provides classes which perform image resizing operations which 27 | * is used to create thumbnails with Thumbnailator. 28 | */ 29 | package net.coobird.thumbnailator.resizers; 30 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/tasks/FileThumbnailTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.tasks; 26 | 27 | import java.awt.image.BufferedImage; 28 | import java.io.File; 29 | import java.io.IOException; 30 | 31 | import net.coobird.thumbnailator.ThumbnailParameter; 32 | import net.coobird.thumbnailator.tasks.io.FileImageSink; 33 | import net.coobird.thumbnailator.tasks.io.FileImageSource; 34 | 35 | /** 36 | * A thumbnail generation task which reads and writes data from and to a 37 | * {@link File}. 38 | *

39 | * Only the first image included in the image file will be read. Subsequent 40 | * images included in the image file will be ignored. 41 | * 42 | * @author coobird 43 | * 44 | */ 45 | public class FileThumbnailTask extends ThumbnailTask { 46 | /** 47 | * The {@link SourceSinkThumbnailTask} used to perform the task. 48 | */ 49 | private final SourceSinkThumbnailTask task; 50 | 51 | /** 52 | * Creates a {@link ThumbnailTask} in which image data is read from the 53 | * specified {@link File} and is output to a specified {@link File}, using 54 | * the parameters provided in the specified {@link ThumbnailParameter}. 55 | * 56 | * @param param The parameters to use to create the thumbnail. 57 | * @param sourceFile The {@link File} from which image data is read. 58 | * @param destinationFile The {@link File} to which thumbnail is written. 59 | * @throws NullPointerException If the parameter is {@code null}. 60 | */ 61 | public FileThumbnailTask(ThumbnailParameter param, File sourceFile, File destinationFile) { 62 | super(param); 63 | this.task = new SourceSinkThumbnailTask( 64 | param, 65 | new FileImageSource(sourceFile), 66 | new FileImageSink(destinationFile) 67 | ); 68 | } 69 | 70 | @Override 71 | public BufferedImage read() throws IOException { 72 | return task.read(); 73 | } 74 | 75 | @Override 76 | public void write(BufferedImage img) throws IOException { 77 | task.write(img); 78 | } 79 | 80 | @Override 81 | public ThumbnailParameter getParam() { 82 | return task.getParam(); 83 | } 84 | 85 | @Override 86 | public File getSource() { 87 | return task.getSource(); 88 | } 89 | 90 | @Override 91 | public File getDestination() { 92 | return task.getDestination(); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/tasks/SourceSinkThumbnailTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.tasks; 26 | 27 | import java.awt.image.BufferedImage; 28 | import java.io.IOException; 29 | 30 | import net.coobird.thumbnailator.ThumbnailParameter; 31 | import net.coobird.thumbnailator.tasks.io.ImageSink; 32 | import net.coobird.thumbnailator.tasks.io.ImageSource; 33 | 34 | /** 35 | * A {@link ThumbnailTask} which holds an {@link ImageSource} from which the 36 | * image is read or retrieved, and an {@link ImageSink} to which the thumbnail 37 | * is stored or written. 38 | *

39 | * This class will take care of handing off information from the 40 | * {@link ImageSource} to the {@link ImageSink}. For example, the output format 41 | * that should be used by the {@link ImageSink} will be handed off if the 42 | * {@link ThumbnailParameter#ORIGINAL_FORMAT} parameter is set. 43 | * 44 | * @author coobird 45 | * 46 | * @param The source class from which the source image is retrieved 47 | * or read. 48 | * @param The destination class to which the thumbnail is stored 49 | * or written. 50 | */ 51 | public class SourceSinkThumbnailTask extends ThumbnailTask { 52 | /** 53 | * The source from which the image is retrieved or read. 54 | */ 55 | private final ImageSource source; 56 | 57 | /** 58 | * The destination to which the thumbnail is stored or written. 59 | */ 60 | private final ImageSink destination; 61 | 62 | /** 63 | * Creates a {@link ThumbnailTask} in which an image is retrived from the 64 | * specified {@link ImageSource} and written to the specified 65 | * {@link ImageSink}, using the parameters provided in the specified 66 | * {@link ThumbnailParameter}. 67 | * 68 | * @param param The parameters to use to create the thumbnail. 69 | * @param source The source from which the image is retrieved 70 | * or read from. 71 | * @param destination The destination to which the thumbnail is 72 | * stored or written to. 73 | * @throws NullPointerException If either the parameter, 74 | * {@link ImageSource} or {@link ImageSink} 75 | * is {@code null}. 76 | */ 77 | public SourceSinkThumbnailTask(ThumbnailParameter param, ImageSource source, ImageSink destination) { 78 | super(param); 79 | if (source == null) { 80 | throw new NullPointerException("ImageSource cannot be null."); 81 | } 82 | if (destination == null) { 83 | throw new NullPointerException("ImageSink cannot be null."); 84 | } 85 | 86 | source.setThumbnailParameter(param); 87 | this.source = source; 88 | 89 | destination.setThumbnailParameter(param); 90 | this.destination = destination; 91 | } 92 | 93 | @Override 94 | public BufferedImage read() throws IOException { 95 | BufferedImage img = source.read(); 96 | inputFormatName = source.getInputFormatName(); 97 | 98 | return img; 99 | } 100 | 101 | @Override 102 | public void write(BufferedImage img) throws IOException { 103 | String paramOutputFormat = param.getOutputFormat(); 104 | String formatName = null; 105 | 106 | if (ThumbnailParameter.DETERMINE_FORMAT.equals(paramOutputFormat)) { 107 | paramOutputFormat = destination.preferredOutputFormatName(); 108 | } 109 | 110 | if (paramOutputFormat == ThumbnailParameter.ORIGINAL_FORMAT) { 111 | formatName = inputFormatName; 112 | } else { 113 | formatName = paramOutputFormat; 114 | } 115 | 116 | destination.setOutputFormatName(formatName); 117 | destination.write(img); 118 | } 119 | 120 | @Override 121 | public S getSource() { 122 | return source.getSource(); 123 | } 124 | 125 | @Override 126 | public D getDestination() { 127 | return destination.getSink(); 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/tasks/StreamThumbnailTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.tasks; 26 | 27 | import java.awt.image.BufferedImage; 28 | import java.io.IOException; 29 | import java.io.InputStream; 30 | import java.io.OutputStream; 31 | 32 | import net.coobird.thumbnailator.ThumbnailParameter; 33 | import net.coobird.thumbnailator.tasks.io.InputStreamImageSource; 34 | import net.coobird.thumbnailator.tasks.io.OutputStreamImageSink; 35 | 36 | /** 37 | * A thumbnail generation task which streams data from an {@link InputStream} 38 | * to an {@link OutputStream}. 39 | *

40 | * This class does not close the {@link InputStream} and {@link OutputStream} 41 | * upon the completion of processing. 42 | *

43 | * Only the first image obtained from the data stream will be read. Subsequent 44 | * images will be ignored. 45 | * 46 | * @author coobird 47 | * 48 | */ 49 | public class StreamThumbnailTask extends ThumbnailTask { 50 | /** 51 | * The {@link SourceSinkThumbnailTask} used to perform the task. 52 | */ 53 | private final SourceSinkThumbnailTask task; 54 | 55 | /** 56 | * Creates a {@link ThumbnailTask} in which streamed image data from the 57 | * specified {@link InputStream} is output to a specified 58 | * {@link OutputStream}, using the parameters provided in the specified 59 | * {@link ThumbnailParameter}. 60 | * 61 | * @param param The parameters to use to create the thumbnail. 62 | * @param is The {@link InputStream} from which to obtain image data. 63 | * @param os The {@link OutputStream} to send thumbnail data to. 64 | * @throws NullPointerException If the parameter is {@code null}. 65 | */ 66 | public StreamThumbnailTask(ThumbnailParameter param, InputStream is, OutputStream os) { 67 | super(param); 68 | this.task = new SourceSinkThumbnailTask( 69 | param, 70 | new InputStreamImageSource(is), 71 | new OutputStreamImageSink(os) 72 | ); 73 | } 74 | 75 | @Override 76 | public BufferedImage read() throws IOException { 77 | return task.read(); 78 | } 79 | 80 | @Override 81 | public void write(BufferedImage img) throws IOException { 82 | task.write(img); 83 | } 84 | 85 | @Override 86 | public ThumbnailParameter getParam() { 87 | return task.getParam(); 88 | } 89 | 90 | @Override 91 | public InputStream getSource() { 92 | return task.getSource(); 93 | } 94 | 95 | @Override 96 | public OutputStream getDestination() { 97 | return task.getDestination(); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/tasks/ThumbnailTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.tasks; 26 | 27 | import java.awt.image.BufferedImage; 28 | import java.io.IOException; 29 | 30 | import net.coobird.thumbnailator.ThumbnailParameter; 31 | 32 | /** 33 | * This class is used by {@link ThumbnailTask} implementations which is used 34 | * when creating thumbnails from external sources and destinations. 35 | *

36 | * If the image handled by a {@link ThumbnailTask} contains multiple images, 37 | * only the first image will be read by the {@link #read()} method. Any 38 | * subsequent images will be ignored. 39 | * 40 | * @param The class from which the image is retrieved or read. 41 | * @param The class to which the thumbnail is stored or written. 42 | * 43 | * @author coobird 44 | * 45 | */ 46 | public abstract class ThumbnailTask { 47 | /** 48 | * The parameters to use when creating a thumbnail. 49 | */ 50 | protected final ThumbnailParameter param; 51 | 52 | /** 53 | * String indicating the image format of the input image. 54 | *

55 | * To be used for situtions where the output image format should be the 56 | * same as the input image format. 57 | */ 58 | protected String inputFormatName; 59 | 60 | /** 61 | * Constant used to obtain the first image when reading an image file. 62 | */ 63 | protected static final int FIRST_IMAGE_INDEX = 0; 64 | 65 | /** 66 | * Instantiates a {@link ThumbnailTask} with the parameters to use when 67 | * creating thumbnails. 68 | * 69 | * @param param The parameters to use when creating thumbnails. 70 | * @throws NullPointerException If the parameter is {@code null}. 71 | */ 72 | protected ThumbnailTask(ThumbnailParameter param) { 73 | if (param == null) { 74 | throw new NullPointerException("The parameter is null."); 75 | } 76 | this.param = param; 77 | } 78 | 79 | /** 80 | * Reads a source image. 81 | * 82 | * @return The image which was obtained from the source. 83 | * @throws IOException Thrown when an I/O problem occurs when reading 84 | * from the image source. 85 | */ 86 | /* 87 | * Future changes note: The public interface of this method may have to be 88 | * changed to support reading images tile-by-tile. This change may be 89 | * required in order to support large images. 90 | */ 91 | public abstract BufferedImage read() throws IOException; 92 | 93 | /** 94 | * Writes the thumbnail to the destination. 95 | * 96 | * @param img The image to write. 97 | * @throws UnsupportedFormatException When an image file which is to be 98 | * read or written is unsupported. 99 | * @throws IOException Thrown when an I/O problem occurs when writing the 100 | * image. 101 | */ 102 | public abstract void write(BufferedImage img) throws IOException; 103 | 104 | /** 105 | * Returns the {@link ThumbnailParameter} for this {@link ThumbnailTask}, 106 | * used when performing a thumbnail generation operation. 107 | * 108 | * @return The parameters to use when generating thumbnails. 109 | */ 110 | public ThumbnailParameter getParam() { 111 | return param; 112 | } 113 | 114 | /** 115 | * Returns the source from which the source image is retrieved or read. 116 | * 117 | * @return The source. 118 | */ 119 | public abstract S getSource(); 120 | 121 | /** 122 | * Returns the destination to which the thumbnail is stored or written. 123 | * 124 | * @return The destination. 125 | */ 126 | public abstract D getDestination(); 127 | } 128 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/tasks/UnsupportedFormatException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.tasks; 26 | 27 | import java.io.IOException; 28 | 29 | /** 30 | * An exception used to indicate that the specified format could not be 31 | * used in an operation. 32 | * 33 | * @author coobird 34 | * 35 | */ 36 | public class UnsupportedFormatException extends IOException { 37 | /** 38 | * An ID used for serialization. 39 | */ 40 | private static final long serialVersionUID = 1254432584303852552L; 41 | 42 | /** 43 | * The format name which was not supported. 44 | */ 45 | private final String formatName; 46 | 47 | /** 48 | * A constant which is used to indicate an unknown format. 49 | */ 50 | public static final String UNKNOWN = ""; 51 | 52 | /** 53 | * Instantiates a {@link UnsupportedFormatException} with the unsupported 54 | * format. 55 | * 56 | * @param formatName Format name. 57 | */ 58 | public UnsupportedFormatException(String formatName) { 59 | super(); 60 | this.formatName = formatName; 61 | } 62 | 63 | /** 64 | * Instantiates a {@link UnsupportedFormatException} with the unsupported 65 | * format and a detailed message. 66 | * 67 | * @param formatName Format name. 68 | * @param s A message detailing the exception. 69 | */ 70 | public UnsupportedFormatException(String formatName, String s) { 71 | super(s); 72 | this.formatName = formatName; 73 | } 74 | 75 | /** 76 | * Returns the format name which is not supported. 77 | * 78 | * @return Format name. 79 | */ 80 | public String getFormatName() { 81 | return formatName; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/tasks/io/AbstractImageSink.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.tasks.io; 26 | 27 | import java.awt.image.BufferedImage; 28 | import java.io.IOException; 29 | 30 | import net.coobird.thumbnailator.ThumbnailParameter; 31 | 32 | /** 33 | * An abstract class for {@link ImageSink}s. 34 | * 35 | * @author coobird 36 | * 37 | */ 38 | public abstract class AbstractImageSink implements ImageSink { 39 | /** 40 | * The name of the format to output the image as. 41 | */ 42 | protected String outputFormat; 43 | 44 | /** 45 | * The parameters that should be used when storing the image. 46 | */ 47 | protected ThumbnailParameter param; 48 | 49 | /** 50 | * Default constructor. 51 | */ 52 | protected AbstractImageSink() {} 53 | 54 | public void setOutputFormatName(String format) { 55 | outputFormat = format; 56 | } 57 | 58 | public void setThumbnailParameter(ThumbnailParameter param) { 59 | this.param = param; 60 | } 61 | 62 | public void write(BufferedImage img) throws IOException { 63 | if (img == null) { 64 | throw new NullPointerException("Cannot write a null image."); 65 | } 66 | 67 | if (ThumbnailParameter.DETERMINE_FORMAT.equals(outputFormat)) { 68 | outputFormat = preferredOutputFormatName(); 69 | } 70 | } 71 | 72 | public String preferredOutputFormatName() { 73 | return ThumbnailParameter.ORIGINAL_FORMAT; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/tasks/io/AbstractImageSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.tasks.io; 26 | 27 | import net.coobird.thumbnailator.ThumbnailParameter; 28 | 29 | /** 30 | * An abstract class for {@link ImageSource}s. 31 | * 32 | * @author coobird 33 | * 34 | */ 35 | public abstract class AbstractImageSource implements ImageSource { 36 | /** 37 | * The image format of the input image. 38 | */ 39 | protected String inputFormatName; 40 | 41 | /** 42 | * The parameters that should be used when retrieving the image. 43 | */ 44 | protected ThumbnailParameter param; 45 | 46 | /** 47 | * Indicates whether the input has already been read. 48 | */ 49 | protected boolean hasReadInput = false; 50 | 51 | /** 52 | * Default constructor. 53 | */ 54 | protected AbstractImageSource() {} 55 | 56 | /** 57 | * Indicates that the {@link ImageSource} has completed reading the input 58 | * file, and returns the value given in the argument. 59 | *

60 | * This method should be used by implementation classes when returning 61 | * the result of the {@link #read()} method, as shown in the following 62 | * example code: 63 |

64 | return finishedReading(sourceImage);
65 | 
66 | * 67 | * @param The return value type. 68 | * @param returnValue The return value of the {@link #read()} method. 69 | * @return The return value of the {@link #read()} method. 70 | */ 71 | protected V finishedReading(V returnValue) { 72 | hasReadInput = true; 73 | return returnValue; 74 | } 75 | 76 | public void setThumbnailParameter(ThumbnailParameter param) { 77 | this.param = param; 78 | } 79 | 80 | public String getInputFormatName() { 81 | if (!hasReadInput) { 82 | throw new IllegalStateException("Input has not been read yet."); 83 | } 84 | return inputFormatName; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/tasks/io/BufferedImageSink.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.tasks.io; 26 | 27 | import java.awt.image.BufferedImage; 28 | import java.io.IOException; 29 | 30 | /** 31 | * An {@link ImageSink} which stores the resulting thumbnail to a 32 | * {@link BufferedImage}. 33 | * 34 | * @author coobird 35 | * 36 | */ 37 | public class BufferedImageSink extends AbstractImageSink { 38 | /** 39 | * The {@link BufferedImage} which holds the thumbnail. 40 | */ 41 | private BufferedImage img; 42 | 43 | /** 44 | * Indicates whether the thumbnail has been written to this object. 45 | */ 46 | private boolean written = false; 47 | 48 | public void write(BufferedImage img) throws IOException { 49 | super.write(img); 50 | 51 | this.img = img; 52 | written = true; 53 | } 54 | 55 | /** 56 | * Returns the thumbnail. 57 | * 58 | * @return The thumbnail. 59 | * @throws IllegalStateException If a thumbnail has not been stored to 60 | * this {@link BufferedImageSink} yet. 61 | */ 62 | public BufferedImage getSink() { 63 | if (!written) { 64 | throw new IllegalStateException("BufferedImageSink has not been written to yet."); 65 | } 66 | return img; 67 | } 68 | 69 | @Override 70 | public void setOutputFormatName(String format) { 71 | // do nothing 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/tasks/io/BufferedImageSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2023 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.tasks.io; 26 | 27 | import java.awt.Rectangle; 28 | import java.awt.image.BufferedImage; 29 | import java.io.IOException; 30 | 31 | import net.coobird.thumbnailator.geometry.Region; 32 | 33 | /** 34 | * An {@link ImageSource} which uses a {@link BufferedImage} as the source 35 | * image. 36 | * 37 | * @author coobird 38 | * 39 | */ 40 | public class BufferedImageSource extends AbstractImageSource { 41 | /** 42 | * The image that should be used as the source for making a thumbnail. 43 | */ 44 | private final BufferedImage img; 45 | 46 | /** 47 | * Instantiates a {@link BufferedImageSource} object with the 48 | * {@link BufferedImage} that should be used as the source image for making 49 | * thumbnails. 50 | * 51 | * @param img The source image. 52 | * @throws NullPointerException If the image is null. 53 | */ 54 | public BufferedImageSource(BufferedImage img) { 55 | super(); 56 | 57 | if (img == null) { 58 | throw new NullPointerException("Image cannot be null."); 59 | } 60 | 61 | this.img = img; 62 | } 63 | 64 | public BufferedImage read() throws IOException { 65 | inputFormatName = null; 66 | 67 | if (param != null && param.getSourceRegion() != null) { 68 | Region region = param.getSourceRegion(); 69 | Rectangle r = region.calculate( 70 | img.getWidth(), img.getHeight(), false, false, false 71 | ); 72 | 73 | return finishedReading(img.getSubimage(r.x, r.y, r.width, r.height)); 74 | } else { 75 | return finishedReading(img); 76 | } 77 | } 78 | 79 | public BufferedImage getSource() { 80 | return img; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/tasks/io/ImageSink.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.tasks.io; 26 | 27 | import java.awt.image.BufferedImage; 28 | import java.io.IOException; 29 | 30 | import net.coobird.thumbnailator.ThumbnailParameter; 31 | 32 | /** 33 | * An interface to be implemented by classes which stores the image resulting 34 | * from a thumbnail generation task. 35 | * 36 | * @param The destination class to which the thumbnail is stored 37 | * or written. 38 | * 39 | * @author coobird 40 | * 41 | */ 42 | public interface ImageSink { 43 | /** 44 | * Writes the resulting image to a destination. 45 | * 46 | * @param img The image to write or store. 47 | * @throws IOException When a problem occurs while writing or storing 48 | * the image. 49 | * @throws NullPointerException If the image is {@code null}. 50 | */ 51 | public void write(BufferedImage img) throws IOException; 52 | 53 | /** 54 | * Sets the output format of the resulting image. 55 | *

56 | * For {@link ImageSink}s which stores raw images, the format name specified 57 | * by this method may be ignored. 58 | * 59 | * @param format File format with which to store the image. 60 | */ 61 | public void setOutputFormatName(String format); 62 | 63 | /** 64 | * Sets the {@link ThumbnailParameter} from which to retrieve parameters 65 | * to use when storing the image. 66 | * 67 | * @param param The {@link ThumbnailParameter} with image 68 | * writing parameters. 69 | */ 70 | public void setThumbnailParameter(ThumbnailParameter param); 71 | 72 | /** 73 | *

74 | * Returns the output format to use from information provided for the 75 | * output image. 76 | *

77 | *

78 | * If the output format cannot be determined, then 79 | * {@link ThumbnailParameter#ORIGINAL_FORMAT} should be returned. 80 | *

81 | * @return Name of the preferred output format. 82 | */ 83 | public String preferredOutputFormatName(); 84 | 85 | /** 86 | * Returns the destination to which the thumbnail will be stored or 87 | * written. 88 | * 89 | * @return The destination for the thumbnail image. 90 | */ 91 | public T getSink(); 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/tasks/io/ImageSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.tasks.io; 26 | 27 | import java.awt.image.BufferedImage; 28 | import java.io.IOException; 29 | 30 | import net.coobird.thumbnailator.ThumbnailParameter; 31 | 32 | /** 33 | * An interface to be implemented by classes which read or retrieve images 34 | * from which a thumbnail should be produced. 35 | * 36 | * @param The source class from which the source image is retrieved 37 | * or read. 38 | * @author coobird 39 | * 40 | */ 41 | public interface ImageSource { 42 | /** 43 | * Retrieves the image from the source. 44 | * 45 | * @return The image. 46 | * @throws IOException When a problem occurs while reading or obtaining 47 | * the image. 48 | */ 49 | public BufferedImage read() throws IOException; 50 | 51 | /** 52 | * Returns the name of the image format. 53 | * 54 | * @return The image format name. If there is no 55 | * image format information, then 56 | * {@code null} will be returned. 57 | * @throws IllegalStateException If the source image has not been 58 | * read yet. 59 | */ 60 | public String getInputFormatName(); 61 | 62 | /** 63 | * Sets the {@link ThumbnailParameter} from which to retrieve parameters 64 | * to use when retrieving the image. 65 | * 66 | * @param param The {@link ThumbnailParameter} with image 67 | * reading parameters. 68 | */ 69 | public void setThumbnailParameter(ThumbnailParameter param); 70 | 71 | /** 72 | * Returns the source from which the image is read or retrieved. 73 | * 74 | * @return The source of the image. 75 | */ 76 | public T getSource(); 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/tasks/io/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * This package provides classes which perform image input and output 27 | * operations in conjunction with the 28 | * {@link net.coobird.thumbnailator.tasks.SourceSinkThumbnailTask} class. 29 | */ 30 | package net.coobird.thumbnailator.tasks.io; 31 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/tasks/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * This package provides classes which perform image input and output 27 | * operations, which can be used to aid in creating and writing thumbnails 28 | * to and from external sources. 29 | */ 30 | package net.coobird.thumbnailator.tasks; 31 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/util/BufferedImages.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.util; 26 | 27 | import net.coobird.thumbnailator.builders.BufferedImageBuilder; 28 | 29 | import java.awt.Graphics; 30 | import java.awt.image.BufferedImage; 31 | 32 | /** 33 | * This class provides convenience methods for using {@link BufferedImage}s. 34 | * 35 | * @author coobird 36 | * 37 | */ 38 | public final class BufferedImages { 39 | /** 40 | * This class is not intended to be instantiated. 41 | */ 42 | private BufferedImages() {} 43 | 44 | /** 45 | * Returns a {@link BufferedImage} which is a graphical copy of the 46 | * specified image. 47 | * 48 | * @param img The image to copy. 49 | * @return A copy of the specified image. 50 | */ 51 | public static BufferedImage copy(BufferedImage img) { 52 | return copy(img, img.getType()); 53 | } 54 | 55 | /** 56 | * Returns a {@link BufferedImage} with the specified image type, where the 57 | * graphical content is a copy of the specified image. 58 | * 59 | * @param img The image to copy. 60 | * @param imageType The image type for the image to return. 61 | * @return A copy of the specified image. 62 | */ 63 | public static BufferedImage copy(BufferedImage img, int imageType) { 64 | int width = img.getWidth(); 65 | int height = img.getHeight(); 66 | 67 | BufferedImage newImage = new BufferedImageBuilder(width, height, imageType).build(); 68 | 69 | Graphics g = newImage.createGraphics(); 70 | g.drawImage(img, 0, 0, null); 71 | g.dispose(); 72 | 73 | return newImage; 74 | } 75 | } -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/util/ThumbnailatorUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2022 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.util; 26 | 27 | import java.util.Arrays; 28 | import java.util.Collections; 29 | import java.util.Iterator; 30 | import java.util.List; 31 | 32 | import javax.imageio.ImageIO; 33 | import javax.imageio.ImageWriter; 34 | 35 | import net.coobird.thumbnailator.ThumbnailParameter; 36 | 37 | /** 38 | * A utility class for Thumbnailator. 39 | * 40 | * @author coobird 41 | * 42 | */ 43 | public final class ThumbnailatorUtils { 44 | /** 45 | * This class is not intended to be instantiated. 46 | */ 47 | private ThumbnailatorUtils() {} 48 | 49 | /** 50 | * Returns a {@link List} of supported output formats. 51 | * 52 | * @return A {@link List} of supported output formats. If no formats 53 | * are supported, an empty list is returned. 54 | */ 55 | public static List getSupportedOutputFormats() { 56 | String[] formats = ImageIO.getWriterFormatNames(); 57 | 58 | if (formats == null) { 59 | return Collections.emptyList(); 60 | } else { 61 | return Arrays.asList(formats); 62 | } 63 | } 64 | 65 | /** 66 | * Returns whether a specified format is supported for output. 67 | * 68 | * @param format The format to check whether it is supported or not. 69 | * @return {@code true} if the format is supported, {@code false} 70 | * otherwise. 71 | */ 72 | public static boolean isSupportedOutputFormat(String format) 73 | { 74 | if (format == ThumbnailParameter.ORIGINAL_FORMAT) { 75 | return true; 76 | } 77 | 78 | for (String supportedFormat : getSupportedOutputFormats()) { 79 | if (supportedFormat.equalsIgnoreCase(format)) { 80 | return true; 81 | } 82 | } 83 | 84 | return false; 85 | } 86 | 87 | /** 88 | * Returns a {@link List} of supported output formats types for a specified 89 | * output format. 90 | * 91 | * @param format The output format. 92 | * @return A {@link List} of supported output formats types. If no 93 | * formats types are supported, or if compression is not 94 | * supported for the specified format, then an empty list 95 | * is returned. 96 | */ 97 | public static List getSupportedOutputFormatTypes(String format) { 98 | if (format == ThumbnailParameter.ORIGINAL_FORMAT) { 99 | return Collections.emptyList(); 100 | } 101 | 102 | Iterator writers = ImageIO.getImageWritersByFormatName(format); 103 | if (!writers.hasNext()) { 104 | return Collections.emptyList(); 105 | } 106 | 107 | String[] types; 108 | try { 109 | types = writers.next().getDefaultWriteParam().getCompressionTypes(); 110 | } catch (UnsupportedOperationException e) { 111 | return Collections.emptyList(); 112 | } 113 | 114 | if (types == null) { 115 | return Collections.emptyList(); 116 | } else { 117 | return Arrays.asList(types); 118 | } 119 | } 120 | 121 | /** 122 | * Returns whether a specified format type is supported for a specified 123 | * output format. 124 | * 125 | * @param format The format to check whether it is supported or not. 126 | * @param type The format type to check whether it is supported or not. 127 | * @return {@code true} if the format type is supported by the 128 | * specified supported format, {@code false} otherwise. 129 | */ 130 | public static boolean isSupportedOutputFormatType(String format, String type) { 131 | if (!isSupportedOutputFormat(format)) { 132 | return false; 133 | } 134 | 135 | if (format == ThumbnailParameter.ORIGINAL_FORMAT 136 | && type == ThumbnailParameter.DEFAULT_FORMAT_TYPE) { 137 | return true; 138 | 139 | } else if (format == ThumbnailParameter.ORIGINAL_FORMAT 140 | && type != ThumbnailParameter.DEFAULT_FORMAT_TYPE) { 141 | return false; 142 | 143 | } else if (type == ThumbnailParameter.DEFAULT_FORMAT_TYPE) { 144 | return true; 145 | } 146 | 147 | for (String supportedType : getSupportedOutputFormatTypes(format)) { 148 | if (supportedType.equals(type)) { 149 | return true; 150 | } 151 | } 152 | 153 | return false; 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/util/exif/ExifFilterUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2022 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.util.exif; 26 | 27 | import net.coobird.thumbnailator.filters.Flip; 28 | import net.coobird.thumbnailator.filters.ImageFilter; 29 | import net.coobird.thumbnailator.filters.Pipeline; 30 | import net.coobird.thumbnailator.filters.Rotation; 31 | import net.coobird.thumbnailator.filters.SwapDimensions; 32 | 33 | /** 34 | * An utility class which returns a suitable {@link ImageFilter} to perform 35 | * the transformations necessary to properly orient an image according to the 36 | * Exif metadata. 37 | * 38 | * @author coobird 39 | * 40 | */ 41 | public final class ExifFilterUtils { 42 | /** 43 | * This class should not be instantiated. 44 | */ 45 | private ExifFilterUtils() {}; 46 | 47 | /** 48 | * Returns a {@link ImageFilter} which will perform the transformations 49 | * required to properly orient the thumbnail according to the Exif 50 | * orientation. 51 | * 52 | * @param orientation The Exif orientation 53 | * @return {@link ImageFilter}s required to properly 54 | * orient the image. 55 | */ 56 | public static ImageFilter getFilterForOrientation(Orientation orientation) { 57 | Pipeline filters = new Pipeline(); 58 | 59 | if (orientation == Orientation.TOP_RIGHT) { 60 | filters.add(Flip.HORIZONTAL); 61 | 62 | } else if (orientation == Orientation.BOTTOM_RIGHT) { 63 | filters.add(Rotation.ROTATE_180_DEGREES); 64 | 65 | } else if (orientation == Orientation.BOTTOM_LEFT) { 66 | filters.add(Rotation.ROTATE_180_DEGREES); 67 | filters.add(Flip.HORIZONTAL); 68 | 69 | } else if (orientation == Orientation.LEFT_TOP) { 70 | filters.add(Rotation.RIGHT_90_DEGREES); 71 | filters.add(Flip.HORIZONTAL); 72 | filters.add(SwapDimensions.getInstance()); 73 | 74 | } else if (orientation == Orientation.RIGHT_TOP) { 75 | filters.add(Rotation.RIGHT_90_DEGREES); 76 | filters.add(SwapDimensions.getInstance()); 77 | 78 | } else if (orientation == Orientation.RIGHT_BOTTOM) { 79 | filters.add(Rotation.LEFT_90_DEGREES); 80 | filters.add(Flip.HORIZONTAL); 81 | filters.add(SwapDimensions.getInstance()); 82 | 83 | } else if (orientation == Orientation.LEFT_BOTTOM) { 84 | filters.add(Rotation.LEFT_90_DEGREES); 85 | filters.add(SwapDimensions.getInstance()); 86 | } 87 | 88 | return filters; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/util/exif/IfdType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.util.exif; 26 | 27 | /** 28 | * This enum corresponds to the types of data present in an IFD, 29 | * as defined in Section 4.6.2 of the Exif Specification version 2.3. 30 | * 31 | * @author coobird 32 | * 33 | */ 34 | public enum IfdType 35 | { 36 | /** 37 | * An 8-bit unsigned integer value. 38 | */ 39 | BYTE(1, 1), 40 | 41 | /** 42 | * An 8-bit value containing a single 7-bit ASCII character. 43 | * The final byte is NULL-terminated. 44 | */ 45 | ASCII(2, 1), 46 | 47 | /** 48 | * A 16-bit unsigned integer value. 49 | */ 50 | SHORT(3, 2), 51 | 52 | /** 53 | * A 32-bit unsigned integer value. 54 | */ 55 | LONG(4, 4), 56 | 57 | /** 58 | * Two {@link #LONG} values, where the first {@code LONG} is the 59 | * numerator, while the second {@code LONG} is the denominator. 60 | */ 61 | RATIONAL(5, LONG.size() * 2), 62 | 63 | /** 64 | * An 8-bit value which can be value as defined elsewhere. 65 | */ 66 | UNDEFINED(7, 1), 67 | 68 | /** 69 | * A 32-bit signed integer value using 2's complement. 70 | */ 71 | SLONG(9, 4), 72 | 73 | /** 74 | * Two {@link #SLONG} values, where the first {@code SLONG} is the 75 | * numerator, while the second {@code SLONG} is the denominator. 76 | */ 77 | SRATIONAL(10, SLONG.size() * 2), 78 | ; 79 | 80 | private int value; 81 | private int size; 82 | 83 | private IfdType(int value, int size) 84 | { 85 | this.value = value; 86 | this.size = size; 87 | } 88 | 89 | /** 90 | * Returns the size in bytes for this IFD type. 91 | * @return Size in bytes for this IFD type. 92 | */ 93 | public int size() 94 | { 95 | return size; 96 | } 97 | 98 | /** 99 | * Returns the IFD type as a type value. 100 | * @return IFD type as a type value. 101 | */ 102 | public int value() 103 | { 104 | return value; 105 | } 106 | 107 | /** 108 | * Returns the {@link IfdType} corresponding to the given IFD type value. 109 | * 110 | * @param value The IFD type value. 111 | * @return {@link IfdType} corresponding to the IDF type value. 112 | * Return {@code null} if the given value does not 113 | * correspond to a valid {@link IfdType}. 114 | */ 115 | public static IfdType typeOf(int value) 116 | { 117 | for (IfdType type : IfdType.values()) 118 | { 119 | if (type.value == value) 120 | { 121 | return type; 122 | } 123 | } 124 | 125 | return null; 126 | } 127 | 128 | /** 129 | * Returns a textual {@link String} reprensentation of this enum. 130 | * @return A textual representation of this enum. 131 | */ 132 | @Override 133 | public String toString() 134 | { 135 | return "IfdType [type=" + this.name() + ", value=" + value + ", size=" + size + "]"; 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/util/exif/Orientation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.util.exif; 26 | 27 | /** 28 | * Representation for the Orientation (Tag 274) in the Exif metadata, as 29 | * defined in Section 4.6.4 of the Exif Specification version 2.3. 30 | * 31 | * @author coobird 32 | * 33 | */ 34 | public enum Orientation 35 | { 36 | /** 37 | * Orientation 1. 38 | *
    39 | *
  • First row: visual top of the image
  • 40 | *
  • First column: visual left-hand side of the image
  • 41 | *
42 | */ 43 | TOP_LEFT(1), 44 | 45 | /** 46 | * Orientation 2. 47 | *
    48 | *
  • First row: visual top of the image
  • 49 | *
  • First column: visual right-hand side of the image
  • 50 | *
51 | */ 52 | TOP_RIGHT(2), 53 | 54 | /** 55 | * Orientation 3. 56 | *
    57 | *
  • First row: visual bottom of the image
  • 58 | *
  • First column: visual right-hand side of the image
  • 59 | *
60 | */ 61 | BOTTOM_RIGHT(3), 62 | 63 | /** 64 | * Orientation 4. 65 | *
    66 | *
  • First row: visual bottom of the image
  • 67 | *
  • First column: visual left-hand side of the image
  • 68 | *
69 | */ 70 | BOTTOM_LEFT(4), 71 | 72 | /** 73 | * Orientation 5. 74 | *
    75 | *
  • First row: visual left-hand side of the image
  • 76 | *
  • First column: visual top of the image
  • 77 | *
78 | */ 79 | LEFT_TOP(5), 80 | 81 | /** 82 | * Orientation 6. 83 | *
    84 | *
  • First row: visual right-hand side of the image
  • 85 | *
  • First column: visual top of the image
  • 86 | *
87 | */ 88 | RIGHT_TOP(6), 89 | 90 | /** 91 | * Orientation 7. 92 | *
    93 | *
  • First row: visual right-hand side of the image
  • 94 | *
  • First column: visual bottom of the image
  • 95 | *
96 | */ 97 | RIGHT_BOTTOM(7), 98 | 99 | /** 100 | * Orientation 8. 101 | *
    102 | *
  • First row: visual left-hand side of the image
  • 103 | *
  • First column: visual bottom of the image
  • 104 | *
105 | */ 106 | LEFT_BOTTOM(8), 107 | ; 108 | 109 | private int value; 110 | private Orientation(int value) 111 | { 112 | this.value = value; 113 | } 114 | 115 | /** 116 | * Returns the {@link Orientation} corresponding to the given orientation 117 | * value. 118 | * 119 | * @param value The orientation value. 120 | * @return {@link Orientation} corresponding to the orientation 121 | * value. Return {@code null} if the given value does not 122 | * correspond to a valid {@link Orientation}. 123 | */ 124 | public static Orientation typeOf(int value) 125 | { 126 | for (Orientation orientation : Orientation.values()) 127 | { 128 | if (orientation.value == value) 129 | { 130 | return orientation; 131 | } 132 | } 133 | 134 | return null; 135 | } 136 | 137 | /** 138 | * Returns a textual {@link String} reprensentation of this enum. 139 | * @return A textual representation of this enum. 140 | */ 141 | @Override 142 | public String toString() 143 | { 144 | return "Orientation [type=" + value + "]"; 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/util/exif/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * This package contains utilities classes used to handle Exif metadata. 27 | */ 28 | package net.coobird.thumbnailator.util.exif; 29 | -------------------------------------------------------------------------------- /src/main/java/net/coobird/thumbnailator/util/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * This package contains utilities classes used by Thumbnailator. 27 | */ 28 | package net.coobird.thumbnailator.util; 29 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2008-2023 Chris Kroells 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/test/java/net/coobird/thumbnailator/TestUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2022 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator; 26 | 27 | import org.junit.rules.TemporaryFolder; 28 | 29 | import java.awt.image.BufferedImage; 30 | import java.io.File; 31 | import java.io.FileInputStream; 32 | import java.io.FileOutputStream; 33 | import java.io.IOException; 34 | import java.io.InputStream; 35 | import java.net.URL; 36 | 37 | import javax.imageio.ImageIO; 38 | 39 | public class TestUtils { 40 | /** 41 | * Copies a specified length of the source file. 42 | * 43 | * @param sourceFile The source file. 44 | * @param destFile The destination file. 45 | * @param length Length of source file to copy. 46 | * @throws IOException If an IOException is thrown. 47 | */ 48 | public static void copyFile(File sourceFile, File destFile, long length) throws IOException { 49 | FileInputStream fis = new FileInputStream(sourceFile); 50 | FileOutputStream fos = new FileOutputStream(destFile); 51 | fis.getChannel().transferTo(0, length, fos.getChannel()); 52 | fis.close(); 53 | fos.close(); 54 | } 55 | 56 | /** 57 | * Copies a file. 58 | * 59 | * @param sourceFile The source file. 60 | * @param destFile The destination file. 61 | * @throws IOException If an IOException is thrown. 62 | */ 63 | public static void copyFile(File sourceFile, File destFile) throws IOException { 64 | copyFile(sourceFile, destFile, sourceFile.length()); 65 | } 66 | 67 | /** 68 | * Returns the format of an image which is read through the {@link InputStream}. 69 | * 70 | * @param is The {@link InputStream} to an image. 71 | * @return File format of the image. 72 | * @throws IOException 73 | */ 74 | public static String getFormatName(InputStream is) throws IOException { 75 | return ImageIO.getImageReaders( 76 | ImageIO.createImageInputStream(is) 77 | ).next().getFormatName(); 78 | } 79 | 80 | public static URL getResource(String resourceName) throws IOException { 81 | URL url = ClassLoader.getSystemClassLoader().getResource(resourceName); 82 | if (url == null) { 83 | throw new IOException("Resource not found: " + resourceName); 84 | } 85 | return url; 86 | } 87 | 88 | public static InputStream getResourceStream(String resourceName) throws IOException { 89 | InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream(resourceName); 90 | if (is == null) { 91 | throw new IOException("Resource not found: " + resourceName); 92 | } 93 | return is; 94 | } 95 | 96 | public static File copyResourceToFile(String resourceName, File destination) throws IOException { 97 | InputStream is = getResourceStream(resourceName); 98 | FileOutputStream fos = new FileOutputStream(destination); 99 | 100 | byte[] buffer; 101 | int bytesAvailable; 102 | while ((bytesAvailable = is.available()) != 0) { 103 | buffer = new byte[bytesAvailable]; 104 | int bytesRead = is.read(buffer, 0, buffer.length); 105 | fos.write(buffer, 0, bytesRead); 106 | } 107 | is.close(); 108 | fos.close(); 109 | 110 | return destination; 111 | } 112 | 113 | public static File copyResourceToTemporaryFile(String resourceName, TemporaryFolder folder) throws IOException { 114 | String name; 115 | if (resourceName.contains("/")) { 116 | name = resourceName.substring(resourceName.lastIndexOf("/") + 1); 117 | } else { 118 | name = resourceName; 119 | } 120 | File destination = folder.newFile(name); 121 | 122 | return copyResourceToFile(resourceName, destination); 123 | } 124 | 125 | public static File copyResourceToTemporaryFile(String resourceName, String namedAs, TemporaryFolder folder) throws IOException { 126 | return copyResourceToFile(resourceName, folder.newFile(namedAs)); 127 | } 128 | 129 | public static BufferedImage getImageFromResource(String resourceName) throws IOException { 130 | InputStream is = getResourceStream(resourceName); 131 | try { 132 | return ImageIO.read(is); 133 | } finally { 134 | is.close(); 135 | } 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /src/test/java/net/coobird/thumbnailator/filters/CaptionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.filters; 26 | 27 | import static net.coobird.thumbnailator.filters.ImageFilterTestUtils.assertImageTypeRetained; 28 | import static org.junit.Assert.*; 29 | 30 | import java.awt.Color; 31 | import java.awt.Font; 32 | import java.awt.image.BufferedImage; 33 | 34 | import net.coobird.thumbnailator.geometry.Position; 35 | import net.coobird.thumbnailator.geometry.Positions; 36 | import net.coobird.thumbnailator.test.BufferedImageComparer; 37 | import net.coobird.thumbnailator.util.BufferedImages; 38 | 39 | import org.junit.Test; 40 | 41 | /** 42 | * Tests for the {@link Caption} filter. 43 | * 44 | * @author coobird 45 | * 46 | */ 47 | public class CaptionTest { 48 | 49 | private static final String DEFAULT_CAPTION = "hello"; 50 | private static final Font DEFAULT_FONT = new Font("Monospaced", Font.PLAIN, 14); 51 | private static final Color DEFAULT_COLOR = Color.black; 52 | private static final Position DEFAULT_POSITION = Positions.BOTTOM_CENTER; 53 | 54 | /** 55 | * Checks that the input image contents are not altered. 56 | */ 57 | @Test 58 | public void inputContentsAreNotAltered() { 59 | // given 60 | BufferedImage originalImage = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB); 61 | BufferedImage copyImage = BufferedImages.copy(originalImage); 62 | 63 | ImageFilter filter = new Caption( 64 | DEFAULT_CAPTION, 65 | DEFAULT_FONT, 66 | DEFAULT_COLOR, 67 | DEFAULT_POSITION, 68 | 0 69 | ); 70 | 71 | // when 72 | filter.apply(originalImage); 73 | 74 | // then 75 | assertTrue(BufferedImageComparer.isSame(originalImage, copyImage)); 76 | } 77 | 78 | @Test 79 | public void imageTypeForInputAndOutputIsTheSame() { 80 | ImageFilter filter = new Caption( 81 | DEFAULT_CAPTION, 82 | DEFAULT_FONT, 83 | DEFAULT_COLOR, 84 | DEFAULT_POSITION, 85 | 0 86 | ); 87 | 88 | assertImageTypeRetained(filter); 89 | } 90 | 91 | @Test(expected = NullPointerException.class) 92 | public void constructorNullCheckForCaption() { 93 | new Caption( 94 | null, 95 | DEFAULT_FONT, 96 | DEFAULT_COLOR, 97 | DEFAULT_POSITION, 98 | 0 99 | ); 100 | } 101 | 102 | @Test(expected = NullPointerException.class) 103 | public void constructorNullCheckForFont() { 104 | new Caption( 105 | DEFAULT_CAPTION, 106 | null, 107 | DEFAULT_COLOR, 108 | DEFAULT_POSITION, 109 | 0 110 | ); 111 | } 112 | 113 | @Test(expected = NullPointerException.class) 114 | public void constructorNullCheckForColor() { 115 | new Caption( 116 | DEFAULT_CAPTION, 117 | DEFAULT_FONT, 118 | null, 119 | DEFAULT_POSITION, 120 | 0 121 | ); 122 | } 123 | 124 | @Test(expected = NullPointerException.class) 125 | public void constructorNullCheckForPosition() { 126 | new Caption( 127 | DEFAULT_CAPTION, 128 | DEFAULT_FONT, 129 | DEFAULT_COLOR, 130 | null, 131 | 0 132 | ); 133 | } 134 | 135 | @Test 136 | public void constructorAllowsPositiveInsets() { 137 | new Caption( 138 | DEFAULT_CAPTION, 139 | DEFAULT_FONT, 140 | DEFAULT_COLOR, 141 | DEFAULT_POSITION, 142 | 10 143 | ); 144 | } 145 | 146 | @Test(expected = IllegalArgumentException.class) 147 | public void constructorRejectsNegativeInsets() { 148 | new Caption( 149 | DEFAULT_CAPTION, 150 | DEFAULT_FONT, 151 | DEFAULT_COLOR, 152 | DEFAULT_POSITION, 153 | -1 154 | ); 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /src/test/java/net/coobird/thumbnailator/filters/ColorizeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.filters; 26 | 27 | import static net.coobird.thumbnailator.filters.ImageFilterTestUtils.assertImageTypeRetained; 28 | import static org.junit.Assert.*; 29 | 30 | import java.awt.Color; 31 | import java.awt.image.BufferedImage; 32 | 33 | import net.coobird.thumbnailator.test.BufferedImageComparer; 34 | import net.coobird.thumbnailator.util.BufferedImages; 35 | 36 | import org.junit.Test; 37 | 38 | /** 39 | * Tests for the {@link Colorize} filter. 40 | * 41 | * @author coobird 42 | * 43 | */ 44 | public class ColorizeTest { 45 | 46 | /** 47 | * Checks that the input image contents are not altered. 48 | */ 49 | @Test 50 | public void inputContentsAreNotAltered() { 51 | // given 52 | BufferedImage originalImage = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB); 53 | BufferedImage copyImage = BufferedImages.copy(originalImage); 54 | 55 | ImageFilter filter = new Colorize(Color.blue); 56 | 57 | // when 58 | filter.apply(originalImage); 59 | 60 | // then 61 | assertTrue(BufferedImageComparer.isSame(originalImage, copyImage)); 62 | } 63 | 64 | /** 65 | * Checks that the input image contents are not altered for constructor with alpha. 66 | */ 67 | @Test 68 | public void inputContentsAreNotAltered_alphaConstructor() { 69 | // given 70 | BufferedImage originalImage = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB); 71 | BufferedImage copyImage = BufferedImages.copy(originalImage); 72 | 73 | ImageFilter filter = new Colorize(Color.blue, 0.5f); 74 | 75 | // when 76 | filter.apply(originalImage); 77 | 78 | // then 79 | assertTrue(BufferedImageComparer.isSame(originalImage, copyImage)); 80 | } 81 | 82 | @Test 83 | public void imageTypeForInputAndOutputIsTheSame() { 84 | assertImageTypeRetained(new Colorize(Color.blue)); 85 | } 86 | 87 | @Test 88 | public void imageTypeForInputAndOutputIsTheSame_alphaConstructor() { 89 | assertImageTypeRetained(new Colorize(Color.blue, 0.5f)); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/test/java/net/coobird/thumbnailator/filters/FlipTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2022 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.filters; 26 | 27 | import static net.coobird.thumbnailator.TestUtils.getImageFromResource; 28 | import static net.coobird.thumbnailator.filters.ImageFilterTestUtils.assertImageTypeRetained; 29 | import static org.junit.Assert.assertTrue; 30 | 31 | import java.awt.image.BufferedImage; 32 | 33 | import net.coobird.thumbnailator.test.BufferedImageAssert; 34 | import net.coobird.thumbnailator.test.BufferedImageComparer; 35 | import net.coobird.thumbnailator.util.BufferedImages; 36 | 37 | import org.junit.Test; 38 | 39 | public class FlipTest { 40 | 41 | @Test 42 | public void flipHorizontal() throws Exception { 43 | // given 44 | BufferedImage img = getImageFromResource("Exif/original.png"); 45 | 46 | // when 47 | BufferedImage result = Flip.HORIZONTAL.apply(img); 48 | 49 | // then 50 | BufferedImageAssert.assertMatches( 51 | result, 52 | new float[] { 53 | 1, 1, 1, 54 | 1, 1, 1, 55 | 0, 0, 1, 56 | } 57 | ); 58 | } 59 | 60 | @Test 61 | public void flipVertical() throws Exception { 62 | // given 63 | BufferedImage img = getImageFromResource("Exif/original.png"); 64 | 65 | // when 66 | BufferedImage result = Flip.VERTICAL.apply(img); 67 | 68 | // then 69 | BufferedImageAssert.assertMatches( 70 | result, 71 | new float[] { 72 | 1, 0, 0, 73 | 1, 1, 1, 74 | 1, 1, 1, 75 | } 76 | ); 77 | } 78 | 79 | /** 80 | * Checks that the input image contents are not altered, when using the 81 | * {@link Flip#HORIZONTAL}. 82 | */ 83 | @Test 84 | public void inputContentsAreNotAltered_UsingFlipHorizontal() { 85 | // given 86 | BufferedImage originalImage = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB); 87 | BufferedImage copyImage = BufferedImages.copy(originalImage); 88 | 89 | ImageFilter filter = Flip.HORIZONTAL; 90 | 91 | // when 92 | filter.apply(originalImage); 93 | 94 | // then 95 | assertTrue(BufferedImageComparer.isSame(originalImage, copyImage)); 96 | } 97 | 98 | /** 99 | * Checks that the input image contents are not altered, when using the 100 | * {@link Flip#VERTICAL}. 101 | */ 102 | @Test 103 | public void inputContentsAreNotAltered_UsingFlipVertical() { 104 | // given 105 | BufferedImage originalImage = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB); 106 | BufferedImage copyImage = BufferedImages.copy(originalImage); 107 | 108 | ImageFilter filter = Flip.VERTICAL; 109 | 110 | // when 111 | filter.apply(originalImage); 112 | 113 | // then 114 | assertTrue(BufferedImageComparer.isSame(originalImage, copyImage)); 115 | } 116 | 117 | @Test 118 | public void imageTypeForInputAndOutputIsTheSame_UsingFlipHorizontal() { 119 | assertImageTypeRetained(Flip.HORIZONTAL); 120 | } 121 | 122 | @Test 123 | public void imageTypeForInputAndOutputIsTheSame_UsingFlipVertical() { 124 | assertImageTypeRetained(Flip.VERTICAL); 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /src/test/java/net/coobird/thumbnailator/filters/ImageFilterTestUtils.java: -------------------------------------------------------------------------------- 1 | package net.coobird.thumbnailator.filters; 2 | 3 | import java.awt.image.BufferedImage; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | 7 | public class ImageFilterTestUtils { 8 | private static final int[] IMAGE_TYPES = new int[] { 9 | BufferedImage.TYPE_INT_ARGB, 10 | BufferedImage.TYPE_INT_RGB, 11 | BufferedImage.TYPE_BYTE_GRAY, 12 | BufferedImage.TYPE_BYTE_INDEXED, 13 | BufferedImage.TYPE_3BYTE_BGR, 14 | BufferedImage.TYPE_4BYTE_ABGR, 15 | BufferedImage.TYPE_4BYTE_ABGR_PRE, 16 | BufferedImage.TYPE_BYTE_BINARY, 17 | BufferedImage.TYPE_INT_ARGB_PRE, 18 | BufferedImage.TYPE_INT_BGR, 19 | BufferedImage.TYPE_USHORT_555_RGB, 20 | BufferedImage.TYPE_USHORT_565_RGB, 21 | BufferedImage.TYPE_USHORT_GRAY 22 | }; 23 | 24 | public static void assertImageTypeRetained(ImageFilter filter) { 25 | for (int bufferedImageType : IMAGE_TYPES) { 26 | // given 27 | BufferedImage originalImage = new BufferedImage(200, 200, bufferedImageType); 28 | 29 | // when 30 | BufferedImage finalImage = filter.apply(originalImage); 31 | 32 | // then 33 | assertEquals(originalImage.getType(), finalImage.getType()); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/net/coobird/thumbnailator/filters/TransparencyTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.filters; 26 | 27 | import static net.coobird.thumbnailator.filters.ImageFilterTestUtils.assertImageTypeRetained; 28 | import static org.junit.Assert.*; 29 | 30 | import java.awt.image.BufferedImage; 31 | 32 | import net.coobird.thumbnailator.test.BufferedImageComparer; 33 | import net.coobird.thumbnailator.util.BufferedImages; 34 | 35 | import org.junit.Test; 36 | 37 | /** 38 | * Tests for the {@link Transparency} filter. 39 | * 40 | * @author coobird 41 | * 42 | */ 43 | public class TransparencyTest { 44 | 45 | /** 46 | * Checks that the input image contents are not altered, when using the 47 | * {@link Transparency#Transparency(double)} constructor. 48 | */ 49 | @Test 50 | public void inputContentsAreNotAltered_DoubleConstructor() { 51 | // given 52 | BufferedImage originalImage = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB); 53 | BufferedImage copyImage = BufferedImages.copy(originalImage); 54 | 55 | ImageFilter filter = new Transparency(0.5); 56 | 57 | // when 58 | filter.apply(originalImage); 59 | 60 | // then 61 | assertTrue(BufferedImageComparer.isSame(originalImage, copyImage)); 62 | } 63 | 64 | /** 65 | * Checks that the input image contents are not altered, when using the 66 | * {@link Transparency#Transparency(float)} constructor. 67 | */ 68 | @Test 69 | public void inputContentsAreNotAltered_FloatConstructor() { 70 | // given 71 | BufferedImage originalImage = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB); 72 | BufferedImage copyImage = BufferedImages.copy(originalImage); 73 | 74 | ImageFilter filter = new Transparency(0.5f); 75 | 76 | // when 77 | filter.apply(originalImage); 78 | 79 | // then 80 | assertTrue(BufferedImageComparer.isSame(originalImage, copyImage)); 81 | } 82 | 83 | @Test 84 | public void imageTypeForInputAndOutputIsTheSame_DoubleConstructor() { 85 | assertImageTypeRetained(new Transparency(0.5)); 86 | } 87 | 88 | @Test 89 | public void imageTypeForInputAndOutputIsTheSame_FloatConstructor() { 90 | assertImageTypeRetained(new Transparency(0.5f)); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/test/java/net/coobird/thumbnailator/resizers/NullResizerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2022 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.resizers; 26 | 27 | import java.awt.image.BufferedImage; 28 | import java.io.IOException; 29 | 30 | import net.coobird.thumbnailator.test.BufferedImageComparer; 31 | 32 | import org.junit.Test; 33 | 34 | import static net.coobird.thumbnailator.TestUtils.getImageFromResource; 35 | import static org.junit.Assert.*; 36 | 37 | public class NullResizerTest { 38 | 39 | @Test 40 | public void sourceAndDestSameDimension() throws IOException { 41 | // given 42 | BufferedImage srcImage = getImageFromResource("Thumbnailator/grid.png"); 43 | BufferedImage destImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB); 44 | 45 | // when 46 | new NullResizer().resize(srcImage, destImage); 47 | 48 | // then 49 | assertEquals(srcImage.getWidth(), destImage.getWidth()); 50 | assertEquals(srcImage.getHeight(), destImage.getHeight()); 51 | assertTrue(BufferedImageComparer.isRGBSimilar(srcImage, destImage)); 52 | } 53 | 54 | @Test 55 | public void sourceSmallerThanDest() throws IOException { 56 | // given 57 | BufferedImage srcImage = getImageFromResource("Thumbnailator/grid.png"); 58 | BufferedImage destImage = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB); 59 | 60 | // when 61 | new NullResizer().resize(srcImage, destImage); 62 | 63 | // then 64 | assertTrue(BufferedImageComparer.isRGBSimilar(srcImage, destImage.getSubimage(0, 0, 100, 100))); 65 | } 66 | 67 | @Test 68 | public void sourceLargerThanDest() throws IOException { 69 | // given 70 | BufferedImage srcImage = getImageFromResource("Thumbnailator/grid.png"); 71 | BufferedImage destImage = new BufferedImage(50, 50, BufferedImage.TYPE_INT_ARGB); 72 | 73 | // when 74 | new NullResizer().resize(srcImage, destImage); 75 | 76 | // then 77 | assertTrue(BufferedImageComparer.isRGBSimilar(srcImage.getSubimage(0, 0, 50, 50), destImage)); 78 | } 79 | 80 | @Test 81 | public void resizeNullAndNull() { 82 | // given 83 | BufferedImage srcImage = null; 84 | BufferedImage destImage = null; 85 | 86 | try { 87 | // when 88 | new NullResizer().resize(srcImage, destImage); 89 | fail(); 90 | } catch (Exception e) { 91 | // then 92 | assertEquals("The source and/or destination image is null.", e.getMessage()); 93 | } 94 | } 95 | 96 | @Test 97 | public void resizeSpecifiedAndNull() { 98 | // given 99 | BufferedImage srcImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB); 100 | BufferedImage destImage = null; 101 | 102 | try { 103 | // when 104 | new NullResizer().resize(srcImage, destImage); 105 | fail(); 106 | } catch (Exception e) { 107 | // then 108 | assertEquals("The source and/or destination image is null.", e.getMessage()); 109 | } 110 | } 111 | 112 | @Test 113 | public void resizeNullAndSpecified() { 114 | // given 115 | BufferedImage srcImage = null; 116 | BufferedImage destImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB); 117 | 118 | try { 119 | // when 120 | new NullResizer().resize(srcImage, destImage); 121 | fail(); 122 | } catch (Exception e) { 123 | // then 124 | assertEquals("The source and/or destination image is null.", e.getMessage()); 125 | } 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /src/test/java/net/coobird/thumbnailator/resizers/ProgressiveBilinearResizerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.resizers; 26 | 27 | import static org.junit.Assert.*; 28 | 29 | import java.awt.image.BufferedImage; 30 | import java.io.IOException; 31 | 32 | import org.junit.Test; 33 | 34 | public class ProgressiveBilinearResizerTest { 35 | 36 | /** 37 | * Test for 38 | * {@link ProgressiveBilinearResizer#resize(BufferedImage, BufferedImage)} 39 | * where, 40 | * 41 | * 1) source image is null. 42 | * 2) destination image is null. 43 | * 44 | * Expected outcome is, 45 | * 46 | * 1) Processing will stop with an NullPointerException. 47 | * 48 | * @throws IOException 49 | */ 50 | @Test(expected=NullPointerException.class) 51 | public void resizeNullAndNull() { 52 | BufferedImage srcImage = null; 53 | BufferedImage destImage = null; 54 | 55 | new ProgressiveBilinearResizer().resize(srcImage, destImage); 56 | 57 | fail(); 58 | } 59 | 60 | /** 61 | * Test for 62 | * {@link ProgressiveBilinearResizer#resize(BufferedImage, BufferedImage)} 63 | * where, 64 | * 65 | * 1) source image is specified. 66 | * 2) destination image is null. 67 | * 68 | * Expected outcome is, 69 | * 70 | * 1) Processing will stop with an NullPointerException. 71 | * 72 | * @throws IOException 73 | */ 74 | @Test(expected=NullPointerException.class) 75 | public void resizeSpecifiedAndNull() { 76 | BufferedImage srcImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB); 77 | BufferedImage destImage = null; 78 | 79 | new ProgressiveBilinearResizer().resize(srcImage, destImage); 80 | 81 | fail(); 82 | } 83 | 84 | /** 85 | * Test for 86 | * {@link ProgressiveBilinearResizer#resize(BufferedImage, BufferedImage)} 87 | * where, 88 | * 89 | * 1) source image is null. 90 | * 2) destination image is specified. 91 | * 92 | * Expected outcome is, 93 | * 94 | * 1) Processing will stop with an NullPointerException. 95 | * 96 | * @throws IOException 97 | */ 98 | @Test(expected=NullPointerException.class) 99 | public void resizeNullAndSpecified() { 100 | BufferedImage srcImage = null; 101 | BufferedImage destImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB); 102 | 103 | new ProgressiveBilinearResizer().resize(srcImage, destImage); 104 | 105 | fail(); 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /src/test/java/net/coobird/thumbnailator/tasks/io/BufferedImageSinkTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.tasks.io; 26 | 27 | import java.awt.image.BufferedImage; 28 | import java.io.IOException; 29 | 30 | import org.junit.Test; 31 | import static org.junit.Assert.*; 32 | 33 | public class BufferedImageSinkTest { 34 | @Test 35 | public void writeImage() throws IOException { 36 | // given 37 | BufferedImage img = 38 | new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB); 39 | 40 | // when 41 | BufferedImageSink sink = new BufferedImageSink(); 42 | sink.write(img); 43 | 44 | // then 45 | assertSame(img, sink.getSink()); 46 | } 47 | 48 | @Test(expected=NullPointerException.class) 49 | public void writeNull() throws IOException { 50 | // given 51 | BufferedImage img = null; 52 | 53 | try { 54 | // when 55 | new BufferedImageSink().write(img); 56 | fail(); 57 | } catch (NullPointerException e) { 58 | // then 59 | assertEquals("Cannot write a null image.", e.getMessage()); 60 | throw e; 61 | } 62 | } 63 | 64 | @Test(expected=IllegalStateException.class) 65 | public void getSink_BeforeWrite() throws IOException { 66 | // given 67 | 68 | try { 69 | // when 70 | new BufferedImageSink().getSink(); 71 | fail(); 72 | } catch (IllegalStateException e) { 73 | // then 74 | assertEquals("BufferedImageSink has not been written to yet.", e.getMessage()); 75 | throw e; 76 | } 77 | } 78 | 79 | @Test 80 | public void setOutputFormatName_DoesntAffectAnything() throws IOException { 81 | // given 82 | BufferedImageSink sink0 = new BufferedImageSink(); 83 | BufferedImageSink sink1 = new BufferedImageSink(); 84 | 85 | BufferedImage img = 86 | new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB); 87 | 88 | // when 89 | sink0.setOutputFormatName("PNG"); 90 | 91 | sink0.write(img); 92 | sink1.write(img); 93 | 94 | // then 95 | assertSame(img, sink0.getSink()); 96 | assertSame(img, sink1.getSink()); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/test/java/net/coobird/thumbnailator/tasks/io/InputStreamImageSourceMalformedTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2021 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.tasks.io; 26 | 27 | import org.junit.After; 28 | import org.junit.Before; 29 | import org.junit.Test; 30 | import org.junit.runner.RunWith; 31 | import org.junit.runners.Parameterized; 32 | 33 | import java.io.ByteArrayInputStream; 34 | import java.io.InputStream; 35 | import java.util.ArrayList; 36 | import java.util.Arrays; 37 | import java.util.Collection; 38 | import java.util.List; 39 | 40 | @RunWith(Parameterized.class) 41 | public class InputStreamImageSourceMalformedTest { 42 | 43 | @Parameterized.Parameters(name = "type={0}, length={1}") 44 | public static Collection testCases() { 45 | List cases = new ArrayList(); 46 | for (String type : Arrays.asList("jpg", "png", "bmp")) { 47 | for (int i = 1; i <= 40; i++) { 48 | cases.add(new Object[] { type, i }); 49 | } 50 | } 51 | return Arrays.asList(cases.toArray()); 52 | } 53 | 54 | @Parameterized.Parameter 55 | public String type; 56 | 57 | @Parameterized.Parameter(value = 1) 58 | public Integer length; 59 | 60 | @Before @After 61 | public void cleanup() { 62 | System.clearProperty("thumbnailator.disableExifWorkaround"); 63 | } 64 | 65 | @Test 66 | public void terminatesProperlyWithWorkaround() { 67 | runTest(); 68 | } 69 | 70 | @Test 71 | public void terminatesProperlyWithoutWorkaround() { 72 | System.setProperty("thumbnailator.disableExifWorkaround", "true"); 73 | runTest(); 74 | } 75 | 76 | /** 77 | * Test to check that reading an abnormal file won't cause image reading 78 | * to end up in a bad state like in an infinite loop. 79 | */ 80 | private void runTest() { 81 | try { 82 | byte[] bytes = new byte[length]; 83 | InputStream sourceIs = ClassLoader.getSystemResourceAsStream(String.format("Thumbnailator/grid.%s", type)); 84 | sourceIs.read(bytes); 85 | sourceIs.close(); 86 | 87 | ByteArrayInputStream is = new ByteArrayInputStream(bytes); 88 | InputStreamImageSource source = new InputStreamImageSource(is); 89 | 90 | source.read(); 91 | 92 | } catch (Exception e) { 93 | // terminates properly, even if an exception is thrown. 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/test/java/net/coobird/thumbnailator/tasks/io/Issue156OutputStreamImageSinkTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2022 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.tasks.io; 26 | 27 | import net.coobird.thumbnailator.ThumbnailParameter; 28 | import net.coobird.thumbnailator.builders.ThumbnailParameterBuilder; 29 | import org.junit.Rule; 30 | import org.junit.Test; 31 | import org.junit.rules.TemporaryFolder; 32 | 33 | import javax.imageio.ImageIO; 34 | import java.awt.image.BufferedImage; 35 | import java.io.ByteArrayOutputStream; 36 | import java.io.File; 37 | import java.io.IOException; 38 | 39 | import static net.coobird.thumbnailator.TestUtils.copyResourceToTemporaryFile; 40 | import static org.junit.Assert.assertTrue; 41 | 42 | public class Issue156OutputStreamImageSinkTest { 43 | 44 | @Rule 45 | public TemporaryFolder temporaryFolder = new TemporaryFolder(); 46 | 47 | @Test 48 | public void compressedPngDoesntGetLarger() throws IOException { 49 | File originalFile = copyResourceToTemporaryFile("Exif/original.png", temporaryFolder); 50 | BufferedImage originalImage = ImageIO.read(originalFile); 51 | 52 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 53 | OutputStreamImageSink imageSink = new OutputStreamImageSink(baos); 54 | 55 | ThumbnailParameter param = new ThumbnailParameterBuilder() 56 | .scale(1.0) 57 | .build(); 58 | imageSink.setThumbnailParameter(param); 59 | 60 | imageSink.setOutputFormatName("png"); 61 | imageSink.write(originalImage); 62 | 63 | assertTrue(baos.size() < originalFile.length()); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/net/coobird/thumbnailator/test/BufferedImageAssert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Thumbnailator - a thumbnail generation library 3 | * 4 | * Copyright (c) 2008-2020 Chris Kroells 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package net.coobird.thumbnailator.test; 26 | 27 | import static org.junit.Assert.assertEquals; 28 | 29 | import java.awt.Color; 30 | import java.awt.Point; 31 | import java.awt.image.BufferedImage; 32 | import java.util.Arrays; 33 | import java.util.List; 34 | 35 | public class BufferedImageAssert { 36 | 37 | /** 38 | * Checks if the 3x3 pattern matches the given image. 39 | * 40 | * @param img The image to check. 41 | * @param pattern The pattern that should be present. 42 | * @return If the pattern is present in the image. 43 | */ 44 | public static void assertMatches(BufferedImage img, float[] pattern) { 45 | if (pattern.length != 9) { 46 | throw new IllegalArgumentException("Pattern must be of length 9."); 47 | } 48 | 49 | int width = img.getWidth(); 50 | int height = img.getHeight(); 51 | 52 | List points = Arrays.asList( 53 | new Point(0, 0), 54 | new Point(width / 2 - 1, 0), 55 | new Point(width - 1, 0), 56 | new Point(0, height / 2 - 1), 57 | new Point(width / 2 - 1, height / 2 - 1), 58 | new Point(width - 1, height / 2 - 1), 59 | new Point(0, height - 1), 60 | new Point(width / 2 - 1, height - 1), 61 | new Point(width - 1, height - 1) 62 | ); 63 | 64 | for (int i = 0; i < 9; i++) { 65 | Point p = points.get(i); 66 | Color c = pattern[i] == 0 ? Color.white : Color.black; 67 | assertEquals(c.getRGB(), img.getRGB(p.x, p.y)); 68 | } 69 | } 70 | } 71 | 72 | -------------------------------------------------------------------------------- /src/test/java/net/coobird/thumbnailator/util/ConfigurationsTest.java: -------------------------------------------------------------------------------- 1 | package net.coobird.thumbnailator.util; 2 | 3 | import org.junit.*; 4 | import org.junit.experimental.runners.Enclosed; 5 | import org.junit.runner.RunWith; 6 | import org.junit.runner.notification.RunNotifier; 7 | import org.junit.runners.BlockJUnit4ClassRunner; 8 | import org.junit.runners.model.InitializationError; 9 | 10 | import java.net.URL; 11 | import java.net.URLClassLoader; 12 | 13 | import static org.junit.Assert.assertFalse; 14 | import static org.junit.Assert.assertTrue; 15 | 16 | @RunWith(Enclosed.class) 17 | public class ConfigurationsTest { 18 | 19 | @Ignore 20 | private static class Base { 21 | @Before 22 | public void resetConfiguration() { 23 | Configurations.init(); 24 | } 25 | 26 | @AfterClass 27 | public static void clearConfiguration() { 28 | Configurations.clear(); 29 | } 30 | } 31 | 32 | @RunWith(AllTruePropertiesTest.CustomRunner.class) 33 | public static class AllTruePropertiesTest extends Base { 34 | @Test 35 | public void test() { 36 | for (Configurations config : Configurations.values()) { 37 | assertTrue(config.getBoolean()); 38 | } 39 | } 40 | 41 | public static class CustomRunner extends ThreadContextClassLoaderReplacingClassRunner { 42 | public CustomRunner(Class testClass) throws InitializationError { 43 | super(testClass); 44 | } 45 | 46 | protected ClassLoader getCustomClassLoader() { 47 | return new PropertiesFileRedirectingClassLoader("Configurations/all_true.txt"); 48 | } 49 | } 50 | } 51 | 52 | @RunWith(AllFalsePropertiesTest.CustomRunner.class) 53 | public static class AllFalsePropertiesTest extends Base { 54 | @Test 55 | public void test() { 56 | for (Configurations config : Configurations.values()) { 57 | assertFalse(config.getBoolean()); 58 | } 59 | } 60 | 61 | public static class CustomRunner extends ThreadContextClassLoaderReplacingClassRunner { 62 | public CustomRunner(Class testClass) throws InitializationError { 63 | super(testClass); 64 | } 65 | 66 | protected ClassLoader getCustomClassLoader() { 67 | return new PropertiesFileRedirectingClassLoader("Configurations/all_false.txt"); 68 | } 69 | } 70 | } 71 | 72 | public abstract static class ThreadContextClassLoaderReplacingClassRunner extends BlockJUnit4ClassRunner { 73 | public ThreadContextClassLoaderReplacingClassRunner(Class testClass) throws InitializationError { 74 | super(testClass); 75 | } 76 | 77 | protected abstract ClassLoader getCustomClassLoader(); 78 | 79 | @Override 80 | public void run(RunNotifier notifier) { 81 | Thread.currentThread().setContextClassLoader(getCustomClassLoader()); 82 | super.run(notifier); 83 | Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader()); 84 | } 85 | } 86 | 87 | @Ignore 88 | public static class PropertiesFileRedirectingClassLoader extends URLClassLoader { 89 | private final String resourceForPropertiesFile; 90 | 91 | public PropertiesFileRedirectingClassLoader(String resourceForPropertiesFile) { 92 | super(new URL[] {}); 93 | this.resourceForPropertiesFile = resourceForPropertiesFile; 94 | } 95 | 96 | @Override 97 | public URL getResource(String name) { 98 | if (name.startsWith("thumbnailator.properties")) { 99 | return ClassLoader.getSystemClassLoader().getResource(resourceForPropertiesFile); 100 | } 101 | return super.getResource(name); 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/test/resources/Configurations/all_false.txt: -------------------------------------------------------------------------------- 1 | thumbnailator.disableExifWorkaround=false 2 | thumbnailator.debugLog=false 3 | thumbnailator.debugLog.exifWorkaround=false 4 | thumbnailator.conserveMemoryWorkaround=false -------------------------------------------------------------------------------- /src/test/resources/Configurations/all_true.txt: -------------------------------------------------------------------------------- 1 | thumbnailator.disableExifWorkaround=true 2 | thumbnailator.debugLog=true 3 | thumbnailator.debugLog.exifWorkaround=true 4 | thumbnailator.conserveMemoryWorkaround=true -------------------------------------------------------------------------------- /src/test/resources/Exif/fragments/README: -------------------------------------------------------------------------------- 1 | Files here are fragments from adding JFIF segments to "source_2.jpg". 2 | XMP tag is included as it is also a APP1 like Exif. 3 | The Exif reader should cope with XMP properly. -------------------------------------------------------------------------------- /src/test/resources/Exif/fragments/app0.segment: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/fragments/app0.segment -------------------------------------------------------------------------------- /src/test/resources/Exif/fragments/exif.segment: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/fragments/exif.segment -------------------------------------------------------------------------------- /src/test/resources/Exif/fragments/rest: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/fragments/rest -------------------------------------------------------------------------------- /src/test/resources/Exif/fragments/soi.segment: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/fragments/soi.segment -------------------------------------------------------------------------------- /src/test/resources/Exif/fragments/xmp.segment: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/fragments/xmp.segment -------------------------------------------------------------------------------- /src/test/resources/Exif/orientation_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/orientation_1.jpg -------------------------------------------------------------------------------- /src/test/resources/Exif/orientation_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/orientation_2.jpg -------------------------------------------------------------------------------- /src/test/resources/Exif/orientation_3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/orientation_3.jpg -------------------------------------------------------------------------------- /src/test/resources/Exif/orientation_4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/orientation_4.jpg -------------------------------------------------------------------------------- /src/test/resources/Exif/orientation_5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/orientation_5.jpg -------------------------------------------------------------------------------- /src/test/resources/Exif/orientation_6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/orientation_6.jpg -------------------------------------------------------------------------------- /src/test/resources/Exif/orientation_7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/orientation_7.jpg -------------------------------------------------------------------------------- /src/test/resources/Exif/orientation_8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/orientation_8.jpg -------------------------------------------------------------------------------- /src/test/resources/Exif/original.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/original.jpg -------------------------------------------------------------------------------- /src/test/resources/Exif/original.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/original.png -------------------------------------------------------------------------------- /src/test/resources/Exif/sourceTall_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/sourceTall_1.jpg -------------------------------------------------------------------------------- /src/test/resources/Exif/sourceTall_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/sourceTall_2.jpg -------------------------------------------------------------------------------- /src/test/resources/Exif/sourceTall_3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/sourceTall_3.jpg -------------------------------------------------------------------------------- /src/test/resources/Exif/sourceTall_4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/sourceTall_4.jpg -------------------------------------------------------------------------------- /src/test/resources/Exif/sourceTall_5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/sourceTall_5.jpg -------------------------------------------------------------------------------- /src/test/resources/Exif/sourceTall_6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/sourceTall_6.jpg -------------------------------------------------------------------------------- /src/test/resources/Exif/sourceTall_7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/sourceTall_7.jpg -------------------------------------------------------------------------------- /src/test/resources/Exif/sourceTall_8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/sourceTall_8.jpg -------------------------------------------------------------------------------- /src/test/resources/Exif/sourceWide_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/sourceWide_1.jpg -------------------------------------------------------------------------------- /src/test/resources/Exif/sourceWide_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/sourceWide_2.jpg -------------------------------------------------------------------------------- /src/test/resources/Exif/sourceWide_3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/sourceWide_3.jpg -------------------------------------------------------------------------------- /src/test/resources/Exif/sourceWide_4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/sourceWide_4.jpg -------------------------------------------------------------------------------- /src/test/resources/Exif/sourceWide_5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/sourceWide_5.jpg -------------------------------------------------------------------------------- /src/test/resources/Exif/sourceWide_6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/sourceWide_6.jpg -------------------------------------------------------------------------------- /src/test/resources/Exif/sourceWide_7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/sourceWide_7.jpg -------------------------------------------------------------------------------- /src/test/resources/Exif/sourceWide_8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/sourceWide_8.jpg -------------------------------------------------------------------------------- /src/test/resources/Exif/source_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/source_1.jpg -------------------------------------------------------------------------------- /src/test/resources/Exif/source_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/source_2.jpg -------------------------------------------------------------------------------- /src/test/resources/Exif/source_3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/source_3.jpg -------------------------------------------------------------------------------- /src/test/resources/Exif/source_4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/source_4.jpg -------------------------------------------------------------------------------- /src/test/resources/Exif/source_5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/source_5.jpg -------------------------------------------------------------------------------- /src/test/resources/Exif/source_6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/source_6.jpg -------------------------------------------------------------------------------- /src/test/resources/Exif/source_7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/source_7.jpg -------------------------------------------------------------------------------- /src/test/resources/Exif/source_8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/source_8.jpg -------------------------------------------------------------------------------- /src/test/resources/Exif/stretch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Exif/stretch.png -------------------------------------------------------------------------------- /src/test/resources/Thumbnailator/grid.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Thumbnailator/grid.bmp -------------------------------------------------------------------------------- /src/test/resources/Thumbnailator/grid.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Thumbnailator/grid.gif -------------------------------------------------------------------------------- /src/test/resources/Thumbnailator/grid.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Thumbnailator/grid.jpg -------------------------------------------------------------------------------- /src/test/resources/Thumbnailator/grid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Thumbnailator/grid.png -------------------------------------------------------------------------------- /src/test/resources/Thumbnailator/igrid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coobird/thumbnailator/951d04f352d90f34420a82909c15453fee1b75ff/src/test/resources/Thumbnailator/igrid.png --------------------------------------------------------------------------------