All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.blitline.image.functions.ResizeToFit Maven / Gradle / Ivy

There is a newer version: 0.17.1
Show newest version
package com.blitline.image.functions;

public class ResizeToFit extends AbstractFunction {
	@Override
	public String getName() {
		return "resize_to_fit";
	}

	/**
	 * Specify the maximum dimensions of the resized image. You may specify zero for one of the dimensions to leave it
	 * unconstrained.
	 * 
	 * @param maxWidth
	 *            the maximum width of the resulting image, or zero for any width
	 * @param maxHeight
	 *            the maximum height of the resulting image, or zero for any height
	 */
	public ResizeToFit(int maxWidth, int maxHeight) {
		if (maxWidth == 0 && maxHeight == 0)
			throw new IllegalArgumentException("at least one maximum dimension must be specified");

		if (maxWidth > 0)
			params.put("width", maxWidth);

		if (maxHeight > 0)
			params.put("height", maxHeight);
	}

	/**
	 * Do not upscale the image if the original is already smaller than the maximum dimensions. Sets the {@code only_shrink_larger}
	 * JSON option.
	 * 
	 * @return {@literal this}
	 */
	public ResizeToFit doNotUpscale() {
		params.put("only_shrink_larger", Boolean.TRUE);
		return this;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy