Skip to main content
  1. Articles/

Q: Image resize quality (Java)

This was originally posted as an answer to the question "Image resize quality (Java)" on stackoverflow.com.
13 upvotes
26k views

The two most popular open source libs specializing in image resizing in java currently are:

Additonal there is the JDK way with Java’s Graphics2D (see this question on how to do it) which is notorious to create bad results especially with downscaling. There is also a Java interface to ImageMagick which will be omitted here because it requires an external tool.

Visual Quality #

Here is a comparison of the results of resizing/downscaling a 580x852 png to 145x213. As reference Photoshop CS5 “save for web” resizing is used. Note: the results are 1:1 what the libs created just copied together. The zoom does not use any filtering, just a simple nearest neighbor algorithm. Here you can find the original image.

comparison

  1. Thumbnailator 0.4.8 with default settings, no dimension adjustments
  2. Photoshop CS5 with bicubic algorithm
  3. imgscalr 4.2 with ULTRA_QUALITY setting, no dimension adjustments
  4. Graphics2D (Java 8) with render hints VALUE_INTERPOLATION_BICUBIC, VALUE_RENDER_QUALITY, VALUE_ANTIALIAS_ON

I leave it to the reader to select the best result as this is subjective. Generally, all have good output except Graphics2D. Thumbnailator generates sharper images very similar to Photoshop output, whereas imgscalr’s output is considerably softer. For icons/text etc. you want a sharper output, for pictures you may want softer output.

Computational Time #

Here is non-scientific benchmark using this tool and 114 images with dimension from about 96x96 up to 2560x1440 treating it as 425% images creating: 100%, 150%, 200%, 300% and 400% scaled versions of it (so 114 * 5 scaling operations). All libs use the same settings as in the quality comparison (so highest quality possible). Times are only scaling not the whole process. Done on a i5-2520M with 8GB Ram and 5 runs.

  • Thumbnailator: 7003.0ms | 6581.3ms | 6019.1ms | 6375.3ms | 8700.3ms
  • imgscalr: 25218.5ms | 25786.6ms | 25095.7ms | 25790.4ms | 29296.3ms
  • Graphics2D: 7387.6ms | 7177.0ms | 7048.2ms | 7132.3ms | 7510.3ms

Here is the code used in this benchmark.

Interestingly Thumbnailator is also the fastest with an average time of 6.9 sec followed by Java2D with 7.2 sec leaving imgscalr behind with a poor 26.2 sec. This is probably not fair since imgscalr is set to ULTRA_QUALITY which seems to be extremely expensive; with the QUALITY setting it averages at a more competitive 11.1 sec.