The resize to Fit operation will rescale the image so that it fit into the defined pixel rectangle as closely as possible. Aspect ratio is preserved so the image is not stretched and will end up being either the width or height specified but not both unless the apsect ratio of the image is the same as the specified new size.
ImageProcessingOperations operations = new ImageProcessingOperations(); // You can chain several operations here such as scale, blur, etc operations.resizeToFit(100, 100); // make image fit into a box 100x100 pixels preserving aspect ratio // Apply the operations to a BufferedImage BufferedImage modifiedImage = operations.apply(BufferedImage originalImage);
Process and convert between image formats using the following code examples:
File inputFile = new File("path/to/file"); File outputFile = new File("path/to/output-resizedToFit-file"); JDeli.convert(inputFile, outputFile, operations);
final InputStream inputStream = new FileInputStream(inputFile); final OutputStream outputStream = new FileOutputStream(outputFile); final String outputFormat = "format"; // format of the output file eg. png, jpeg,...; JDeli.convert(inputStream, outputStream, outputFormat, operations);
byte inputData = Files.readAllBytes(Paths.get("/path/to/file")); final String outputFormat = "format"; // format of the output file eg. png, jpeg,...; byte outputData = JDeli.convert(inputData, outputFormat, operations);