Created
December 11, 2014 16:04
-
-
Save AKB428/01dfc48b253357190a8c to your computer and use it in GitHub Desktop.
コミックマーケット DVD-ROMカタログのデータをプログラムから利用する(サークルカット編) ref: http://qiita.com/AKB428/items/dbb0e073a9ff50b687d3
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 'pathname' | |
require 'fileutils' | |
require 'RMagick' | |
module ComikeCatalogParser | |
class CircleCut | |
WORK_FOLDER_NAME = "./circle_cut" | |
CIRCLE_CUT_SIZE_WIDTH = 165 | |
CIRCLE_CUT_SIZE_HEIGHT = 241 | |
#とりあえず計算せずMAPで持つ 1ページ 6x6=36カット | |
H1 = 70 | |
H2 = 323 | |
H3 = 575 | |
H4 = 828 | |
H5 = 1081 | |
H6 = 1333 | |
W1 = 15 | |
W2 = 192 | |
W3 = 369 | |
W4 = 547 | |
W5 = 724 | |
W6 = 903 | |
CIRCLE_CUT_MAP = | |
[ | |
[W1,H1],[W2,H1],[W3,H1], [W4,H1],[W5,H1],[W6,H1], | |
[W1,H2],[W2,H2],[W3,H2], [W4,H2],[W5,H2],[W6,H2], | |
[W1,H3],[W2,H3],[W3,H3], [W4,H3],[W5,H3],[W6,H3], | |
[W1,H4],[W2,H4],[W3,H4], [W4,H4],[W5,H4],[W6,H4], | |
[W1,H5],[W2,H5],[W3,H5], [W4,H5],[W5,H5],[W6,H5], | |
[W1,H6],[W2,H6],[W3,H6], [W4,H6],[W5,H6],[W6,H6], | |
] | |
def initialize(circle_cut_page_file_path) | |
@circle_cut_page_file_path = circle_cut_page_file_path | |
end | |
#対象のサークルカットPNGから1サークルのカットを切り取りファイルパスを返却する | |
#すでに切り取っていたらそれを使う | |
def individual_cut(position_id) | |
circle_cut_page_file_name = Pathname(@circle_cut_page_file_path).basename.to_s | |
circle_cut_page_file_name.gsub!("\.PNG", "") | |
page_folder_name = Pathname.new(WORK_FOLDER_NAME).join(circle_cut_page_file_name).to_s | |
FileUtils.mkdir_p(page_folder_name) unless File.exist?(page_folder_name) | |
write_file_path_name = Pathname.new(page_folder_name).join(position_id + ".png").to_s | |
#ファイルをすでにカットしていたら処理せず終了 | |
return write_file_path_name if File.exist?(write_file_path_name) | |
image = Magick::Image.read(@circle_cut_page_file_path).first | |
image.crop(CIRCLE_CUT_MAP[position_id.to_i - 1][0], CIRCLE_CUT_MAP[position_id.to_i - 1][1], CIRCLE_CUT_SIZE_WIDTH, CIRCLE_CUT_SIZE_HEIGHT).write(write_file_path_name) | |
puts "create " + write_file_path_name | |
write_file_path_name | |
end | |
end | |
end |
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
image = Magick::Image.read(@circle_cut_page_file_path).first | |
image.crop(CIRCLE_CUT_MAP[position_id.to_i - 1][0], CIRCLE_CUT_MAP[position_id.to_i - 1][1], CIRCLE_CUT_SIZE_WIDTH, CIRCLE_CUT_SIZE_HEIGHT).write(write_file_path_name) |
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 'circle_cut.rb' | |
include ComikeCatalogParser | |
CircleCut.new("/Users/cocoa/PDATA/1093.PNG").individual_cut("32")' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment