本文根据 Devhints / Chunky PNG 翻译。代码示例及版本范围沿用原文。
加载
image = ChunkyPNG::Image.from_file('file.png')
其他方式
image = ChunkyPNG::Image.from_blob(File.read('file.png'))
image = ChunkyPNG::Image.from_io(io)
从……加载 file.png.
保存
image.save('filename.png')
其他方式
File.open('newfile.png', 'wb') { |io| image.write(io) }
binary_string = image.to_blob
将图像写入…… newfile.png.
绘图
image[0, 0] = ChunkyPNG::Color.rgba(255, 0,0, 128)
image.line(1, 1, 10, 1, ChunkyPNG::Color.from_hex('#aa007f'))
Canvas
crop(x, y, w, h)
转换器 (Transforms)
new_image = image.flip_horizontally.rotate_right