Skip to content

Commit 4f142bb

Browse files
committed
changes scaler lib imgscalr with thumbnailator resulting in better images
updates to v0.9.2 update readme
1 parent 8499e4c commit 4f142bb

8 files changed

Lines changed: 33 additions & 20 deletions

File tree

README.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This is a powerful little tool that helps **converting single or batches of imag
44
versions given the source scale factor or target width/height in [dp](http://developer.android.com/guide/practices/screens_support.html#density-independence).
55
It has a **graphical** and **command line** interface and supports a wide array of image types for reading and conversion
66
including PNG, JPEG, SVG, PSD and Android 9-patches. Using sophisticated scaling algorithms, it is designed to make conversion of images easy and
7-
fast while keeping the image quality high. To further optimize the output post processors like **pngcrush** and **mozJpeg** can be used (see section below).
7+
fast while keeping the image quality high (comparable to PS). To further optimize the output post processors like **pngcrush** and **mozJpeg** can be used (see section below).
88

99
Usage:
1010

@@ -56,8 +56,8 @@ Full list of arguments:
5656
-androidIncludeLdpiTvdpi Android only: creates mipmap sub-folders instead of drawable.
5757
-androidMipmapInsteadOfDrawable Android only: If set will include additional densities (ldpi and
5858
tvdpi)
59-
-antiAliasing Anti-aliases images creating a little more blurred result; useful
60-
for very small images
59+
-antiAliasing Anti-aliases images creating a little more blurred result; a light
60+
3x3 convolve matrix is used; useful for very small images
6161
-clean Deletes all file and folders in out dir that would be used in
6262
current configuration before converting.
6363
-compressionQuality <0.0-1.0> Only used with compression 'jpg' sets the quality [0-1.0] where 1.0
@@ -192,12 +192,16 @@ If an image will be re-compressed with a file type that does not support alpha,
192192

193193
## Quality Comparison
194194
One of the main features of this converter is downscaling. Unfortunately without using specific algorithms, down scaled
195-
images may look jagged. Density converter uses the algorithms of [imgscalr](https://github.com/thebuzzmedia/imgscalr) which
196-
provide fairly good quality, comparable to Photoshop output (although PS comes out ahead a bit). The following
197-
diagram is to compare the expected quality when using this tool in comparison to Java's native Graphics2D and Photoshop.
195+
images may look jagged. Density converter uses the algorithms of [Thumbnailator](https://github.com/coobird/thumbnailator) which
196+
provide fairly good quality, comparable to Photoshop output. Thumbnailator turned out to generater better results than the other popular open source resizer lib [imgscalr](https://github.com/thebuzzmedia/imgscalr) which was used in previous versions. The following diagram is to compare the expected quality when using this tool in comparison to Java's native Graphics2D and Photoshop.
198197

198+
![comparison-ldpi](src/main/resources/img/ldpi_comparison.png)
199+
![comparison-ldpi](src/main/resources/img/mdpi_comparison.png)
199200

200-
![comparison](src/main/resources/img/quality_comparison.png)
201+
1) Density Converter using Thumbnailator with default settings
202+
2) Photoshop CS5 with bicubic algorithm
203+
3) imgscalr with ULTRA_QUALITY setting
204+
4) Java2d with render hints VALUE_INTERPOLATION_BICUBIC, VALUE_RENDER_QUALITY, VALUE_ANTIALIAS_ON
201205

202206
## Post Processors
203207

@@ -266,7 +270,7 @@ The .jar file will be in the generated `/target` folder
266270
## Credits
267271

268272
* TIFF, PSD, SVG image type support [TwelveMonkeys](https://github.com/haraldk/TwelveMonkeys)
269-
* HQ image resizing with [imgscalr](https://github.com/thebuzzmedia/imgscalr)
273+
* HQ image resizing with [Thumbnailator](https://github.com/coobird/thumbnailator)
270274
* JavaFx theme based on Flatter by [hendrikebbers](https://github.com/guigarage/javafx-collection/tree/master/flatter)
271275
* Image file icon: Icon made by [Freepik](http://www.freepik.com/)
272276
* 9-patch resizing routine from [Redwarp](https://github.com/redwarp/9-Patch-Resizer)

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>at.favre.tools</groupId>
88
<artifactId>dconvert</artifactId>
9-
<version>0.9.1</version>
9+
<version>0.9.2</version>
1010

1111
<prerequisites>
1212
<maven>3.1.0</maven>
@@ -85,9 +85,9 @@
8585
</dependency>
8686
<!-- hq image scaling -->
8787
<dependency>
88-
<groupId>org.imgscalr</groupId>
89-
<artifactId>imgscalr-lib</artifactId>
90-
<version>4.2</version>
88+
<groupId>net.coobird</groupId>
89+
<artifactId>thumbnailator</artifactId>
90+
<version>[0.4, 0.5)</version>
9191
</dependency>
9292
<!-- supported reading/writing image types -->
9393
<dependency>

src/main/java/at/favre/tools/dconvert/util/ImageUtil.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
import com.twelvemonkeys.imageio.metadata.jpeg.JPEG;
2525
import com.twelvemonkeys.imageio.metadata.jpeg.JPEGSegment;
2626
import com.twelvemonkeys.imageio.metadata.jpeg.JPEGSegmentUtil;
27-
import org.imgscalr.Scalr;
27+
import net.coobird.thumbnailator.makers.FixedSizeThumbnailMaker;
28+
import net.coobird.thumbnailator.resizers.DefaultResizerFactory;
29+
import net.coobird.thumbnailator.resizers.Resizer;
2830

2931
import javax.imageio.*;
3032
import javax.imageio.metadata.IIOMetadata;
@@ -34,7 +36,8 @@
3436
import javax.imageio.stream.ImageOutputStream;
3537
import java.awt.*;
3638
import java.awt.image.BufferedImage;
37-
import java.awt.image.BufferedImageOp;
39+
import java.awt.image.ConvolveOp;
40+
import java.awt.image.Kernel;
3841
import java.io.File;
3942
import java.io.IOException;
4043
import java.io.InputStream;
@@ -46,6 +49,9 @@
4649
* Main Util class containing all
4750
*/
4851
public class ImageUtil {
52+
public static final ConvolveOp OP_ANTIALIAS = new ConvolveOp(
53+
new Kernel(3, 3, new float[]{.0f, .08f, .0f, .08f, .68f, .08f,
54+
.0f, .08f, .0f}), ConvolveOp.EDGE_NO_OP, null);
4955

5056
public static LoadedImage loadImage(File input) throws Exception {
5157
if (input == null) {
@@ -172,14 +178,17 @@ public static BufferedImage scale(BufferedImage imageToScale, int dWidth, int dH
172178
BufferedImage scaledImage = null;
173179
if (imageToScale != null) {
174180

175-
BufferedImageOp[] bufferedImageOpArray = new BufferedImageOp[]{};
181+
Resizer resizer = DefaultResizerFactory.getInstance()
182+
.getResizer(new Dimension(imageToScale.getWidth(), imageToScale.getHeight()), new Dimension(dWidth, dHeight));
183+
184+
scaledImage = new FixedSizeThumbnailMaker(dWidth, dHeight, false, true)
185+
.resizer(resizer)
186+
.make(imageToScale);
176187

177188
if (antiAlias) {
178-
bufferedImageOpArray = new BufferedImageOp[]{Scalr.OP_ANTIALIAS};
189+
scaledImage = OP_ANTIALIAS.filter(scaledImage, null);
179190
}
180191

181-
scaledImage = Scalr.resize(imageToScale, Scalr.Method.ULTRA_QUALITY, Scalr.Mode.FIT_EXACT, dWidth, dHeight, bufferedImageOpArray);
182-
183192
if (!compression.hasTransparency) {
184193
BufferedImage convertedImg = new BufferedImage(scaledImage.getWidth(), scaledImage.getHeight(), BufferedImage.TYPE_INT_RGB);
185194
convertedImg.getGraphics().drawImage(scaledImage, 0, 0, background, null);

src/main/resources/bundles/strings.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ arg.descr.cmd.verbose=If set will log to console more verbose
6464
arg.descr.dryrun=Will not create any images or folder. Useful as fast preview in log what images in what resolutions would be created.
6565
arg.descr.halterror=If set will stop the process if an error occurred during conversion
6666
arg.descr.androidldpi=Android only: If set will include additional densities (ldpi and tvdpi)
67-
arg.descr.antialiasing=Anti-aliases images creating a little more blurred result; useful for very small images
67+
arg.descr.antialiasing=Anti-aliases images creating a little more blurred result; a light 3x3 convolve matrix is used; useful for very small images
6868
arg.descr.androidmipmap=Android only: creates mipmap sub-folders instead of drawable.
6969
arg.descr.pngcrush=Will post-process all pngs with pngcrush, a lossless compressor. The executable must be set in the system PATH as 'pngcrush' i.e executable from every path. Pngcrush is a tool to compress pngs. Requires v1.7.22+
7070
arg.descr.webp=Will additionally convert all png/gif to lossless wepb and all jpg to lossy webp with cwebp. Does not delete source files. The executable must be set in the system path as 'cwebp' i.e executable from every path. cwebp is the official converter from Google.
46.9 KB
Loading
67.1 KB
Loading
-79.9 KB
Binary file not shown.

src/test/java/at/favre/tools/dconvert/test/GUITest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class GUITest extends ApplicationTest {
3434

3535
@BeforeClass
3636
public static void setupSpec() throws Exception {
37-
if (false) {
37+
if (true) {
3838
System.setProperty("testfx.robot", "glass");
3939
System.setProperty("testfx.headless", "true");
4040
System.setProperty("prism.order", "sw");

0 commit comments

Comments
 (0)