Last active
September 14, 2016 08:08
-
-
Save pokotyamu/d7240120ca0b5d758e163eed875ee7a6 to your computer and use it in GitHub Desktop.
文字書き込み
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' | |
path = 'test.jpeg' | |
image = Magick::ImageList.new("./images/#{File.basename(path)}") | |
# フォントの指定がないと日本語辛い | |
font = "./fonts/GenJyuuGothic-Normal.ttf" | |
draw = Magick::Draw.new | |
draw.font(font) | |
draw.pointsize(30) | |
# | |
# 右下に固定 | |
# http://www.simplesystems.org/RMagick/doc/draw.html#gravity | |
# | |
draw.gravity(Magick::SouthEastGravity) | |
draw.font_weight('bold') | |
# 文字の裏を白にする | |
draw.text_undercolor('white') | |
draw.text(20, 20, '値下げ') | |
# 画像に書き込み | |
draw.draw(image) | |
# 出力 | |
image.write("./images/string_#{File.basename(path)}") # save to file | |
image.destroy! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
画像の配置先の一覧