Package dev.avelar.mapnik
Class ImageFormat
java.lang.Object
dev.avelar.mapnik.ImageFormat
An image format with its options, built in code instead of written as a string. Mapnik takes a format as text,
such as
png8:c=64:m=h; this builds that text and checks every value in the range Mapnik accepts, so a
typo is an IllegalArgumentException at once instead of an error from deep inside the encoder.
byte[] png = map.renderToBytes(ImageFormat.png8().colors(64).quantizer(ImageFormat.Quantizer.HEXTREE));
byte[] jpg = map.renderToBytes(ImageFormat.jpeg(85));
byte[] webp = map.renderToBytes(ImageFormat.webp().lossless());
The plain strings still work wherever a format is taken. option(java.lang.String, java.lang.String) sets any option Mapnik has that this
class has no method for.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe zlib strategy of a PNG.static enumHow PNG8 chooses its palette.static enumHow TIFF data is compressed.static enumHow a TIFF is laid out in the file.static enumWhat PNG8 does about the alpha channel. -
Method Summary
Modifier and TypeMethodDescriptionalpha(boolean keep) WebP: keep (true) or drop (false) the alpha channel.colors(int count) PNG8: the number of colours in the palette, from 1 to 256.compression(int level) PNG and PNG8: zlib compression level, from -1 (zlib's default) or 0 (none) to 9 (smallest, slowest).compression(ImageFormat.TiffCompression compression) effort(int method) WebP: how hard the encoder works, from 0 (fast) to 6 (smallest).gamma(double gamma) PNG8: the gamma the colours are matched in, 0 or more.static ImageFormatjpeg(int quality) JPEG at a quality from 0 (smallest) to 100 (best).layout(ImageFormat.TiffLayout layout) lossless()WebP: store the pixels exactly.Set an option this class has no method for, by Mapnik's own name, such asimage_hintfor WebP.static ImageFormatpng()True-colour PNG with an alpha channel: exact, and larger thanpng8().static ImageFormatpng8()PNG with a palette of at most 256 colours: much smaller, and fine for maps with flat colours.quality(double quality) WebP: quality from 0 to 100.quantizer(ImageFormat.Quantizer quantizer) PNG8: the algorithm that picks the palette.rowsPerStrip(int rows) TIFF, stripped layout: rows in each strip.strategy(ImageFormat.PngStrategy strategy) PNG and PNG8: the zlib strategy.static ImageFormattiff()TIFF, uncompressed unless you say otherwise.toString()The format as Mapnik writes it, such aspng8:c=64:m=h.PNG8: what to do with transparency.static ImageFormatwebp()WebP, lossy at quality 90 unless you say otherwise.zlevel(int level) TIFF with deflate compression: the zlib level, from 0 to 9.
-
Method Details
-
png
True-colour PNG with an alpha channel: exact, and larger thanpng8(). -
png8
PNG with a palette of at most 256 colours: much smaller, and fine for maps with flat colours. -
colors
PNG8: the number of colours in the palette, from 1 to 256. -
quantizer
PNG8: the algorithm that picks the palette. -
transparency
PNG8: what to do with transparency. -
gamma
PNG8: the gamma the colours are matched in, 0 or more. Left out, no gamma correction is applied. -
compression
PNG and PNG8: zlib compression level, from -1 (zlib's default) or 0 (none) to 9 (smallest, slowest). -
strategy
PNG and PNG8: the zlib strategy. -
jpeg
JPEG at a quality from 0 (smallest) to 100 (best). JPEG has no transparency. -
webp
WebP, lossy at quality 90 unless you say otherwise. -
quality
WebP: quality from 0 to 100. Lossy unlesslossless(). -
lossless
WebP: store the pixels exactly. -
effort
WebP: how hard the encoder works, from 0 (fast) to 6 (smallest). -
alpha
WebP: keep (true) or drop (false) the alpha channel. -
tiff
TIFF, uncompressed unless you say otherwise. -
compression
-
layout
-
zlevel
TIFF with deflate compression: the zlib level, from 0 to 9. -
rowsPerStrip
TIFF, stripped layout: rows in each strip. -
option
Set an option this class has no method for, by Mapnik's own name, such asimage_hintfor WebP. The value is passed as it is, and Mapnik rejects what it does not accept when the image is encoded. -
toString
The format as Mapnik writes it, such aspng8:c=64:m=h.
-