sugar_png 0.0.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +6 -4
- data/Gemfile.lock +77 -24
- data/README.md +105 -0
- data/README.md.tpl +99 -0
- data/Rakefile +41 -6
- data/VERSION +1 -1
- data/data/1-dump-hex.rb +22 -0
- data/data/2-marshal-test.rb +22 -0
- data/data/3-hex2marshal.rb +71 -0
- data/data/font/00 +0 -0
- data/data/font/01 +0 -0
- data/data/font/02 +0 -0
- data/data/font/03 +0 -0
- data/data/font/04 +0 -0
- data/data/font/05 +0 -0
- data/data/font/06 +0 -0
- data/data/font/07 +0 -0
- data/data/font/09 +0 -0
- data/data/font/0a +0 -0
- data/data/font/0b +0 -0
- data/data/font/0c +0 -0
- data/data/font/0d +0 -0
- data/data/font/0e +0 -0
- data/data/font/0f +0 -0
- data/data/font/10 +0 -0
- data/data/font/11 +0 -0
- data/data/font/12 +0 -0
- data/data/font/13 +0 -0
- data/data/font/14 +0 -0
- data/data/font/15 +0 -0
- data/data/font/16 +0 -0
- data/data/font/17 +0 -0
- data/data/font/18 +0 -0
- data/data/font/19 +0 -0
- data/data/font/1a +0 -0
- data/data/font/1b +0 -0
- data/data/font/1c +0 -0
- data/data/font/1d +0 -0
- data/data/font/1e +0 -0
- data/data/font/1f +0 -0
- data/data/font/20 +0 -0
- data/data/font/21 +0 -0
- data/data/font/22 +0 -0
- data/data/font/23 +0 -0
- data/data/font/24 +0 -0
- data/data/font/25 +0 -0
- data/data/font/26 +0 -0
- data/data/font/27 +0 -0
- data/data/font/28 +0 -0
- data/data/font/29 +0 -0
- data/data/font/2a +0 -0
- data/data/font/2b +0 -0
- data/data/font/2c +0 -0
- data/data/font/2d +0 -0
- data/data/font/2e +0 -0
- data/data/font/2f +0 -0
- data/data/font/30 +0 -0
- data/data/font/31 +0 -0
- data/data/font/32 +0 -0
- data/data/font/33 +0 -0
- data/data/font/34 +0 -0
- data/data/font/35 +0 -0
- data/data/font/36 +0 -0
- data/data/font/37 +0 -0
- data/data/font/38 +0 -0
- data/data/font/39 +0 -0
- data/data/font/3a +0 -0
- data/data/font/3b +0 -0
- data/data/font/3c +0 -0
- data/data/font/3d +0 -0
- data/data/font/3e +0 -0
- data/data/font/3f +0 -0
- data/data/font/40 +0 -0
- data/data/font/41 +0 -0
- data/data/font/42 +0 -0
- data/data/font/43 +0 -0
- data/data/font/44 +0 -0
- data/data/font/45 +0 -0
- data/data/font/46 +0 -0
- data/data/font/47 +0 -0
- data/data/font/48 +0 -0
- data/data/font/49 +0 -0
- data/data/font/4a +0 -0
- data/data/font/4b +0 -0
- data/data/font/4c +0 -0
- data/data/font/4d +0 -0
- data/data/font/4e +0 -0
- data/data/font/4f +0 -0
- data/data/font/50 +0 -0
- data/data/font/51 +0 -0
- data/data/font/52 +0 -0
- data/data/font/53 +0 -0
- data/data/font/54 +0 -0
- data/data/font/55 +0 -0
- data/data/font/56 +0 -0
- data/data/font/57 +0 -0
- data/data/font/58 +0 -0
- data/data/font/59 +0 -0
- data/data/font/5a +0 -0
- data/data/font/5b +0 -0
- data/data/font/5c +0 -0
- data/data/font/5d +0 -0
- data/data/font/5e +0 -0
- data/data/font/5f +0 -0
- data/data/font/60 +0 -0
- data/data/font/61 +0 -0
- data/data/font/62 +0 -0
- data/data/font/63 +0 -0
- data/data/font/64 +0 -0
- data/data/font/65 +0 -0
- data/data/font/66 +0 -0
- data/data/font/67 +0 -0
- data/data/font/68 +0 -0
- data/data/font/69 +0 -0
- data/data/font/6a +0 -0
- data/data/font/6b +0 -0
- data/data/font/6c +0 -0
- data/data/font/6d +0 -0
- data/data/font/6e +0 -0
- data/data/font/6f +0 -0
- data/data/font/70 +0 -0
- data/data/font/71 +0 -0
- data/data/font/72 +0 -0
- data/data/font/73 +0 -0
- data/data/font/74 +0 -0
- data/data/font/75 +0 -0
- data/data/font/76 +0 -0
- data/data/font/77 +0 -0
- data/data/font/78 +0 -0
- data/data/font/79 +0 -0
- data/data/font/7a +0 -0
- data/data/font/7b +0 -0
- data/data/font/7c +0 -0
- data/data/font/7d +0 -0
- data/data/font/7e +0 -0
- data/data/font/7f +0 -0
- data/data/font/80 +0 -0
- data/data/font/81 +0 -0
- data/data/font/82 +0 -0
- data/data/font/83 +0 -0
- data/data/font/84 +0 -0
- data/data/font/85 +0 -0
- data/data/font/86 +0 -0
- data/data/font/87 +0 -0
- data/data/font/88 +0 -0
- data/data/font/89 +0 -0
- data/data/font/8a +0 -0
- data/data/font/8b +0 -0
- data/data/font/8c +0 -0
- data/data/font/8d +0 -0
- data/data/font/8e +0 -0
- data/data/font/8f +0 -0
- data/data/font/90 +0 -0
- data/data/font/91 +0 -0
- data/data/font/92 +0 -0
- data/data/font/93 +0 -0
- data/data/font/94 +0 -0
- data/data/font/95 +0 -0
- data/data/font/96 +0 -0
- data/data/font/97 +0 -0
- data/data/font/98 +0 -0
- data/data/font/99 +0 -0
- data/data/font/9a +0 -0
- data/data/font/9b +0 -0
- data/data/font/9c +0 -0
- data/data/font/9d +0 -0
- data/data/font/9e +0 -0
- data/data/font/9f +0 -0
- data/data/font/a0 +0 -0
- data/data/font/a1 +0 -0
- data/data/font/a2 +0 -0
- data/data/font/a3 +0 -0
- data/data/font/a4 +0 -0
- data/data/font/a5 +0 -0
- data/data/font/a6 +0 -0
- data/data/font/a7 +0 -0
- data/data/font/a8 +0 -0
- data/data/font/a9 +0 -0
- data/data/font/aa +0 -0
- data/data/font/ac +0 -0
- data/data/font/ad +0 -0
- data/data/font/ae +0 -0
- data/data/font/af +0 -0
- data/data/font/b0 +0 -0
- data/data/font/b1 +0 -0
- data/data/font/b2 +0 -0
- data/data/font/b3 +0 -0
- data/data/font/b4 +0 -0
- data/data/font/b5 +0 -0
- data/data/font/b6 +0 -0
- data/data/font/b7 +0 -0
- data/data/font/b8 +0 -0
- data/data/font/b9 +0 -0
- data/data/font/ba +0 -0
- data/data/font/bb +0 -0
- data/data/font/bc +0 -0
- data/data/font/bd +0 -0
- data/data/font/be +0 -0
- data/data/font/bf +0 -0
- data/data/font/c0 +0 -0
- data/data/font/c1 +0 -0
- data/data/font/c2 +0 -0
- data/data/font/c3 +0 -0
- data/data/font/c4 +0 -0
- data/data/font/c5 +0 -0
- data/data/font/c6 +0 -0
- data/data/font/c7 +0 -0
- data/data/font/c8 +0 -0
- data/data/font/c9 +0 -0
- data/data/font/ca +0 -0
- data/data/font/cb +0 -0
- data/data/font/cc +0 -0
- data/data/font/cd +0 -0
- data/data/font/ce +0 -0
- data/data/font/cf +0 -0
- data/data/font/d0 +0 -0
- data/data/font/d1 +0 -0
- data/data/font/d2 +0 -0
- data/data/font/d3 +0 -0
- data/data/font/d4 +0 -0
- data/data/font/d5 +0 -0
- data/data/font/d6 +0 -0
- data/data/font/d7 +0 -0
- data/data/font/f9 +0 -0
- data/data/font/fa +0 -0
- data/data/font/fb +0 -0
- data/data/font/fc +0 -0
- data/data/font/fd +0 -0
- data/data/font/fe +0 -0
- data/data/font/ff +0 -0
- data/data/unifont-5.1.20080820.7z +0 -0
- data/data/unused-4-read-tar.rb +49 -0
- data/lib/sugar_png.rb +164 -2
- data/lib/sugar_png/border.rb +20 -0
- data/lib/sugar_png/color.rb +118 -0
- data/lib/sugar_png/datastream.rb +2 -17
- data/lib/sugar_png/dyn_accessor.rb +28 -0
- data/lib/sugar_png/font.rb +44 -0
- data/lib/sugar_png/glyph.rb +36 -0
- data/lib/sugar_png/image.rb +104 -0
- data/samples/damaged_chunk.png +0 -0
- data/samples/damaged_signature.png +0 -0
- data/samples/png_suite/f00n0g08_reference.png +0 -0
- data/samples/png_suite/f00n2c08_reference.png +0 -0
- data/samples/png_suite/f01n0g08_reference.png +0 -0
- data/samples/png_suite/f01n2c08_reference.png +0 -0
- data/samples/png_suite/f02n0g08_reference.png +0 -0
- data/samples/png_suite/f02n2c08_reference.png +0 -0
- data/samples/png_suite/f03n0g08_reference.png +0 -0
- data/samples/png_suite/f03n2c08_reference.png +0 -0
- data/samples/png_suite/f04n0g08_reference.png +0 -0
- data/samples/png_suite/f04n2c08_reference.png +0 -0
- data/samples/readme/explicit_image_dimensions_bg_color.png +0 -0
- data/samples/readme/hello_world.png +0 -0
- data/samples/readme/japanese_text_with_rainbow_borders_zoomed_4x.png +0 -0
- data/samples/readme/pixels_can_be_set_using_ranges_enumerators_arrays.png +0 -0
- data/samples/readme/playing_with_transparency_16_bit_color_depth.png +0 -0
- data/samples/readme/white_noise.png +0 -0
- data/samples/rgba.tar.bz2 +0 -0
- data/samples/text_chunk.png +0 -0
- data/samples/ztxt_chunk.png +0 -0
- data/spec/color_spec.rb +81 -0
- data/spec/font_spec.rb +82 -0
- data/spec/magic/border_spec.rb +49 -0
- data/spec/magic/create_spec.rb +42 -0
- data/spec/magic/pixels_spec.rb +73 -0
- data/spec/magic/text_spec.rb +113 -0
- data/spec/magic/zoom_spec.rb +38 -0
- data/spec/png_suite_spec.rb +145 -0
- data/spec/spec_helper.rb +45 -1
- data/spec/sugar_png/datastream_spec.rb +32 -0
- data/spec/support/png_suite.rb +44 -0
- data/sugar_png.gemspec +295 -28
- metadata +331 -50
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f4e3f3c23821bd5142bd7fa690b710dac9f81f32f387384c5696b414674addbf
|
4
|
+
data.tar.gz: c6219a130b05bf3b7bae14c91401710b91c6226eafca11747e80852cb189112e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: de450b6e2c69a0b37d524be8c29a18fadee725e941df5bfd7146dd47263eea3dea7305d9e34373b86b4de730ace12e084e1eb2b0491ae95ae94d0e5e8b983d7c
|
7
|
+
data.tar.gz: bc68d74a7c5b9464c4a49255e9408431a94ab8eaa7f6b059a967f54e403b057a3e5200bf17e7e2b12746617fa5e4f40f5f96e0b4d76b4dda1a3710c2536f841a
|
data/Gemfile
CHANGED
@@ -2,12 +2,14 @@ source "http://rubygems.org"
|
|
2
2
|
# Add dependencies required to use your gem here.
|
3
3
|
# Example:
|
4
4
|
# gem "activesupport", ">= 2.3.5"
|
5
|
-
gem 'zpng', ">= 0.
|
5
|
+
gem 'zpng', ">= 0.3.1"
|
6
6
|
|
7
7
|
# Add dependencies to develop your gem here.
|
8
8
|
# Include everything needed to run rake, tests, features, etc.
|
9
9
|
group :development do
|
10
|
-
gem "rspec", "
|
11
|
-
gem "
|
12
|
-
gem "
|
10
|
+
gem "rspec", "~> 3.9.0"
|
11
|
+
gem "rspec-its", "~> 1.3.0"
|
12
|
+
gem "bundler", "~> 2.2.3"
|
13
|
+
gem "jeweler", "~> 2.3.9"
|
14
|
+
gem "awesome_print"
|
13
15
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,36 +1,89 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
addressable (2.4.0)
|
5
|
+
awesome_print (1.8.0)
|
6
|
+
builder (3.2.4)
|
7
|
+
descendants_tracker (0.0.4)
|
8
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
9
|
+
diff-lcs (1.4.4)
|
10
|
+
faraday (0.9.2)
|
11
|
+
multipart-post (>= 1.2, < 3)
|
12
|
+
git (1.8.1)
|
13
|
+
rchardet (~> 1.8)
|
14
|
+
github_api (0.16.0)
|
15
|
+
addressable (~> 2.4.0)
|
16
|
+
descendants_tracker (~> 0.0.4)
|
17
|
+
faraday (~> 0.8, < 0.10)
|
18
|
+
hashie (>= 3.4)
|
19
|
+
mime-types (>= 1.16, < 3.0)
|
20
|
+
oauth2 (~> 1.0)
|
21
|
+
hashie (4.1.0)
|
22
|
+
highline (2.0.3)
|
23
|
+
jeweler (2.3.9)
|
24
|
+
builder
|
25
|
+
bundler
|
9
26
|
git (>= 1.2.5)
|
27
|
+
github_api (~> 0.16.0)
|
28
|
+
highline (>= 1.6.15)
|
29
|
+
nokogiri (>= 1.5.10)
|
30
|
+
psych
|
10
31
|
rake
|
11
32
|
rdoc
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
33
|
+
semver2
|
34
|
+
jwt (2.2.2)
|
35
|
+
mime-types (2.99.3)
|
36
|
+
mini_portile2 (2.5.0)
|
37
|
+
multi_json (1.15.0)
|
38
|
+
multi_xml (0.6.0)
|
39
|
+
multipart-post (2.1.1)
|
40
|
+
nokogiri (1.11.1)
|
41
|
+
mini_portile2 (~> 2.5.0)
|
42
|
+
racc (~> 1.4)
|
43
|
+
oauth2 (1.4.4)
|
44
|
+
faraday (>= 0.8, < 2.0)
|
45
|
+
jwt (>= 1.0, < 3.0)
|
46
|
+
multi_json (~> 1.3)
|
47
|
+
multi_xml (~> 0.5)
|
48
|
+
rack (>= 1.2, < 3)
|
49
|
+
psych (3.3.0)
|
50
|
+
racc (1.5.2)
|
51
|
+
rack (2.2.3)
|
52
|
+
rainbow (3.0.0)
|
53
|
+
rake (13.0.3)
|
54
|
+
rchardet (1.8.0)
|
55
|
+
rdoc (6.3.0)
|
56
|
+
rspec (3.9.0)
|
57
|
+
rspec-core (~> 3.9.0)
|
58
|
+
rspec-expectations (~> 3.9.0)
|
59
|
+
rspec-mocks (~> 3.9.0)
|
60
|
+
rspec-core (3.9.3)
|
61
|
+
rspec-support (~> 3.9.3)
|
62
|
+
rspec-expectations (3.9.4)
|
63
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
64
|
+
rspec-support (~> 3.9.0)
|
65
|
+
rspec-its (1.3.0)
|
66
|
+
rspec-core (>= 3.0.0)
|
67
|
+
rspec-expectations (>= 3.0.0)
|
68
|
+
rspec-mocks (3.9.1)
|
69
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
70
|
+
rspec-support (~> 3.9.0)
|
71
|
+
rspec-support (3.9.4)
|
72
|
+
semver2 (3.4.2)
|
73
|
+
thread_safe (0.3.6)
|
74
|
+
zpng (0.3.2)
|
27
75
|
rainbow
|
28
76
|
|
29
77
|
PLATFORMS
|
30
78
|
ruby
|
31
79
|
|
32
80
|
DEPENDENCIES
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
81
|
+
awesome_print
|
82
|
+
bundler (~> 2.2.3)
|
83
|
+
jeweler (~> 2.3.9)
|
84
|
+
rspec (~> 3.9.0)
|
85
|
+
rspec-its (~> 1.3.0)
|
86
|
+
zpng (>= 0.3.1)
|
87
|
+
|
88
|
+
BUNDLED WITH
|
89
|
+
2.2.3
|
data/README.md
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
sugar_png [![Build Status](https://travis-ci.org/zed-0xff/sugar_png.png?branch=master)](https://travis-ci.org/zed-0xff/sugar_png) [![Dependency Status](https://gemnasium.com/zed-0xff/sugar_png.png)](https://gemnasium.com/zed-0xff/sugar_png)
|
2
|
+
======
|
3
|
+
|
4
|
+
|
5
|
+
Description
|
6
|
+
-----------
|
7
|
+
A pure ruby high-level PNG file creation toolkit.
|
8
|
+
|
9
|
+
(If you need a low-level PNG manipulation & analysis toolkit - take a look at [ZPNG](https://github.com/zed-0xff/zpng))
|
10
|
+
|
11
|
+
Features
|
12
|
+
--------
|
13
|
+
* neat syntax
|
14
|
+
* unicode text drawing support
|
15
|
+
* 16-bit color depth support
|
16
|
+
|
17
|
+
Installation
|
18
|
+
------------
|
19
|
+
gem install sugar_png
|
20
|
+
|
21
|
+
Examples
|
22
|
+
--------
|
23
|
+
|
24
|
+
### Hello World!
|
25
|
+
<img src="https://raw.githubusercontent.com/zed-0xff/sugar_png/master/samples/readme/hello_world.png" alt="Hello World!" title="Hello World!" align="right" />
|
26
|
+
```ruby
|
27
|
+
SugarPNG.new do
|
28
|
+
text "Hello World!"
|
29
|
+
save "out.png"
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
### Explicit image dimensions + bg color
|
34
|
+
<img src="https://raw.githubusercontent.com/zed-0xff/sugar_png/master/samples/readme/explicit_image_dimensions_bg_color.png" alt="Explicit image dimensions + bg color" title="Explicit image dimensions + bg color" align="right" />
|
35
|
+
```ruby
|
36
|
+
SugarPNG.new do
|
37
|
+
background 'red' # or :blue, or #ffee00, or :transparent (default)
|
38
|
+
width 100
|
39
|
+
height 50
|
40
|
+
text "Hello World!", :color => '#ffffff'
|
41
|
+
save "out.png"
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
### Japanese text with rainbow borders, zoomed 4x
|
46
|
+
<img src="https://raw.githubusercontent.com/zed-0xff/sugar_png/master/samples/readme/japanese_text_with_rainbow_borders_zoomed_4x.png" alt="Japanese text with rainbow borders, zoomed 4x" title="Japanese text with rainbow borders, zoomed 4x" align="right" />
|
47
|
+
```ruby
|
48
|
+
SugarPNG.new do
|
49
|
+
border 1, :red
|
50
|
+
border 1, :green
|
51
|
+
border 1, :blue
|
52
|
+
text '水水水'
|
53
|
+
zoom 4
|
54
|
+
|
55
|
+
save "out.png"
|
56
|
+
end
|
57
|
+
```
|
58
|
+
|
59
|
+
### White noise
|
60
|
+
<img src="https://raw.githubusercontent.com/zed-0xff/sugar_png/master/samples/readme/white_noise.png" alt="White noise" title="White noise" align="right" />
|
61
|
+
```ruby
|
62
|
+
SugarPNG.new do
|
63
|
+
bg :black # shortcut for 'background'
|
64
|
+
fg :white # ditto
|
65
|
+
width 100
|
66
|
+
height 100
|
67
|
+
200.times{ pixel(rand(100),rand(100)) }
|
68
|
+
|
69
|
+
save "out.png"
|
70
|
+
end
|
71
|
+
```
|
72
|
+
|
73
|
+
### Playing with transparency & 16-bit color depth
|
74
|
+
<img src="https://raw.githubusercontent.com/zed-0xff/sugar_png/master/samples/readme/playing_with_transparency_16_bit_color_depth.png" alt="Playing with transparency & 16-bit color depth" title="Playing with transparency & 16-bit color depth" align="right" />
|
75
|
+
```ruby
|
76
|
+
SugarPNG.new do |img|
|
77
|
+
img.depth = 16
|
78
|
+
|
79
|
+
100.times do |y|
|
80
|
+
100.times do |x|
|
81
|
+
img[x,y] = [0,65536*x/100,0,65535*y/100] # RGBA
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# 'export' returns PNG image data suitable for streaming to client
|
86
|
+
# or manually saving to a file or do whatever you want
|
87
|
+
@data = img.export
|
88
|
+
end
|
89
|
+
```
|
90
|
+
|
91
|
+
### Pixels can be set using Ranges, Enumerators & Arrays
|
92
|
+
<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" />
|
93
|
+
```ruby
|
94
|
+
SugarPNG.new do |img|
|
95
|
+
# Ranges
|
96
|
+
img[10...50, 10..20] = :blue
|
97
|
+
# Array + Enumerator
|
98
|
+
img[[1,2,4,8,16,32], 0.step(50,2)] = :red
|
99
|
+
img.zoom = 2
|
100
|
+
end.save("out.png")
|
101
|
+
```
|
102
|
+
|
103
|
+
License
|
104
|
+
-------
|
105
|
+
Released under the MIT License. See the [LICENSE](https://github.com/zed-0xff/sugar_png/blob/master/LICENSE.txt) file for further details.
|
data/README.md.tpl
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
sugar_png [![Build Status](https://travis-ci.org/zed-0xff/sugar_png.png?branch=master)](https://travis-ci.org/zed-0xff/sugar_png) [![Dependency Status](https://gemnasium.com/zed-0xff/sugar_png.png)](https://gemnasium.com/zed-0xff/sugar_png)
|
2
|
+
======
|
3
|
+
|
4
|
+
|
5
|
+
Description
|
6
|
+
-----------
|
7
|
+
A pure ruby high-level PNG file creation toolkit.
|
8
|
+
|
9
|
+
(If you need a low-level PNG manipulation & analysis toolkit - take a look at [ZPNG](https://github.com/zed-0xff/zpng))
|
10
|
+
|
11
|
+
Features
|
12
|
+
--------
|
13
|
+
* neat syntax
|
14
|
+
* unicode text drawing support
|
15
|
+
* 16-bit color depth support
|
16
|
+
|
17
|
+
Installation
|
18
|
+
------------
|
19
|
+
gem install sugar_png
|
20
|
+
|
21
|
+
Examples
|
22
|
+
--------
|
23
|
+
|
24
|
+
### Hello World!
|
25
|
+
```ruby
|
26
|
+
SugarPNG.new do
|
27
|
+
text "Hello World!"
|
28
|
+
save "out.png"
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
### Explicit image dimensions + bg color
|
33
|
+
```ruby
|
34
|
+
SugarPNG.new do
|
35
|
+
background 'red' # or :blue, or #ffee00, or :transparent (default)
|
36
|
+
width 100
|
37
|
+
height 50
|
38
|
+
text "Hello World!", :color => '#ffffff'
|
39
|
+
save "out.png"
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
### Japanese text with rainbow borders, zoomed 4x
|
44
|
+
```ruby
|
45
|
+
SugarPNG.new do
|
46
|
+
border 1, :red
|
47
|
+
border 1, :green
|
48
|
+
border 1, :blue
|
49
|
+
text '水水水'
|
50
|
+
zoom 4
|
51
|
+
|
52
|
+
save "out.png"
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
### White noise
|
57
|
+
```ruby
|
58
|
+
SugarPNG.new do
|
59
|
+
bg :black # shortcut for 'background'
|
60
|
+
fg :white # ditto
|
61
|
+
width 100
|
62
|
+
height 100
|
63
|
+
200.times{ pixel(rand(100),rand(100)) }
|
64
|
+
|
65
|
+
save "out.png"
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
69
|
+
### Playing with transparency & 16-bit color depth
|
70
|
+
```ruby
|
71
|
+
SugarPNG.new do |img|
|
72
|
+
img.depth = 16
|
73
|
+
|
74
|
+
100.times do |y|
|
75
|
+
100.times do |x|
|
76
|
+
img[x,y] = [0,65536*x/100,0,65535*y/100] # RGBA
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# 'export' returns PNG image data suitable for streaming to client
|
81
|
+
# or manually saving to a file or do whatever you want
|
82
|
+
@data = img.export
|
83
|
+
end
|
84
|
+
```
|
85
|
+
|
86
|
+
### Pixels can be set using Ranges, Enumerators & Arrays
|
87
|
+
```ruby
|
88
|
+
SugarPNG.new do |img|
|
89
|
+
# Ranges
|
90
|
+
img[10...50, 10..20] = :blue
|
91
|
+
# Array + Enumerator
|
92
|
+
img[[1,2,4,8,16,32], 0.step(50,2)] = :red
|
93
|
+
img.zoom = 2
|
94
|
+
end.save("out.png")
|
95
|
+
```
|
96
|
+
|
97
|
+
License
|
98
|
+
-------
|
99
|
+
Released under the MIT License. See the [LICENSE](https://github.com/zed-0xff/sugar_png/blob/master/LICENSE.txt) file for further details.
|
data/Rakefile
CHANGED
@@ -23,6 +23,7 @@ Jeweler::Tasks.new do |gem|
|
|
23
23
|
gem.authors = ["Andrey \"Zed\" Zaikin"]
|
24
24
|
#gem.executables = %w'sugar_png'
|
25
25
|
gem.files.include "lib/**/*.rb"
|
26
|
+
gem.files.include "data/font/??"
|
26
27
|
# dependencies defined in Gemfile
|
27
28
|
end
|
28
29
|
Jeweler::RubygemsDotOrgTasks.new
|
@@ -40,12 +41,46 @@ end
|
|
40
41
|
|
41
42
|
task :default => :spec
|
42
43
|
|
43
|
-
desc "
|
44
|
-
task :
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
desc "build readme"
|
45
|
+
task :readme do
|
46
|
+
dir = "samples/readme"
|
47
|
+
FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
|
48
|
+
|
49
|
+
tpl = File.read('README.md.tpl')
|
50
|
+
Dir.chdir "tmp"
|
51
|
+
result = tpl.gsub(/^### ([^~`\n]+?)\n```ruby(.+?)^```/m) do |x|
|
52
|
+
title, code = $1, $2
|
53
|
+
fname = File.join(
|
54
|
+
dir,
|
55
|
+
title.split(/\W+/).join('_').sub(/^_+/,'').sub(/_+$/,'').downcase + ".png"
|
56
|
+
)
|
57
|
+
|
58
|
+
File.open("tmp.rb", "w:utf-8") do |f|
|
59
|
+
f.puts "#coding: utf-8"
|
60
|
+
f.puts "$:.unshift('../lib')"
|
61
|
+
f.puts "require 'sugar_png'"
|
62
|
+
f.puts "srand 0"
|
63
|
+
f.puts code
|
64
|
+
f.puts <<-EOF
|
65
|
+
if defined?(@data) && @data
|
66
|
+
File.open("out.png","wb"){ |f| f<<@data }
|
67
|
+
end
|
68
|
+
EOF
|
69
|
+
end
|
70
|
+
|
71
|
+
puts "[.] #{fname} .. "
|
72
|
+
system "ruby tmp.rb"
|
73
|
+
exit unless $?.success?
|
74
|
+
raise "[?] no out.png" unless File.exist?("out.png")
|
75
|
+
FileUtils.mv "out.png", "../#{fname}"
|
76
|
+
|
77
|
+
url = File.join("https://raw.githubusercontent.com/zed-0xff/sugar_png/master", fname)
|
78
|
+
img = %Q|<img src="#{url}" alt="#{title}" title="#{title}" align="right" />|
|
79
|
+
|
80
|
+
x.sub(title,title+"\n"+img)
|
81
|
+
end
|
82
|
+
Dir.chdir ".."
|
83
|
+
File.open('README.md','w'){ |f| f << result }
|
49
84
|
end
|
50
85
|
|
51
86
|
Rake::Task[:console].clear
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.2
|
data/data/1-dump-hex.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
fname = ARGV.first || "unifont-5.1.20080820.hex"
|
4
|
+
|
5
|
+
want = ARGV[1] && ARGV[1].to_i(16)
|
6
|
+
|
7
|
+
File.read(fname).each_line do |line|
|
8
|
+
idx, data = line.strip.split(':',2)
|
9
|
+
idx = idx.to_i(16)
|
10
|
+
next if want && want != idx
|
11
|
+
case data.size
|
12
|
+
when 32
|
13
|
+
data.scan(/../).each do |x|
|
14
|
+
puts(("%08b" % x.to_i(16)).tr('01',' #'))
|
15
|
+
end
|
16
|
+
when 64
|
17
|
+
data.scan(/..../).each do |x|
|
18
|
+
puts(("%016b" % x.to_i(16)).tr('01',' #'))
|
19
|
+
end
|
20
|
+
else raise data.size.to_s
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'hexdump'
|
3
|
+
require 'awesome_print'
|
4
|
+
|
5
|
+
def dump x
|
6
|
+
data = Marshal.dump(x)
|
7
|
+
printf "[.] %4d: %-10s (%d): %s\n".green, data.size, x.class.to_s, x.size, x.inspect[0,30].gray
|
8
|
+
Hexdump.dump data
|
9
|
+
puts
|
10
|
+
end
|
11
|
+
|
12
|
+
dump 0
|
13
|
+
dump 0xff
|
14
|
+
dump [0] * 10
|
15
|
+
dump [0xff] * 10
|
16
|
+
dump 'x'
|
17
|
+
dump 'x'*100
|
18
|
+
dump ['x']*100
|
19
|
+
|
20
|
+
a = [1,2,3,4,5]
|
21
|
+
dump a
|
22
|
+
dump [a]*10
|