@@ -94,12 +94,16 @@ down-sizes images for use as thumbnails (along with some additional minor
94
94
optimizations).
95
95
96
96
imgscalr also provides support for applying arbitrary BufferedImageOps against
97
- resultant images directly in the library and provides defaults out of the box
98
- for common, hardware-accelerated options like applying a light "anti-aliasing"
99
- filter to the results.
97
+ resultant images directly in the library.
98
+
99
+ TIP: imgscalr provides a default "anti-aliasing" Op that will very lightly soften
100
+ an image; this was a common request. Check Scalr.OP_ANTIALIAS
100
101
101
102
TIP: All resizing operations maintain the original images proportions.
102
103
104
+ TIP: You can ask imgscalr to fit an image to a specific width or height regardless
105
+ of its orientation using a Mode argument.
106
+
103
107
This class attempts to make scaling images in Java as simple as possible by providing
104
108
a handful of approaches tuned for scaling as fast as possible or as best-looking
105
109
as possible and the ability to let the algorithm choose for you to optionally create
@@ -122,6 +126,43 @@ and write out the scaled result immediately to a single line:
122
126
ImageIO.write(Scalr.resize(ImageIO.read(...), 150));
123
127
124
128
129
+ Working with GIFs
130
+ -----------------
131
+ Java's support for writing GIF is... terrible. In Java 5 is was patent-encumbered
132
+ which made it mostly totally broken. In Java 6 the quantizer used to downsample
133
+ colors to the most accurate 256 colors was fast but inaccurate, yielding
134
+ poor-looking results. The handling of an alpha channel (transparency) while writing
135
+ out GIF files (e.g. ImageIO.write(...)) was non-existent in Java 5 and in Java 6
136
+ would remove the alpha channel completely and replace it with solid BLACK.
137
+
138
+ In Java 7, support for writing out the alpha channel was added but unfortunately
139
+ many of the remaining image operations (like ConvoleOp) still corrupt the
140
+ resulting image when written out as a GIF.
141
+
142
+ NOTE: Support for scaling animated GIFs don't work at all in any version.
143
+
144
+ My recommendation for working with GIFs is as follows in order of preference:
145
+
146
+ 1. Save the resulting BufferedImage from imgscalr as a PNG; it looks
147
+ better as no quantizer needs to be used to cull down the color space and
148
+ transparency is maintained.
149
+
150
+ 2. If you mostly need GIF, check the resulting BufferedImage.getType() to see
151
+ if it is TYPE_INT_RGB (no transparency) or TYPE_INT_ARGB (transparency); if the
152
+ type is ARGB, then save the image as a PNG to maintain the alpha channel, if not,
153
+ you can safely save it as a GIF.
154
+
155
+ 3. If you MUST have GIF, upgrade your runtime to Java 7 and save your images as
156
+ GIF. If you run Java 6, any GIF using transparency will have the transparent
157
+ channel replaced with BLACK and in Java 5 I think the images will most all be
158
+ corrupt/invalid.
159
+
160
+ REMINDER: Even in Java 7, applying some BufferedImageOps (like ConvolveOp) to
161
+ the scaled GIF before saving it totally corrupts it; so you would need to avoid
162
+ that if you didn't want to save it as a PNG. If you decide to save as a PNG, you
163
+ can apply any Ops you want.
164
+
165
+
125
166
Troubleshooting
126
167
---------------
127
168
Image-manipulation in Java can take more memory than the size of the source image
0 commit comments