Skip to content

Commit

Permalink
First Update
Browse files Browse the repository at this point in the history
  • Loading branch information
mojtabaJ committed Jul 30, 2022
1 parent 3fe369c commit 4880242
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>io.github.mojtabaj</groupId>
<artifactId>c-webp</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
<packaging>jar</packaging>

<name>WebP Converter</name>
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/io/github/mojtabaJ/cwebp/CWebp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/io/github/mojtabaJ/cwebp/CWebpException.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
84 changes: 77 additions & 7 deletions src/main/java/io/github/mojtabaJ/cwebp/WebpConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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 {

Expand All @@ -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 {

Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit 4880242

Please sign in to comment.