1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
#!/usr/bin/env ruby
# program : newimgtopdf
# copyright : PRAGMA Advanced Document Engineering
# version : 2002-2006
# author : Hans Hagen
#
# project : ConTeXt / eXaMpLe
# concept : Hans Hagen
# info : j.hagen@xs4all.nl
# www : www.pragma-ade.com
unless defined? ownpath
ownpath = $0.sub(/[\\\/]\w*?\.rb/i,'')
$: << ownpath
end
require 'base/switch'
require 'base/logger'
require 'graphics/magick'
banner = ['ImgToPdf', 'version 1.1.2', '2002-2006', 'PRAGMA ADE/POD']
class Commands
include CommandBase
# nowadays we would force a directive, but
# for old times sake we handle default usage
def main
filename = @commandline.argument('first')
if filename.empty? then
help
else
convert
end
end
# actions
def convert
magick = Magick.new(session)
['compression','depth','colorspace','quality','inputpath','outputpath'].each do |v|
magick.setvariable(v,@commandline.option(v))
end
@commandline.arguments.each do |fullname|
magick.setvariable('inputfile',fullname)
magick.setvariable('outputfile',fullname.gsub(/(\..*?$)/io, '.pdf'))
if @commandline.option('auto') then
magick.autoconvert
else
magick.convert
end
end
end
end
logger = Logger.new(banner.shift)
commandline = CommandLine.new
commandline.registerflag('auto')
commandline.registervalue('compression')
commandline.registervalue('depth')
commandline.registervalue('colorspace')
commandline.registervalue('quality')
commandline.registervalue('inputpath')
commandline.registervalue('outputpath')
commandline.registeraction('help')
commandline.registeraction('version')
commandline.registeraction('convert', 'convert image into pdf')
commandline.expand
Commands.new(commandline,logger,banner).send(commandline.action || 'main')
|