forked from tario/imageruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
147 lines (94 loc) · 3.29 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
= ImageRuby - flexible ruby gem for image processing
ImageRuby is a gem for image processing written in pure ruby, this makes the library very portable and easy to install
Also, the gem was desgined to accept extensions like:
* new format decoders made from scratch (Ruby or C)
* new format decoders based on existent C libraries like libpng, libbmp, etc...
* new image operations (Ruby or C)
* re-implementations of parts in C to improve performance on environments where it is possible
== Installation
=== Gem installation
sudo gem install imageruby
== Documentation
Full API documentation can be found on:
http://tario.github.com/imageruby/doc/
== Examples
NOTE: Examples loads and saves bitmap files, imageruby-bmp gem must be installed in order
to get the examples work
=== Create and save a black image
require "rubygems"
require "imageruby"
include ImageRuby
# creates an image of 150x150 pixels filled with black
image = ImageRuby::Image.new(150,150, Color.black)
begin
# this only work if imageruby-bmp gem is installed
image.save("black.bmp", :bmp)
rescue
print "Error while trying to save, you must install imageruby-bmp gem"
end
=== Create an image with vertical stripes filled with default named colors
require "rubygems"
require "imageruby"
include ImageRuby
print "list of named colors:\n"
print "--------------------------\n"
colors = Array.new
Color.named_colors.each do |name, color|
print "#{name}: #{color.inspect}\n"
colors << color
end
image = Image.new( colors.count * 32, 512)
x = 0
colors.each do |color|
image[x..x+31, 0..511] = Image.new(32,512,color)
x = x + 32
end
image.save("colors.bmp", :bmp)
=== Gradient using block parameter
require "rubygems"
require "imageruby"
include ImageRuby
gradient_images = Array.new
gradient_images << Image.new(64,64) {|x,y|
Color.from_rgb(x*4,y*4,0)
}
gradient_images << Image.new(64,64) {|x,y|
Color.from_rgb(0,x*4,y*4)
}
gradient_images << Image.new(64,64) {|x,y|
Color.from_rgb(y*4,0,x*4)
}
(0..gradient_images.count-1).each do |i|
gradient_images[i].save("gradient#{i}.bmp", :bmp)
end
all_gradient = Image.new(96*gradient_images.count, 96)
(0..gradient_images.count-1).each do |i|
all_gradient.draw!(i*96+16, 16, gradient_images[i])
end
all_gradient.save("gradients.bmp", :bmp)
=== Draw with mask
require "rubygems"
require "imageruby"
include ImageRuby
colors = Image.from_file("colors.bmp")
gradients = Image.from_file("gradients.bmp")
without_mask = colors.draw(128,192,gradients)
without_mask.save("without_mask.bmp", :bmp)
with_mask = colors.draw(128,192,gradients.mask(Color.black))
with_mask.save("with_mask.bmp", :bmp)
=== Draw with transparency effects
require "rubygems"
require "imageruby"
include ImageRuby
colors = Image.from_file("colors.bmp")
gradients = Image.from_file("gradients.bmp")
transparent_black = Color.black
transparent_black.a = 128
colors.draw(128,192,gradients.color_replace(Color.black, transparent_black)).save("sample1.bmp", :bmp)
half_transparent = gradients.map_pixel{ |x,y,c|
c.a = 128 if x >144
c
}
colors.draw(128,192,half_transparent).save("sample2.bmp", :bmp)
== Copying
Copyright (c) 2011 Dario Seminara, released under the GPL License (see LICENSE)