Handling a vast collection of PNG images? Converting them to JPG in bulk can be extremely beneficial, especially if you need JPGs for various purposes.
PNG (Portable Network Graphics) is a format known for its lossless compression and is widely used across various devices and platforms. Converting PNG images to JPG can significantly reduce file size, making them easier to store and share without compromising too much on quality.
In this article, I’ll guide you through the process of using Java to convert PNG files to JPG format with JDeli, ensuring your images are accessible.
Mass convert PNG to JPG using Java
- Download the JDeli trial jar.
- Process image if needed (scale, sharpen, lighten, watermark, etc)
- Write out BufferedImage as JPG image file
BufferedImage bufferedImage = JDeli.read(new File("pngImageFile.png"));
// Read PNG image into Java
bufferedImage = operations.apply(BufferedImage bufferedImage);
// Process image (Optional)
JDeli.write(bufferedImage, "jpg", new File("jpgImageFile.jpg"));
// Write out BufferedImage as JPEG image file
Export PNG to JPG in one line of code
With the JDeli.convert()
method you can save PNG as JPG in just one line of code.
Using File
JDeli.convert(File inFile, File outFile);
Using InputStream and OutputStream
JDeli.convert(InputStream inputStream, OutputStream outputStream, "jpg");
Using byte[]
byte[] outputData = JDeli.convert(byte[] inputData, "jpg");
Configure Output Settings
You can use this option to specify an EncoderOptions object for configuring output settings such as image compression.
JDeli.convert(File inFile, EncoderOptions outputOptions, File outfile);
How to bulk convert PNG to JPG from the command line
Mass convert PNG to JPG using command line or bash, bat, and PowerShell scripts. This method also enables JDeli to be invoked from any programming language that supports creating a child process.
java -jar jdeli.jar –convert jpg "inputFileOrDir" "outputDir"
In this tutorial you learned how to bulk convert PNG to JPG in bulk, for tutorials on more format conversions visit our support site.
Are you a Java Developer working with Image files?
// Read an image
BufferedImage bufferedImage = JDeli.read(dicomImageFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(heicImageFile);
// Write an image
JDeli.write(bufferedImage, "heic", outputStreamOrFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(jpegImageFile);
// Write an image
JDeli.write(bufferedImage, "jpeg", outputStreamOrFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(jpeg2000ImageFile);
// Write an image
JDeli.write(bufferedImage, "jpx", outputStreamOrFile);
// Write an image
JDeli.write(bufferedImage, "pdf", outputStreamOrFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(pngImageFile);
// Write an image
JDeli.write(bufferedImage, "png", outputStreamOrFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(tiffImageFile);
// Write an image
JDeli.write(bufferedImage, "tiff", outputStreamOrFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(webpImageFile);
// Write an image
JDeli.write(bufferedImage, "webp", outputStreamOrFile);
Why do developers choose JDeli over free alternatives?
- Works with newer image formats such as AVIF, HEIC, JPEG XL, WEBP
- Better support than alternatives for JPEG, PNG, TIFF.
- Prevent JVM crashes caused by native code in other image libraries
- Better performance than other popular Java image libraries