Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an easy to use Image library for simple operations (read,write,rotate,re-size)? [closed]

My use case is pretty simple which I think is shared with many other developers.

I would like to:

 1. Load an image
 2. Read EXIF Orientation details (If available)
 3. Rotate (90, 180, 270) degrees
 4. Resize and store images.

I tried going through the forums and then tried:

Sanselan: Reads EXIF, but not JPG images. Also, commons-imaging download links are all broken.

Java ImageIO/Graphics2D: Can rotate/re-size(not one liner, but is understandable) although as suggested you do lose quality when rotating.

*BUT does not read all JPG images (Throws CMMException for some jpg file)

The rest are either too old and not maintained anymore, have no documentation at all or I missed the 'good' one.

Can anyone suggest a library that supports these few 'simple' use cases?

*Using Sanselan to read EXIF is fine. Read/Rotate/Re-size (JPGs) is my main problem

like image 673
Ioannis Deligiannis Avatar asked Dec 09 '25 23:12

Ioannis Deligiannis


1 Answers

Thumbnailator is a simple Java library which has no external dependencies which can (a) load an image, (b) read the Exif metadata and automatically rotate the image, (c) resize and (d) store the image in one single statement:

Thumbnails.of("path/to/image")
    .size(320, 240)
    .toFile("path/to/thumbnail");

The above will:

  • open the image
  • resize it so that it will fit in a 320 pixel x 240 pixel region, while
  • maintaining the aspect ratio of the original image, and
  • properly orient the image according to the Exif metadata, and
  • store it to a new image

If one desires to perform additional rotations, a rotate method is also available.

Disclaimer: I am the maintainer of Thumbnailator.

like image 199
coobird Avatar answered Dec 12 '25 14:12

coobird