-
Notifications
You must be signed in to change notification settings - Fork 2
/
colors.rb.html
89 lines (77 loc) · 2.82 KB
/
colors.rb.html
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
<!DOCTYPE public PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta name="generator" content="ex2html.rb" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/popup.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<script>
hljs.configure({ cssSelector: "pre" });
hljs.highlightAll();
</script>
<title>RMagick example: colors.rb</title>
</head>
<body>
<h1>colors.rb</h1>
<div class="bodybox">
<div class="bodyfloat">
<pre class="language-ruby">
# frozen_string_literal: true
require 'rmagick'
puts('Creating colors.miff. This may take a few seconds...')
colors = Magick::ImageList.new
# Add a row of "null" colors so we'll have
# room to add the title at the top.
4.times { colors.read('null:') }
puts("\tCreating color swatches...")
# Create a 200x25 image for each named color.
# Label with the name, RGB values, and compliance type.
Magick.colors do |c|
unless c.name.include?('grey') # omit SVG 'grays'
colors.new_image(200, 25) do |options|
options.background_color = c.color
options.border_color = 'gray50'
end
rgb = sprintf('#%02x%02x%02x', c.color.red & 0xff, c.color.green & 0xff, c.color.blue & 0xff)
rgb += sprintf('%02x', c.color.alpha & 0xff) if c.color.alpha != Magick::QuantumRange
m = /(.*?)Compliance/.match c.compliance.to_s
colors.cur_image['Label'] = "#{c.name} (#{rgb}) #{m[1]}"
end
end
puts("\tCreating montage...")
# Montage. Each image will have 40 tiles.
# There will be 16 images.
montage = colors.montage do |options|
options.geometry = '200x25+10+5'
options.gravity = Magick::CenterGravity
options.tile = '4x10'
options.background_color = 'black'
options.border_width = 1
options.fill = 'white'
options.stroke = 'transparent'
end
# Add the title at the top, over the 'null:'
# tiles we added at the very beginning.
title = Magick::Draw.new
title.annotate(montage, 0, 0, 0, 20, 'Named Colors') do |options|
options.fill = 'white'
options.stroke = 'transparent'
options.pointsize = 32
options.font_weight = Magick::BoldWeight
options.gravity = Magick::NorthGravity
end
puts("\tWriting ./colors.miff")
montage.each { |f| f.compression = Magick::ZipCompression }
montage.write('colors.miff')
# Make a small sample of the full montage to display in the HTML file.
sample = montage[8].crop(55, 325, 495, 110)
sample.page = Magick::Rectangle.new(495, 110)
sample.write('colors.gif')
exit
</pre>
</div>
</div>
<div id="close"><a href="javascript:window.close();">Close window</a></div>
</body>
</html>