LoginSignup
2
2

More than 5 years have passed since last update.

IMGkitとRMagickを使ってURLスクリーンキャプチャにHello Worldしてみた

Posted at

動機

ハロワしなきゃいけないという強迫観念に囚われた

やること

  1. IMGKitを使ってURLのスクリーンキャプチャを取得する事
  2. 取得した画像をRMagickを使って加工する事
  3. 加工した画像にHello Worldを確認する事

使うもの

IMGKitでスクリーンキャプチャを取得

  # file_path生成
  file_path = "#{SecureRandom.hex(40)}.png"
  img = IMGkit.new(`http://example.com`)
  img.to_file(file_path)

RMagickで画像加工

   require 'RMagick'
   text = "Hello World!!!"
   img = Magick::ImageList.new(file_path)
   draw = Magick::Draw.new

   # 文字を白色で縁取り
   draw.annotate(img, 0, 0, 3, 3, text) do
     self.fill = 'red'
     self.gravity = Magick::SouthEastGravity
     self.pointsize = 30
     self.stroke = 'white'
     self.stroke_width = 4
     self.text_antialias = true
   end
   # Hello World!!!設定
   draw.annotate(img, 0, 0, 3, 3, text) do
     self.fill = 'red'
     self.gravity = Magick::SouthEastGravity
     self.pointsize = 30
     self.stroke = 'transparent'
     self.text_antialias = true
   end

ハロワ確認

57cbb40ffad2ddfc286df9336d7959f38e682b4a1a40001a0db724731ae7d2dfe1f842a85ccb411f.png

参考

Railsでhtmlファイルやリンク先のスクリーンショットを撮影~IMGKit&wkhtmltoimage
RMagickでフォント名を指定して文字列を描画する

 ⊂[J(´ー`)し
  / (⌒マ
 (⌒\ヘ」つ
  > _)、
  じ \_)\\\

  Hello World!!!

        (⌒
     ⌒Y⌒
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2