Free Java Image Creation & Processing Library
A Useful Open Source Java Image Processing API that allows to Create Read, Write, Resize, Crop, Add Watermarks and Convert Images like PNG, JPEG, BMP, TIFF, ICO, and many more.
In the world of computer vision, libraries play a vital role in simplifying the process of image and video analysis. One such library that has gained significant attention in recent years is ICAFE, an open-source library developed by Dragon66. ICAFE supports popular image formats like JPEG, PNG, BMP, TIFF, GIF, and even RAW formats from digital cameras. It is a powerful, versatile Java library for image processing that offers rich functionality and various basic as well as advanced features for working with images, such as creating new images, image conversion between various formats, working with image metadata, creating animated GIF, merging or splitting images, removing or adding chunks to PNG, compress images or convert between formats, apply filters to images and so on.
ICAFE (Image & Camera Acquisition for Everyone) is an open source Java library that simplifies working with images, offering various features for processing, encoding, decoding, and metadata extraction inside Java applications. Originally designed for image handling, ICAFE has evolved to support a wide range of formats, including the ability to process diagrams. With its flexible API and support for multiple image formats, ICAFE provides software developers the tools they need to create powerful applications, especially for working with diagrams. Moreover, Software Developers can use the library to import diagrams from different formats, manipulate them, and then export them into the desired format. With its ease of use, robust set of features, multi-format support and flexibility, ICAFE is an excellent and valuable resource in any developer's toolkit.
Getting Started with ICAFE
The easiest and recommended way to install ICAFE is via GitHub.
Install ICAFE via GitHub
go get -u https://github.com/dragon66/icafe.git
Image Compression and Conversion
The open source ICAFE library makes it simple to read and compress various type of images, which is crucial when working with large files or optimizing web applications. The library allows for both lossless and lossy compression of images. Here’s an example that shows how software developers can used the code for compressing an input JPEG image and saves it at 75% quality. ICAFE's JPEGEncoder class simplifies image compression, which can be tuned to fit the application's needs.
How to Compressing a JPEG image Images inside Node.js Apps?
import com.icafe4j.image.jpeg.JPEGEncoder;
import java.io.File;
import java.io.IOException;
public class ImageCompressionExample {
public static void main(String[] args) throws IOException {
File inputFile = new File("input.jpg");
File outputFile = new File("compressed_output.jpg");
// Compress JPEG with 75% quality
JPEGEncoder.encode(inputFile, outputFile, 0.75f);
System.out.println("Image compressed successfully!");
}
}
Metadata Extraction via Java Applications
The ICAFE library supports the extraction and manipulation of image metadata such as EXIF, IPTC, and XMP. This is particularly useful when dealing with camera images or diagrams that require additional information like timestamps, location data, or copyright details. In the following code example, ICAFE reads the EXIF metadata from a JPEG file, retrieving details about the camera model and the date the photo was taken. This can be expanded to handle various other metadata tags, making it an excellent tool for managing image collections.
How to Load and Read & Extract the EXIF Metadata from a JPEG file via Java API?
import com.icafe4j.image.metadata.Metadata;
import com.icafe4j.image.metadata.exif.Exif;
import com.icafe4j.image.jpeg.JPEGMetadataReader;
import java.io.File;
import java.io.IOException;
public class MetadataExample {
public static void main(String[] args) throws IOException {
File imageFile = new File("input.jpg");
// Extract EXIF metadata from a JPEG file
Metadata metadata = JPEGMetadataReader.readMetadata(imageFile);
Exif exif = (Exif) metadata.getExif();
if (exif != null) {
System.out.println("Camera Model: " + exif.getCameraModel());
System.out.println("Date Taken: " + exif.getDateTime());
} else {
System.out.println("No EXIF metadata found!");
}
}
}
Manipulate (Resize, Crop, Filters) Images via Java
The open source ICAFE library makes it easy for software developers to read and manipulate various types of images inside Java applications. The library fully supports easy manipulation of images, including resizing, cropping, applying filters and more. In the following code snippet software developers can resizes an image while maintaining its aspect ratio. ICAFE’s manipulation capabilities enable software developers to easily integrate image processing functions into their software.
How to Load and Resize Images via Java API?
public class ResizeImageExample {
public static void main(String[] args) throws IOException {
BufferedImage originalImage = ImageIO.read(new File("input.jpg"));
// Resize the image to a width of 300 and maintain aspect ratio
Image resizedImage = originalImage.getScaledInstance(300, -1, Image.SCALE_SMOOTH);
BufferedImage resizedBufferedImage = new BufferedImage(300, resizedImage.getHeight(null), BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = resizedBufferedImage.createGraphics();
g2d.drawImage(resizedImage, 0, 0, null);
g2d.dispose();
// Save the resized image
ImageIO.write(resizedBufferedImage, "jpg", new File("resized_output.jpg"));
System.out.println("Image resized successfully!");
}
}
Apply Watermarking to Images via Java API?
Adding watermarks to images is simple with ICAFE library. This feature is useful for protecting intellectual property, especially in applications that deal with diagrams or design assets. The following code example demonstrates how to overlay a text watermark on an image, ensuring your diagrams or images are protected.
How to Overlay a Text Watermark on an Image via Java API?
public class WatermarkExample {
public static void main(String[] args) throws IOException {
BufferedImage image = ImageIO.read(new File("input.jpg"));
// Add a text watermark
TextWatermark watermark = new TextWatermark("Watermark", 50);
BufferedImage watermarkedImage = watermark.apply(image);
// Save the watermarked image
ImageIO.write(watermarkedImage, "jpg", new File("watermarked_output.jpg"));
System.out.println("Watermark applied successfully!");
}
}