7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

RubyでWeb画面キャプチャして切り取る

Last updated at Posted at 2016-01-16

環境

# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)

セットアップ

install

package

# yum -y install firefox
# yum -y install xorg-x11-server-Xvfb
# yum -y install ImageMagick.x86_64 ImageMagick-devel.x86_64
# yum -y groupinstall "Japanese Support"
# yum -y install ipa-pgothic-fonts.noarch

gem

# gem install selenium-webdriver
# gem install rmagick

設定

# vi ~/.vi ~/.bash_profile
export DISPLAY=:1

起動

# Xvfb :1 -screen 0 1024x768x24 &
# firefox &

コード

#! /usr/bin/env ruby

require "selenium-webdriver"
require 'rmagick'

driver = Selenium::WebDriver.for :firefox
driver.get("http://counting.hatelabo.jp/count/hei5ifub5x")
driver.save_screenshot("hatena_counting.png")
driver.quit

image = Magick::ImageList.new("hatena_counting.png").crop(0, 68, 502, 250)
image.write("hatena_counting500x250.png")

hatena_counting500x250.png

7
6
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
7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?