/** Creates and initializes an instance of {@link ThumbnailMaker}. */ public ThumbnailMaker() { ready = new ReadinessTracker(); ready.unset(PARAM_IMAGE_TYPE); ready.unset(PARAM_RESIZER); ready.unset(PARAM_RESIZERFACTORY); defaultImageType(); defaultResizerFactory(); }
/** * Makes a thumbnail of the specified dimensions, from the specified source image. * * @param img The source image. * @param width The target width of the thumbnail. * @param height The target height of the thumbnail. * @return The thumbnail image. * @throws IllegalStateException If the {@code ThumbnailMaker} is not ready to create thumbnails. * @throws IllegalArgumentException If the width and/or height is less than or equal to zero. */ protected BufferedImage makeThumbnail(BufferedImage img, int width, int height) { if (!ready.isReady()) { throw new IllegalStateException(ThumbnailMaker.NOT_READY_FOR_MAKE); } if (width <= 0) { throw new IllegalArgumentException("Width must be greater than zero."); } if (height <= 0) { throw new IllegalArgumentException("Height must be greater than zero."); } BufferedImage thumbnailImage = new BufferedImageBuilder(width, height, imageType).build(); Dimension imgSize = new Dimension(img.getWidth(), img.getHeight()); Dimension thumbnailSize = new Dimension(width, height); Resizer resizer = resizerFactory.getResizer(imgSize, thumbnailSize); resizer.resize(img, thumbnailImage); return thumbnailImage; }
/** * Sets the {@link ResizerFactory} to use {@link DefaultResizerFactory}. * * @return A reference to this object. * @since 0.4.0 */ public ThumbnailMaker defaultResizerFactory() { this.resizerFactory = DefaultResizerFactory.getInstance(); ready.set(PARAM_RESIZER); ready.set(PARAM_RESIZERFACTORY); return this; }
/** * Sets the {@link ResizerFactory} which is used to obtain a {@link Resizer} for the resizing * operation. * * @param resizerFactory The {@link ResizerFactory} to obtain the {@link Resizer} used when * resizing the image to create the thumbnail. * @return A reference to this object. * @since 0.4.0 */ public ThumbnailMaker resizerFactory(ResizerFactory resizerFactory) { this.resizerFactory = resizerFactory; ready.set(PARAM_RESIZER); ready.set(PARAM_RESIZERFACTORY); return this; }
/** * Sets the {@link Resizer} which is used for the resizing operation. * * @param resizer The {@link Resizer} to use when resizing the image to create the thumbnail. * @return A reference to this object. */ public ThumbnailMaker resizer(Resizer resizer) { this.resizerFactory = new FixedResizerFactory(resizer); ready.set(PARAM_RESIZER); ready.set(PARAM_RESIZERFACTORY); return this; }
/** * Sets the type for the {@link BufferedImage} to produce. * * @param imageType The type of the {@code BufferedImage}. * @return A reference to this object. */ public ThumbnailMaker imageType(int imageType) { this.imageType = imageType; ready.set(PARAM_IMAGE_TYPE); return this; }