Description
A pure ruby high-level PNG file creation toolkit.
(If you need a low-level PNG manipulation & analysis toolkit - take a look at ZPNG)
Features
- neat syntax
- unicode text drawing support
- 16-bit color depth support
Installation
gem install sugar_png
Examples
Hello World!
Explicit image dimensions + bg color
Japanese text with rainbow borders, zoomed 4x
save "out.png"
end
### White noise
<img src="https://raw.githubusercontent.com/zed-0xff/sugar_png/master/samples/readme/white_noise.png" alt="White noise" title="White noise" align="right" />
```ruby
SugarPNG.new do
bg :black # shortcut for 'background'
fg :white # ditto
width 100
height 100
200.times{ pixel(rand(100),rand(100)) }
save "out.png"
end
Playing with transparency & 16-bit color depth
100.times do |y|
100.times do |x|
img[x,y] = [0,65536*x/100,0,65535*y/100] # RGBA
end
end
# 'export' returns PNG image data suitable for streaming to client
# or manually saving to a file or do whatever you want
@data = img.export
end
### Pixels can be set using Ranges, Enumerators & Arrays
<img src="https://raw.githubusercontent.com/zed-0xff/sugar_png/master/samples/readme/pixels_can_be_set_using_ranges_enumerators_arrays.png" alt="Pixels can be set using Ranges, Enumerators & Arrays" title="Pixels can be set using Ranges, Enumerators & Arrays" align="right" />
```ruby
SugarPNG.new do |img|
# Ranges
img[10...50, 10..20] = :blue
# Array + Enumerator
img[[1,2,4,8,16,32], 0.step(50,2)] = :red
img.zoom = 2
end.save("out.png")
License
Released under the MIT License. See the LICENSE file for further details.