1. Products
  2.   Image
  3.   Java
  4.   ICAFE
 
  

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.

What is ICAFE?

ICAFE is an open source Java imaging API that streamlines complex image workflows. This free Java imaging library excels at essential tasks like resize images in Java, convert image to PNG, JPEG, GIF and others, as well as crop images with ease. It enables seamless read & write image operations for common formats including JPEG, PNG, BMP, and TIFF, along with advanced functions such as animated GIF creation and PNG chunk manipulation. Its robust capabilities make it a powerful Java Image Processing Library for developers.

Beyond basic edits, ICAFE serves as a comprehensive toolkit for advanced image metadata data extract and detailed image manipulate images tasks. As a capable image compression library, it optimizes file sizes while supporting format conversions. Developers can also filter images and handle specialized RAW camera formats. With its versatile API designed for both standard photos and diagram processing, ICAFE provides a flexible, all-in-one solution for diverse imaging needs within Java applications.

Previous Next

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 in Java

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!");
    }
}
 English