Last active
October 29, 2019 08:37
-
-
Save komasaru/6229272 to your computer and use it in GitHub Desktop.
Ruby script to generate a image of available fonts on RMagick.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'RMagick' | |
F_SIZE = 24 # フォントサイズ (pt) | |
FILE = "font_list.png" # 出力ファイル名 | |
class RmagickAvailableFonts | |
# フォント一覧画像作成 | |
def make_image | |
fonts = Magick.fonts # フォント一覧 | |
image = Magick::Image.new(600, (F_SIZE + 20) * fonts.size + 10) { # 画像オブジェクト | |
self.background_color = '#DDDDCC' | |
} | |
draw = Magick::Draw.new # 描画オブジェクト | |
begin | |
# 全フォントについて LOOP | |
fonts.each_with_index do |f, i| | |
# コンソール出力 | |
puts "#{sprintf("%3d", i + 1)}: #{f.name}" | |
# 描画 | |
# (次のフォントは 20pt 下へずらす) | |
draw.annotate(image, 0, 0, 10, 10 + (F_SIZE + 20) * i, "#{i + 1}: #{f.name}") do | |
self.font = f.name # フォント名 | |
self.fill = 'black' # フォント塗りつぶし色(黒) | |
self.stroke = 'transparent' # フォント縁取り色(透過) | |
self.pointsize = F_SIZE # フォントサイズ | |
self.gravity = Magick::NorthWestGravity # 描画開始位置(左上) | |
end | |
end | |
# 画像作成 | |
image.write(FILE) | |
rescue => e | |
STDERR.puts "[ERROR][#{self.class.name}.make_image] #{e}" | |
exit 1 | |
end | |
end | |
end | |
# フォント一覧画像作成 | |
obj_main = RmagickAvailableFonts.new | |
obj_main.make_image |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment