diff --git a/pom.xml b/pom.xml index cd46c16..f6bc1d7 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ io.github.mojtabaj c-webp - 1.0.1 + 1.0.2 jar WebP Converter diff --git a/src/main/java/io/github/mojtabaJ/cwebp/CWebp.java b/src/main/java/io/github/mojtabaJ/cwebp/CWebp.java index 6bb3365..194aeb5 100644 --- a/src/main/java/io/github/mojtabaJ/cwebp/CWebp.java +++ b/src/main/java/io/github/mojtabaJ/cwebp/CWebp.java @@ -2,7 +2,14 @@ import java.io.*; + /** + * created by: Mojtaba Jalambadani + * project name: c-webp + * 24/07/2022 + * All Rights Reserved. + * + * * util fot create and execute cwebp command to compresses an image using the WebP format. * Input format can be either PNG, JPEG, TIFF, WebP or raw Y'CbCr samples. * Note: Animated PNG and WebP files are not supported. diff --git a/src/main/java/io/github/mojtabaJ/cwebp/CWebpException.java b/src/main/java/io/github/mojtabaJ/cwebp/CWebpException.java new file mode 100644 index 0000000..f7e6955 --- /dev/null +++ b/src/main/java/io/github/mojtabaJ/cwebp/CWebpException.java @@ -0,0 +1,19 @@ +package io.github.mojtabaJ.cwebp; + +/** + * created by: Mojtaba Jalambadani + * project name: c-webp + * 24/07/2022 + * All Rights Reserved. + **/ +public class CWebpException extends Exception{ + + + public CWebpException(String message) { + super(message); + } + + public CWebpException(Throwable cause) { + super(cause); + } +} diff --git a/src/main/java/io/github/mojtabaJ/cwebp/WebpConverter.java b/src/main/java/io/github/mojtabaJ/cwebp/WebpConverter.java index 5df584e..bbed044 100644 --- a/src/main/java/io/github/mojtabaJ/cwebp/WebpConverter.java +++ b/src/main/java/io/github/mojtabaJ/cwebp/WebpConverter.java @@ -11,14 +11,30 @@ * project name: c-webp * 21/07/2022 * All Rights Reserved. - **/ + * + * + * util fot create and execute cwebp command to compresses an image using the WebP format. + * Input format can be either PNG, JPEG, TIFF, WebP or raw Y'CbCr samples. + * Note: Animated PNG and WebP files are not supported. + */ public class WebpConverter { + + /** + * convert PNG, JPEG, TIFF, WebP image to WebP Byte + * @param imageByte input image byte + * @return WebP image Byte + */ public static byte[] imageByteToWebpByte(byte[] imageByte){ return imageByteToWebpByte(imageByte, 75); } - + /** + * convert PNG, JPEG, TIFF, WebP image to WebP Byte + * @param imageByte input image byte + * @param quality compression factor for RGB channels + * @return WebP image Byte + */ public static byte[] imageByteToWebpByte(byte[] imageByte, int quality){ try { @@ -42,7 +58,12 @@ public static byte[] imageByteToWebpByte(byte[] imageByte, int quality){ return null; } - + /** + * convert PNG, JPEG, TIFF, WebP image to WebP Byte + * @param imageFilePath input image file path + * @param quality compression factor for RGB channels + * @return WebP image Byte + */ public static byte[] imageFileToWebpByte(String imageFilePath, int quality) { try { @@ -57,17 +78,35 @@ public static byte[] imageFileToWebpByte(String imageFilePath, int quality) { return null; } - + /** + * convert PNG, JPEG, TIFF, WebP image to WebP Byte + * @param imageFile input image file + * @param quality compression factor for RGB channels + * @return WebP image Byte + */ public static byte[] imageFileToWebpByte(File imageFile, int quality) { return imageFileToWebpByte(imageFile.getAbsolutePath(), quality); } + + /** + * convert PNG, JPEG, TIFF, WebP image to WebP File + * @param imageByte input image byte + * @param webpPathFile output webp image path file + * @return WebP image File + */ public static File imageByteToWebpFile(byte[] imageByte, String webpPathFile){ return imageByteToWebpFile(imageByte, webpPathFile,75); } - + /** + * convert PNG, JPEG, TIFF, WebP image to WebP File + * @param imageByte input image byte + * @param webpPathFile output webp image path file + * @param quality compression factor for RGB channels + * @return WebP image File + */ public static File imageByteToWebpFile(byte[] imageByte, String webpPathFile, int quality){ try { @@ -90,7 +129,13 @@ public static File imageByteToWebpFile(byte[] imageByte, String webpPathFile, in return null; } - + /** + * convert PNG, JPEG, TIFF, WebP image to WebP File + * @param imageFilePath input image file path + * @param webpPathFile output webp image path file + * @param quality compression factor for RGB channels + * @return WebP image File + */ public static File imageFileToWebpFile(String imageFilePath, String webpPathFile, int quality){ try { return getWebpFile(imageFilePath, quality, null, webpPathFile); @@ -100,12 +145,28 @@ public static File imageFileToWebpFile(String imageFilePath, String webpPathFile return null; } - + /** + * convert PNG, JPEG, TIFF, WebP image to WebP File + * @param imageFile input image file + * @param webpPathFile output webp image path file + * @param quality compression factor for RGB channels + * @return WebP image File + */ public static File imageFileToWebpFile(File imageFile, String webpPathFile, int quality){ return imageFileToWebpFile(imageFile.getAbsolutePath(), webpPathFile, quality); } + + /** + * convert PNG, JPEG, TIFF, WebP image to WebP Byte + * @param imageFilePath input image file path + * @param quality compression factor for RGB channels + * @param tempDir temp directory for converting + * @param output output webp image path file + * @return WebP image Byte + * @throws IOException handle the exception + */ private static byte[] getWebpBytes(String imageFilePath, int quality, Path tempDir, String output) throws IOException { CWebp cwebp = new CWebp().quality(quality).input(imageFilePath).output(output); cwebp.execute(); @@ -117,6 +178,15 @@ private static byte[] getWebpBytes(String imageFilePath, int quality, Path tempD return webpByte; } + /** + * convert PNG, JPEG, TIFF, WebP image to WebP File + * @param imageFilePath input image file path + * @param quality compression factor for RGB channels + * @param tempDir temp directory for converting + * @param output output webp image path file + * @return WebP image File + * @throws IOException handle the exception + */ private static File getWebpFile(String imageFilePath, int quality, Path tempDir, String output) throws IOException { CWebp cwebp = new CWebp().quality(quality).input(imageFilePath).output(output); cwebp.execute();