-
Notifications
You must be signed in to change notification settings - Fork 102
Constraints
Sandro Turriate edited this page Nov 1, 2022
·
2 revisions
#Constraints
{:compression => Zlib::BEST_COMPRESSION}
This can either be a hash with different constraints, or a symbol which acts as a
preset for some constraints. If no constraints are given, ChunkyPNG will decide
for itself how to best create the PNG datastream.
- Supported presets are
:fast_rgba
for quickly saving images with transparency,:fast_rgb
for quickly saving opaque images, and:best_compression
to obtain the smallest possible filesize. -
:color_mode
The color mode to use. Use one of theChunkyPNG::COLOR_*
constants. -
:interlace
true or false -
:compression
0 - 9, or the Zlib constants such asZlib::BEST_COMPRESSION
-
:bit_depth
The bit depth to use. This option is only used for indexed images, in which case it overrides the determined minimal bit depth. For all the other color modes, a bit depth of 8 is used.
cv = ChunkyPNG::Image.from_rgb_stream(width, height, buffer)
ds = cv.to_datastream(color_mode: ChunkyPNG::COLOR_TRUECOLOR, compression: Zlib::BEST_COMPRESSION, filtering: ChunkyPNG::FILTER_PAETH)
pixel = [0,0,0,0,0,0] # color black
ds.transparency_chunk = ChunkyPNG::Chunk::Transparency.new "tRNS", pixel.pack("C*")
ds.save("out.png")