(Application) PSファイルをEPSファイルに変換
作成者: 西本 絵梨子
概要
- PostScriptファイルから適宜余白を取り除いてEPSファイルに変換します.
- DCL-X.X パッケージに含まれるコマンド(dclpsrot, dclpsrmcm, dclpsmargin)を組み合わせています.
使い方
% ./pstoeps.rb test.ps ==> test.eps が吐き出されます
私は % chmod a+x pstoeps.rb をしてパスの通っているところに置いています.
DESCRIPTION
% pstoeps.rb --help
Usage: pstoeps.rb --o, --output [string] specify a output png file --odir, --outdir [string] specify a output directory --norotate without rotating ( defalut rotate ) --m, --margin [value] ration of border to real figure size ( defalut 0.05 ) --h, --help show this message
ソースコード
#! /usr/bin/ruby
#
require 'getoptlong.rb'
parser = GetoptLong.new
parser.set_options(
['--output','--o', GetoptLong::REQUIRED_ARGUMENT],
['--outdir','--odir', GetoptLong::REQUIRED_ARGUMENT],
['--norotate', GetoptLong::NO_ARGUMENT],
['--margin', '--m', GetoptLong::REQUIRED_ARGUMENT],
['--help', '-h', GetoptLong::NO_ARGUMENT]
)
#-- initial values
outfname = false
outdir = false
norotate = false
margin = 0.05
help = false
#-- get input values
parser.each_option do |name,arg|
name.sub!(/^--/,'')
case name
when 'output' , 'o'
outfname = arg.to_s
when 'outdir' , 'odir'
outdir = arg.to_s
when 'norotate'
norotate = true
when 'margin' , 'm'
margin = arg.to_f
when 'help' , 'h'
help = true
end
end
#-- help message
if (help)
usage = "Usage: #{$0.split('/')[-1]}
--o, --output [string] specify a output png file
--odir, --outdir [string] specify a output directory
--norotate without rotating ( defalut rotate )
--m, --margin [value] ration of border to real figure size ( defalut #{margin} )
--h, --help show this message"
puts usage
exit
end
#-- make ps file to eps
home = Dir.getwd
ARGV.each{|input|
ok = File.exist?(input)
if (not ok)
puts "Not exist #{input} !!\n\n"
else
dirname = File.dirname(input)
psfname = File.basename(input)
outfname = File.basename(input,'.ps')
puts "#{outfname}"
Dir.chdir(dirname)
puts "PS -> EPS ..."
if (norotate)
system("dclpsrmcm #{psfname} | dclpsmargin -m #{margin} > #{outfname}.eps")
else
system("dclpsrot #{psfname} | dclpsrmcm | dclpsmargin -m #{margin} > #{outfname}.eps")
end
Dir.chdir(home)
if (outdir)
puts "move to #{outdir}\n"
system("mv #{dirname}/#{outfname}.eps #{outdir}")
end
end
}
謝辞
このスクリプトは, 神代さんに教えていただいたものを改変したものです.
キーワード:[Postscript] [EPS]
参照: