rmagick 1.7.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rmagick might be problematic. Click here for more details.

Files changed (239) hide show
  1. data/ChangeLog +232 -0
  2. data/Makefile.in +28 -0
  3. data/README.html +404 -0
  4. data/README.txt +397 -0
  5. data/configure +8554 -0
  6. data/configure.ac +497 -0
  7. data/doc/comtasks.html +241 -0
  8. data/doc/constants.html +1195 -0
  9. data/doc/css/doc.css +299 -0
  10. data/doc/css/popup.css +34 -0
  11. data/doc/draw.html +3108 -0
  12. data/doc/ex/Adispatch.rb +43 -0
  13. data/doc/ex/Zconstitute.rb +9 -0
  14. data/doc/ex/adaptive_threshold.rb +19 -0
  15. data/doc/ex/add_noise.rb +18 -0
  16. data/doc/ex/affine.rb +48 -0
  17. data/doc/ex/affine_transform.rb +20 -0
  18. data/doc/ex/arc.rb +47 -0
  19. data/doc/ex/arcpath.rb +33 -0
  20. data/doc/ex/average.rb +15 -0
  21. data/doc/ex/axes.rb +64 -0
  22. data/doc/ex/bilevel_channel.rb +20 -0
  23. data/doc/ex/blur_image.rb +12 -0
  24. data/doc/ex/border.rb +10 -0
  25. data/doc/ex/bounding_box.rb +48 -0
  26. data/doc/ex/cbezier1.rb +40 -0
  27. data/doc/ex/cbezier2.rb +40 -0
  28. data/doc/ex/cbezier3.rb +40 -0
  29. data/doc/ex/cbezier4.rb +41 -0
  30. data/doc/ex/cbezier5.rb +41 -0
  31. data/doc/ex/cbezier6.rb +51 -0
  32. data/doc/ex/channel.rb +26 -0
  33. data/doc/ex/channel_threshold.rb +48 -0
  34. data/doc/ex/charcoal.rb +12 -0
  35. data/doc/ex/chop.rb +29 -0
  36. data/doc/ex/circle.rb +31 -0
  37. data/doc/ex/clip_path.rb +56 -0
  38. data/doc/ex/coalesce.rb +60 -0
  39. data/doc/ex/color_fill_to_border.rb +29 -0
  40. data/doc/ex/color_floodfill.rb +28 -0
  41. data/doc/ex/color_histogram.rb +60 -0
  42. data/doc/ex/color_reset.rb +11 -0
  43. data/doc/ex/colorize.rb +16 -0
  44. data/doc/ex/colors.rb +65 -0
  45. data/doc/ex/composite.rb +135 -0
  46. data/doc/ex/contrast.rb +37 -0
  47. data/doc/ex/crop.rb +31 -0
  48. data/doc/ex/crop_with_gravity.rb +46 -0
  49. data/doc/ex/cycle_colormap.rb +21 -0
  50. data/doc/ex/demo.rb +324 -0
  51. data/doc/ex/drawcomp.rb +42 -0
  52. data/doc/ex/drop_shadow.rb +60 -0
  53. data/doc/ex/edge.rb +11 -0
  54. data/doc/ex/ellipse.rb +43 -0
  55. data/doc/ex/emboss.rb +11 -0
  56. data/doc/ex/enhance.rb +28 -0
  57. data/doc/ex/equalize.rb +11 -0
  58. data/doc/ex/flatten_images.rb +38 -0
  59. data/doc/ex/flip.rb +11 -0
  60. data/doc/ex/flop.rb +11 -0
  61. data/doc/ex/fonts.rb +20 -0
  62. data/doc/ex/frame.rb +12 -0
  63. data/doc/ex/gaussian_blur.rb +11 -0
  64. data/doc/ex/get_multiline_type_metrics.rb +53 -0
  65. data/doc/ex/get_pixels.rb +48 -0
  66. data/doc/ex/get_type_metrics.rb +140 -0
  67. data/doc/ex/gradientfill.rb +27 -0
  68. data/doc/ex/grav.rb +44 -0
  69. data/doc/ex/gravity.rb +80 -0
  70. data/doc/ex/hatchfill.rb +27 -0
  71. data/doc/ex/images/Ballerina.jpg +0 -0
  72. data/doc/ex/images/Ballerina3.jpg +0 -0
  73. data/doc/ex/images/Button_0.gif +0 -0
  74. data/doc/ex/images/Button_1.gif +0 -0
  75. data/doc/ex/images/Button_2.gif +0 -0
  76. data/doc/ex/images/Button_3.gif +0 -0
  77. data/doc/ex/images/Button_4.gif +0 -0
  78. data/doc/ex/images/Button_5.gif +0 -0
  79. data/doc/ex/images/Button_6.gif +0 -0
  80. data/doc/ex/images/Button_7.gif +0 -0
  81. data/doc/ex/images/Button_8.gif +0 -0
  82. data/doc/ex/images/Button_9.gif +0 -0
  83. data/doc/ex/images/Button_A.gif +0 -0
  84. data/doc/ex/images/Button_B.gif +0 -0
  85. data/doc/ex/images/Button_C.gif +0 -0
  86. data/doc/ex/images/Button_D.gif +0 -0
  87. data/doc/ex/images/Button_E.gif +0 -0
  88. data/doc/ex/images/Button_F.gif +0 -0
  89. data/doc/ex/images/Button_G.gif +0 -0
  90. data/doc/ex/images/Button_H.gif +0 -0
  91. data/doc/ex/images/Button_I.gif +0 -0
  92. data/doc/ex/images/Button_J.gif +0 -0
  93. data/doc/ex/images/Button_K.gif +0 -0
  94. data/doc/ex/images/Button_L.gif +0 -0
  95. data/doc/ex/images/Button_M.gif +0 -0
  96. data/doc/ex/images/Button_N.gif +0 -0
  97. data/doc/ex/images/Button_O.gif +0 -0
  98. data/doc/ex/images/Button_P.gif +0 -0
  99. data/doc/ex/images/Button_Q.gif +0 -0
  100. data/doc/ex/images/Button_R.gif +0 -0
  101. data/doc/ex/images/Button_S.gif +0 -0
  102. data/doc/ex/images/Button_T.gif +0 -0
  103. data/doc/ex/images/Button_U.gif +0 -0
  104. data/doc/ex/images/Button_V.gif +0 -0
  105. data/doc/ex/images/Button_W.gif +0 -0
  106. data/doc/ex/images/Button_X.gif +0 -0
  107. data/doc/ex/images/Button_Y.gif +0 -0
  108. data/doc/ex/images/Button_Z.gif +0 -0
  109. data/doc/ex/images/Cheetah.jpg +0 -0
  110. data/doc/ex/images/Coffee.wmf +0 -0
  111. data/doc/ex/images/Flower_Hat.jpg +0 -0
  112. data/doc/ex/images/Gold_Statue.jpg +0 -0
  113. data/doc/ex/images/Hot_Air_Balloons.jpg +0 -0
  114. data/doc/ex/images/Hot_Air_Balloons_H.jpg +0 -0
  115. data/doc/ex/images/No.wmf +0 -0
  116. data/doc/ex/images/Polynesia.jpg +0 -0
  117. data/doc/ex/images/Red_Rocks.jpg +0 -0
  118. data/doc/ex/images/Shorts.jpg +0 -0
  119. data/doc/ex/images/Snake.wmf +0 -0
  120. data/doc/ex/images/Violin.jpg +0 -0
  121. data/doc/ex/images/graydient230x6.gif +0 -0
  122. data/doc/ex/images/logo400x83.gif +0 -0
  123. data/doc/ex/images/model.miff +0 -0
  124. data/doc/ex/images/notimplemented.gif +0 -0
  125. data/doc/ex/images/smile.miff +0 -0
  126. data/doc/ex/images/spin.gif +0 -0
  127. data/doc/ex/implode.rb +32 -0
  128. data/doc/ex/level.rb +12 -0
  129. data/doc/ex/level_channel.rb +33 -0
  130. data/doc/ex/line.rb +40 -0
  131. data/doc/ex/map.rb +28 -0
  132. data/doc/ex/map_f.rb +15 -0
  133. data/doc/ex/matte_fill_to_border.rb +42 -0
  134. data/doc/ex/matte_floodfill.rb +35 -0
  135. data/doc/ex/matte_replace.rb +42 -0
  136. data/doc/ex/median_filter.rb +28 -0
  137. data/doc/ex/modulate.rb +11 -0
  138. data/doc/ex/mono.rb +23 -0
  139. data/doc/ex/morph.rb +26 -0
  140. data/doc/ex/mosaic.rb +35 -0
  141. data/doc/ex/motion_blur.rb +11 -0
  142. data/doc/ex/negate.rb +11 -0
  143. data/doc/ex/negate_channel.rb +19 -0
  144. data/doc/ex/normalize.rb +11 -0
  145. data/doc/ex/oil_paint.rb +11 -0
  146. data/doc/ex/opacity.rb +38 -0
  147. data/doc/ex/opaque.rb +14 -0
  148. data/doc/ex/ordered_dither.rb +11 -0
  149. data/doc/ex/path.rb +62 -0
  150. data/doc/ex/pattern1.rb +25 -0
  151. data/doc/ex/pattern2.rb +26 -0
  152. data/doc/ex/polygon.rb +24 -0
  153. data/doc/ex/polyline.rb +23 -0
  154. data/doc/ex/posterize.rb +19 -0
  155. data/doc/ex/preview.rb +16 -0
  156. data/doc/ex/qbezierpath.rb +49 -0
  157. data/doc/ex/quantize-m.rb +25 -0
  158. data/doc/ex/radial_blur.rb +19 -0
  159. data/doc/ex/raise.rb +11 -0
  160. data/doc/ex/random_channel_threshold.rb +17 -0
  161. data/doc/ex/random_threshold_channel.rb +18 -0
  162. data/doc/ex/rectangle.rb +33 -0
  163. data/doc/ex/reduce_noise.rb +28 -0
  164. data/doc/ex/roll.rb +9 -0
  165. data/doc/ex/rotate.rb +43 -0
  166. data/doc/ex/rotate_f.rb +14 -0
  167. data/doc/ex/roundrect.rb +32 -0
  168. data/doc/ex/rubyname.rb +31 -0
  169. data/doc/ex/segment.rb +11 -0
  170. data/doc/ex/shade.rb +11 -0
  171. data/doc/ex/shave.rb +15 -0
  172. data/doc/ex/shear.rb +10 -0
  173. data/doc/ex/skewx.rb +50 -0
  174. data/doc/ex/skewy.rb +45 -0
  175. data/doc/ex/smile.rb +124 -0
  176. data/doc/ex/solarize.rb +11 -0
  177. data/doc/ex/splice.rb +16 -0
  178. data/doc/ex/spread.rb +11 -0
  179. data/doc/ex/stegano.rb +50 -0
  180. data/doc/ex/stroke_dasharray.rb +41 -0
  181. data/doc/ex/stroke_linecap.rb +44 -0
  182. data/doc/ex/stroke_linejoin.rb +48 -0
  183. data/doc/ex/stroke_width.rb +47 -0
  184. data/doc/ex/swirl.rb +17 -0
  185. data/doc/ex/text.rb +32 -0
  186. data/doc/ex/text_align.rb +36 -0
  187. data/doc/ex/text_antialias.rb +33 -0
  188. data/doc/ex/text_undercolor.rb +26 -0
  189. data/doc/ex/texture_fill_to_border.rb +34 -0
  190. data/doc/ex/texture_floodfill.rb +31 -0
  191. data/doc/ex/texturefill.rb +25 -0
  192. data/doc/ex/threshold.rb +13 -0
  193. data/doc/ex/to_blob.rb +14 -0
  194. data/doc/ex/translate.rb +37 -0
  195. data/doc/ex/transparent.rb +38 -0
  196. data/doc/ex/trim.rb +25 -0
  197. data/doc/ex/unsharp_mask.rb +28 -0
  198. data/doc/ex/viewex.rb +36 -0
  199. data/doc/ex/wave.rb +9 -0
  200. data/doc/ilist.html +1592 -0
  201. data/doc/image1.html +3009 -0
  202. data/doc/image2.html +2169 -0
  203. data/doc/image3.html +2815 -0
  204. data/doc/imageattrs.html +1319 -0
  205. data/doc/imusage.html +403 -0
  206. data/doc/index.html +418 -0
  207. data/doc/info.html +949 -0
  208. data/doc/magick.html +439 -0
  209. data/doc/scripts/doc.js +9 -0
  210. data/doc/struct.html +1334 -0
  211. data/doc/usage.html +1318 -0
  212. data/examples/describe.rb +44 -0
  213. data/examples/histogram.rb +289 -0
  214. data/examples/image_opacity.rb +29 -0
  215. data/examples/import_export.rb +31 -0
  216. data/examples/pattern_fill.rb +38 -0
  217. data/examples/rotating_text.rb +47 -0
  218. data/examples/thumbnail.rb +65 -0
  219. data/examples/vignette.rb +79 -0
  220. data/ext/RMagick/MANIFEST +239 -0
  221. data/ext/RMagick/extconf.rb.in +21 -0
  222. data/ext/RMagick/rmagick.h +938 -0
  223. data/ext/RMagick/rmagick_config.h.in +170 -0
  224. data/ext/RMagick/rmdraw.c +1308 -0
  225. data/ext/RMagick/rmfill.c +609 -0
  226. data/ext/RMagick/rmilist.c +685 -0
  227. data/ext/RMagick/rmimage.c +7980 -0
  228. data/ext/RMagick/rminfo.c +982 -0
  229. data/ext/RMagick/rmmain.c +1497 -0
  230. data/ext/RMagick/rmutil.c +2685 -0
  231. data/install.rb +1015 -0
  232. data/lib/RMagick.rb +1486 -0
  233. data/metaconfig.in +6 -0
  234. data/post-clean.rb +12 -0
  235. data/post-install.rb +36 -0
  236. data/post-setup.rb +245 -0
  237. data/rmagick.gemspec +22 -0
  238. data/uninstall.rb +71 -0
  239. metadata +286 -0
@@ -0,0 +1,44 @@
1
+
2
+ # Purpose: Demonstrate getting information from the image attributes.
3
+ # Usage: describe.rb filename1 [filename2...]
4
+ # Notes: The output is similar to ImageMagick's identify command.
5
+
6
+ require 'RMagick'
7
+
8
+ puts <<END_INFO
9
+
10
+ This example shows how to extract attributes from an image.
11
+
12
+ END_INFO
13
+
14
+ if ARGV.length == 0
15
+ puts "Specify one or more image filenames as arguments."
16
+ exit
17
+ end
18
+
19
+
20
+ ARGV.each { |file|
21
+ puts file
22
+ img = Magick::Image::read(file).first
23
+ puts " Format: #{img.format}"
24
+ puts " Geometry: #{img.columns}x#{img.rows}"
25
+ puts " Class: " + case img.class_type
26
+ when Magick::DirectClass
27
+ "DirectClass"
28
+ when Magick::PseudoClass
29
+ "PseudoClass"
30
+ end
31
+ puts " Depth: #{img.depth} bits-per-pixel"
32
+ puts " Colors: #{img.number_colors}"
33
+ puts " Filesize: #{img.filesize}"
34
+ puts " Resolution: #{img.x_resolution.to_i}x#{img.y_resolution.to_i} "+
35
+ "pixels/#{img.units == Magick::PixelsPerInchResolution ?
36
+ "inch" : "centimeter"}"
37
+
38
+ if img.properties.length > 0
39
+ puts " Properties:"
40
+ img.properties { |name,value|
41
+ puts %Q| #{name} = "#{value}"|
42
+ }
43
+ end
44
+ }
@@ -0,0 +1,289 @@
1
+ # This routine needs the color_histogram method
2
+ # from either ImageMagick 6.0.0 or GraphicsMagick 1.1
3
+ # Specify an image filename as an argument.
4
+
5
+ require 'RMagick'
6
+
7
+ module Magick
8
+ class Image
9
+
10
+ private
11
+ HISTOGRAM_COLS = 256
12
+ HISTOGRAM_ROWS = 200
13
+ AIR_FACTOR = 1.025
14
+
15
+ # The alpha frequencies are shown as white dots.
16
+ def alpha_hist(freqs, scale, fg, bg)
17
+ histogram = Image.new(HISTOGRAM_COLS, HISTOGRAM_ROWS) {
18
+ self.background_color = bg
19
+ self.border_color = fg
20
+ }
21
+
22
+ gc = Draw.new
23
+ gc.affine(1, 0, 0, -scale, 0, HISTOGRAM_ROWS)
24
+ gc.fill('white')
25
+
26
+ HISTOGRAM_COLS.times do |x|
27
+ gc.point(x, freqs[x])
28
+ end
29
+
30
+ gc.draw(histogram)
31
+ histogram['Label'] = 'Alpha'
32
+
33
+ return histogram
34
+ end
35
+
36
+ def channel_histograms(red, green, blue, int, scale, fg, bg)
37
+ rgb_histogram = Image.new(HISTOGRAM_COLS, HISTOGRAM_ROWS) {
38
+ self.background_color = bg
39
+ self.border_color = fg
40
+ }
41
+ rgb_histogram['Label'] = 'RGB'
42
+ red_histogram = rgb_histogram.copy
43
+ red_histogram['Label'] = 'Red'
44
+ green_histogram = rgb_histogram.copy
45
+ green_histogram['Label'] = 'Green'
46
+ blue_histogram = rgb_histogram.copy
47
+ blue_histogram['Label'] = 'Blue'
48
+ int_histogram = rgb_histogram.copy
49
+ int_histogram['Label'] = 'Intensity'
50
+ int_histogram.matte = true
51
+
52
+ HISTOGRAM_COLS.times do |x|
53
+ rgb_column = Array.new(HISTOGRAM_ROWS).fill {Pixel.new}
54
+ red_column = Array.new(HISTOGRAM_ROWS).fill {Pixel.new}
55
+ green_column = Array.new(HISTOGRAM_ROWS).fill {Pixel.new}
56
+ blue_column = Array.new(HISTOGRAM_ROWS).fill {Pixel.new}
57
+ int_column = Array.new(HISTOGRAM_ROWS).fill {Pixel.new}
58
+ HISTOGRAM_ROWS.times do |y|
59
+
60
+ yf = Float(y)
61
+ if yf >= HISTOGRAM_ROWS - (red[x] * scale)
62
+ red_column[y].red = MaxRGB
63
+ rgb_column[y].red = MaxRGB
64
+ end
65
+ if yf >= HISTOGRAM_ROWS - (green[x] * scale)
66
+ green_column[y].green = MaxRGB
67
+ rgb_column[y].green = MaxRGB
68
+ end
69
+ if yf >= HISTOGRAM_ROWS - (blue[x] * scale)
70
+ blue_column[y].blue = MaxRGB
71
+ rgb_column[y].blue = MaxRGB
72
+ end
73
+ if yf >= HISTOGRAM_ROWS - (int[x] * scale)
74
+ int_column[y].opacity = TransparentOpacity
75
+ end
76
+ end
77
+ rgb_histogram.store_pixels( x, 0, 1, HISTOGRAM_ROWS, rgb_column)
78
+ red_histogram.store_pixels( x, 0, 1, HISTOGRAM_ROWS, red_column)
79
+ green_histogram.store_pixels(x, 0, 1, HISTOGRAM_ROWS, green_column)
80
+ blue_histogram.store_pixels( x, 0, 1, HISTOGRAM_ROWS, blue_column)
81
+ int_histogram.store_pixels( x, 0, 1, HISTOGRAM_ROWS, int_column)
82
+ end
83
+
84
+ return red_histogram, green_histogram, blue_histogram, rgb_histogram, int_histogram
85
+ end
86
+
87
+ # Make the color histogram. Quantize the image to 256 colors if necessary.
88
+ def color_hist(fg, bg)
89
+ img = number_colors > 256 ? quantize(256) : self
90
+
91
+ begin
92
+ hist = img.color_histogram
93
+ rescue NotImplementedError
94
+ $stderr.puts "The color_histogram method is not supported by this version "+
95
+ "of ImageMagick/GraphicsMagick"
96
+
97
+ else
98
+ pixels = hist.keys.sort_by {|pixel| hist[pixel] }
99
+ scale = HISTOGRAM_ROWS / (hist.values.max*AIR_FACTOR)
100
+
101
+ histogram = Image.new(HISTOGRAM_COLS, HISTOGRAM_ROWS) {
102
+ self.background_color = bg
103
+ self.border_color = fg
104
+ }
105
+
106
+ x = 0
107
+ pixels.each do |pixel|
108
+ column = Array.new(HISTOGRAM_ROWS).fill {Pixel.new}
109
+ HISTOGRAM_ROWS.times do |y|
110
+ if y >= HISTOGRAM_ROWS - (hist[pixel] * scale)
111
+ column[y] = pixel;
112
+ end
113
+ end
114
+ histogram.store_pixels(x, 0, 1, HISTOGRAM_ROWS, column)
115
+ x = x.succ
116
+ end
117
+
118
+ histogram['Label'] = 'Color Frequency'
119
+ return histogram
120
+ end
121
+ end
122
+
123
+ # Use AnnotateImage to write the stats.
124
+ def info_text(fg, bg)
125
+ klass = class_type == DirectClass ? "DirectClass" : "PsuedoClass"
126
+
127
+ text = <<-END_TEXT
128
+ Format: #{format}
129
+ Geometry: #{columns}x#{rows}
130
+ Class: #{klass}
131
+ Depth: #{depth} bits-per-pixel component
132
+ Colors: #{number_colors}
133
+ END_TEXT
134
+
135
+ info = Image.new(HISTOGRAM_COLS, HISTOGRAM_ROWS) {
136
+ self.background_color = bg
137
+ self.border_color = fg
138
+ }
139
+
140
+ gc = Draw.new
141
+
142
+ gc.annotate(info, 0, 0, 0, 0, text) {
143
+ self.stroke = 'transparent'
144
+ self.fill = fg
145
+ self.gravity = CenterGravity
146
+ }
147
+ info['Label'] = 'Info'
148
+
149
+ return info
150
+ end
151
+
152
+ def intensity_hist(int_histogram)
153
+
154
+ gradient = (Image.read("gradient:#ffff80-#ff9000") { self.size="#{HISTOGRAM_COLS}x#{HISTOGRAM_ROWS}" }).first
155
+ int_histogram = gradient.composite(int_histogram, CenterGravity, OverCompositeOp)
156
+
157
+ int_histogram['Label'] = 'Intensity'
158
+
159
+ return int_histogram
160
+ end
161
+
162
+ # Returns a value between 0 and 255. Same as the PixelIntensity macro.
163
+ def pixel_intensity(pixel)
164
+ (306*pixel.red + 601*pixel.green + 117*pixel.blue)/1024
165
+ end
166
+
167
+ public
168
+ # Create the histogram montage.
169
+ def histogram(fg='white', bg='black')
170
+
171
+ red = Array.new(HISTOGRAM_COLS, 0)
172
+ green = Array.new(HISTOGRAM_COLS, 0)
173
+ blue = Array.new(HISTOGRAM_COLS, 0)
174
+ alpha = Array.new(HISTOGRAM_COLS, 0)
175
+ int = Array.new(HISTOGRAM_COLS, 0)
176
+
177
+ rows.times do |row|
178
+ pixels = get_pixels(0, row, columns, 1)
179
+ pixels.each do |pixel|
180
+ red[pixel.red] += 1
181
+ green[pixel.green] += 1
182
+ blue[pixel.blue] += 1
183
+
184
+ # Only count opacity channel if some pixels are not opaque.
185
+ if !opaque?
186
+ alpha[pixel.opacity] += 1
187
+ end
188
+ v = pixel_intensity(pixel)
189
+ int[v] += 1
190
+ end
191
+ end
192
+
193
+ # Scale to chart size. When computing the scale, add some "air" between
194
+ # the max frequency and the top of the histogram. This makes a prettier chart.
195
+ # The RGBA and intensity histograms are all drawn to the same scale.
196
+ max = [red.max, green.max, blue.max, alpha.max, int.max].max
197
+ scale = HISTOGRAM_ROWS / (max*AIR_FACTOR)
198
+
199
+ charts = ImageList.new
200
+
201
+ # Add the thumbnail.
202
+ thumb = copy
203
+ thumb['Label'] = File.basename(filename)
204
+ charts << thumb
205
+
206
+ # Compute the channel and intensity histograms.
207
+ channel_hists = channel_histograms(red, green, blue, int, scale, fg, bg)
208
+
209
+ # Add the red, green, and blue histograms to the list
210
+ charts << channel_hists.shift
211
+ charts << channel_hists.shift
212
+ charts << channel_hists.shift
213
+
214
+ # Add Alpha channel or image stats
215
+ if !opaque?
216
+ charts << alpha_hist(alpha, scale, fg, bg)
217
+ else
218
+ charts << info_text(fg, bg)
219
+ end
220
+
221
+ # Add the RGB histogram
222
+ charts << channel_hists.shift
223
+
224
+ # Add the intensity histogram.
225
+ charts << intensity_hist(channel_hists.shift)
226
+
227
+ # Add the color frequency histogram.
228
+ charts << color_hist(fg, bg)
229
+
230
+ # Make a montage.
231
+ histogram = charts.montage {
232
+ self.background_color = bg
233
+ self.stroke = 'transparent'
234
+ self.fill = fg
235
+ self.border_width = 1
236
+ self.tile = "4x2"
237
+ self.geometry = "#{HISTOGRAM_COLS}x#{HISTOGRAM_ROWS}+10+10"
238
+ }
239
+
240
+ return histogram
241
+ end
242
+ end
243
+ end
244
+
245
+ puts <<END_INFO
246
+
247
+ This example shows how to get pixel-level access to an image.
248
+ Usage: histogram.rb <image-filename>
249
+
250
+ END_INFO
251
+
252
+ # Get filename from command line.
253
+ if !ARGV[0] then
254
+ puts "No filename argument. Defaulting to Flower_Hat.jpg"
255
+ filename = '../doc/ex/images/Flower_Hat.jpg'
256
+ else
257
+ filename = ARGV[0]
258
+ end
259
+
260
+ # Only process first frame if multi-frame image
261
+ image = Magick::Image.read(filename)
262
+ if image.length > 1
263
+ puts "Charting 1st image"
264
+ end
265
+ image = image.first
266
+
267
+ # Give the user something to look at while we're working.
268
+ name = File.basename(filename).sub(/\..*?$/,'')
269
+ $defout.sync = true
270
+ printf "Creating #{name}_Histogram.miff"
271
+
272
+ timer = Thread.new do
273
+ loop do
274
+ sleep(1)
275
+ printf "."
276
+ end
277
+ end
278
+
279
+ # Generate the histograms
280
+ histogram = image.histogram
281
+
282
+ # Write output file
283
+ histogram.compression = Magick::ZipCompression
284
+ histogram.write("./#{name}_Histogram.miff")
285
+
286
+ Thread.kill(timer)
287
+ puts "Done!"
288
+ exit
289
+
@@ -0,0 +1,29 @@
1
+
2
+ # Ccreate a semi-transparent title for an image.
3
+
4
+ require 'RMagick'
5
+ include Magick
6
+
7
+ puts <<END_INFO
8
+
9
+ This example uses a semi-transparent background color to create a title.
10
+ View the resulting image by entering the command: display image_opacity.miff
11
+
12
+ END_INFO
13
+
14
+ balloons = Image.read('../doc/ex/images/Hot_Air_Balloons_H.jpg').first
15
+ legend = Image.new(160, 50) { self.background_color = '#ffffffc0' }
16
+
17
+ gc = Draw.new
18
+ gc.annotate(legend, 0, 0, 0, 0, "Balloon Day!\\nFri May 2 2003") {
19
+ self.gravity = CenterGravity
20
+ self.stroke = 'transparent'
21
+ self.fill = 'white'
22
+ self.pointsize = 18
23
+ }
24
+
25
+ result = balloons.composite(legend, SouthGravity, OverCompositeOp)
26
+
27
+ puts "...Writing image_opacity.miff"
28
+ result.write 'image_opacity.miff'
29
+ exit
@@ -0,0 +1,31 @@
1
+ #
2
+ # Demonstrate the export_pixels and import_pixels methods.
3
+ #
4
+
5
+ require 'RMagick'
6
+ include Magick
7
+
8
+ puts <<END_INFO
9
+
10
+ This example demonstrates the export_pixels and import_pixels methods
11
+ by copying an image one row at a time. The result is an copy that
12
+ is identical to the original.
13
+
14
+ END_INFO
15
+
16
+ img = Image.read('../doc/ex/images/Gold_Statue.jpg').first
17
+ copy = Image.new(img.columns, img.rows);
18
+
19
+ begin
20
+ img.rows.times { |r|
21
+ scanline = img.export_pixels(0, r, img.columns, 1, "RGB");
22
+ copy.import_pixels(0, r, img.columns, 1, "RGB", scanline);
23
+ }
24
+ rescue NotImplementedError
25
+ $stderr.puts "The export_pixels and import_pixels methods are not supported" +
26
+ " by this version of ImageMagick/GraphicsMagick"
27
+ exit
28
+ end
29
+
30
+ copy.display
31
+ exit
@@ -0,0 +1,38 @@
1
+
2
+ # Demonstrate ImageMagick's new (5.5.7-3 and later) built-in patterns.
3
+ # Create a Fill class that can be reused to fill in new Image backgrounds.
4
+
5
+ # Usage: pattern_fill.rb <name-of-pattern>
6
+ # Try 'checkerboard' or 'verticalsaw'
7
+
8
+ require 'RMagick'
9
+ include Magick
10
+
11
+ puts <<END_INFO
12
+
13
+ This example demonstrates the PATTERN: image format, which is
14
+ new in ImageMagick 5.5.7. Specify the name of any of the
15
+ supported patterns as an argument. For example, try "checkerboard".
16
+
17
+ END_INFO
18
+
19
+ class PatternFill < Magick::TextureFill
20
+ def initialize(name='bricks')
21
+ @pat_img = Magick::Image.read("pattern:#{name}").first
22
+ super(@pat_img)
23
+ end
24
+ end
25
+
26
+ if ARGV[0]
27
+ pattern = ARGV[0]
28
+ else
29
+ $stderr.puts "Defaulting to checkerboard pattern."
30
+ pattern = 'checkerboard'
31
+ end
32
+
33
+ # Create a sample image that is 100x bigger than the pattern.
34
+ attrs = Image.ping("pattern:#{pattern}").first
35
+
36
+ tryit = Image.new(10*attrs.columns, 10*attrs.rows, PatternFill.new(pattern))
37
+ tryit.display
38
+ exit
@@ -0,0 +1,47 @@
1
+ # Demonstrate the Draw#rotation= method by producing
2
+ # an animated MIFF file showing a rotating text string.
3
+
4
+
5
+ require 'RMagick'
6
+ include Magick
7
+
8
+ puts <<END_INFO
9
+ Demonstrate the rotation= attribute in the Draw class
10
+ by producing an animated image. View the output image
11
+ by entering the command: animate rotating_text.miff
12
+ END_INFO
13
+
14
+ text = Draw.new
15
+ text.pointsize = 28
16
+ text.font_weight = BoldWeight
17
+ text.font_style = ItalicStyle
18
+ text.gravity = CenterGravity
19
+
20
+ # Let's make it interesting. Composite the
21
+ # rotated text over a gradient fill background.
22
+ fill = GradientFill.new(100,100,100,100,"yellow","red")
23
+ bg = Image.new(200, 200, fill)
24
+
25
+ # The "none" color is transparent.
26
+ fg = Image.new(bg.columns, bg.rows) { self.background_color = "none" }
27
+
28
+ # Here's where we'll collect the individual frames.
29
+ animation = ImageList.new
30
+
31
+ 0.step(345,15) { |degrees|
32
+ frame = fg.copy
33
+ text.annotate(frame, 0,0,0,0, "Rotating Text") {
34
+ self.rotation = degrees
35
+ }
36
+ # Composite the text over the gradient filled background frame.
37
+ animation << bg.composite(frame, CenterGravity, DisplaceCompositeOp)
38
+ }
39
+
40
+ animation.delay = 8
41
+
42
+ # ignored if ImageMagick not configured with ZLIB
43
+ animation.compression = ZipCompression
44
+ #animation.animate
45
+ puts "...Writing rotating_text.miff"
46
+ animation.write("rotating_text.miff")
47
+ exit