Sha256: 6621a2c2da2dd160b630ffc4de561bbe5511df84d28eeb49b8b5e7b18a33bbca

Contents?: true

Size: 1.8 KB

Versions: 37

Compression:

Stored size: 1.8 KB

Contents

#! /usr/local/bin/ruby -w
require 'RMagick'
include Magick

puts("Creating colors.miff. This may take a few seconds...")

colors = 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.
colors { |c|
    if c.name !~ /grey/ then    # omit SVG 'grays'
        colors.new_image(200, 25) {
            self.background_color = c.color
            self.border_color = 'gray50'
            }
        rgb  = sprintf('#%02x%02x%02x', c.color.red&0xff,  c.color.green&0xff, c.color.blue&0xff)
        rgb += sprintf('%02x', c.color.opacity&0xff) if c.color.opacity != 0
        m = /(.*?)Compliance/.match c.compliance.to_s
        colors.cur_image['Label'] = "#{c.name} (#{rgb}) #{m[1]}"
    end
}

puts("\tCreating montage...")

# Montage. Each image will have 40 tiles.
# There will be 16 images.
montage = colors.montage {
    self.geometry = '200x25+10+5'
    self.gravity = CenterGravity
    self.tile = '4x10'
    self.background_color = 'black'
    self.border_width = 1
    self.fill = 'white'
    self.stroke = 'transparent'
}

# Add the title at the top, over the 'null:'
# tiles we added at the very beginning.
title = Draw.new
title.annotate(montage, 0,0,0,20, 'Named Colors') {
    self.fill = 'white'
    self.stroke = 'transparent'
    self.pointsize = 32
    self.font_weight = BoldWeight
    self.gravity = NorthGravity
}

puts("\tWriting ./colors.miff")
montage.each { |f| f.compression = 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 = Rectangle.new(495,110)
sample.write('colors.gif')

exit

Version data entries

37 entries across 37 versions & 2 rubygems

Version Path
rmagick-2.13.4 doc/ex/colors.rb
rmagick-2.13.3 doc/ex/colors.rb
rmagick-2.13.3.rc1 doc/ex/colors.rb
rmagick-2.13.2 doc/ex/colors.rb
rdp-rmagick-0.0.0 doc/ex/colors.rb
rmagick-2.13.1 doc/ex/colors.rb
rmagick-2.12.2 doc/ex/colors.rb
rmagick-2.12.1 doc/ex/colors.rb
rmagick-2.12.0 doc/ex/colors.rb
rmagick-2.11.1 doc/ex/colors.rb
rmagick-2.10.0 doc/ex/colors.rb
rmagick-2.11.0 doc/ex/colors.rb
rmagick-1.15.10 doc/ex/colors.rb
rmagick-1.15.11 doc/ex/colors.rb
rmagick-1.15.13 doc/ex/colors.rb
rmagick-1.15.12 doc/ex/colors.rb
rmagick-1.15.14 doc/ex/colors.rb
rmagick-1.15.15 doc/ex/colors.rb
rmagick-1.15.16 doc/ex/colors.rb
rmagick-1.15.17 doc/ex/colors.rb