image2pdf 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9c90d471dd663e3692cec983bcabe33fb09f26f4
4
+ data.tar.gz: 128a17e4f2a11ffa0572bfe72c91df72bd051858
5
+ SHA512:
6
+ metadata.gz: f2190d3efdffe12254f5176e5402dd1a18679059e1f98b7d11d0bb213b59676e3ad6b9a4c31a3fc511923d8c46be54849567f4488693e202a330428ed4ca9a30
7
+ data.tar.gz: 9a95d150be29920220372dee40466ed2d24ff25d84a4840ecb8f3c84d25c284d755b6c6a8128272b3d3f4a2d19419ad601139c85a7ed5be1fd7f261ea2b5093c
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 physacco
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,18 @@
1
+ image2pdf
2
+ =========
3
+
4
+ This is a pure Ruby command line program that converts a set of images
5
+ into a PDF document.
6
+
7
+ It supports JPEG and PNG file formats.
8
+
9
+ ## Installation
10
+
11
+ ```
12
+ gem install image2pdf
13
+ ```
14
+
15
+ ## Examples
16
+
17
+ - `image2pdf -o foo.pdf foo.jpg`
18
+ - `image2pdf -o bar.pdf bar/*.jpg`
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require 'getoptlong'
5
+ require 'image2pdf'
6
+
7
+ Usage = <<EOF
8
+ Usage: image2pdf [options] file1 [file2 ...]
9
+
10
+ Options:
11
+ -h, --help Print this help message and exit
12
+ -v, --version Print version information and exit
13
+ -o, --output xxx Specify the output file name
14
+ EOF
15
+
16
+ VersionInfo = "image2pdf v#{ImageToPDF::VERSION}"
17
+
18
+ def parse_arguments
19
+ opts = GetoptLong.new(
20
+ ['--help', '-h', GetoptLong::NO_ARGUMENT],
21
+ ['--version', '-v', GetoptLong::NO_ARGUMENT],
22
+ ['--output', '-o', GetoptLong::REQUIRED_ARGUMENT]
23
+ )
24
+
25
+ output = 'output.pdf'
26
+
27
+ begin
28
+ opts.each do |opt, arg|
29
+ case opt
30
+ when '--help'
31
+ puts Usage
32
+ exit 0
33
+ when '--version'
34
+ puts VersionInfo
35
+ exit 0
36
+ when '--output'
37
+ output = arg
38
+ end
39
+ end
40
+ rescue GetoptLong::MissingArgument
41
+ exit 1
42
+ end
43
+
44
+ if ARGV.size < 1
45
+ STDERR.puts "Error: no input files"
46
+ STDERR.puts Usage
47
+ exit 1
48
+ end
49
+
50
+ ARGV.each do |filename|
51
+ unless File.file?(filename) and File.readable?(filename)
52
+ STDERR.puts "Error: not a readable file: #{filename}"
53
+ exit 1
54
+ end
55
+
56
+ unless ['.png', '.jpg', '.jpeg'].include?(File.extname(filename))
57
+ STDERR.puts "Error: illegal file type: #{filename}"
58
+ exit 1
59
+ end
60
+ end
61
+
62
+ [ARGV, output]
63
+ end
64
+
65
+ images, output = parse_arguments
66
+
67
+ begin
68
+ ImageToPDF.convert(images, output)
69
+ puts "Done. Successfully written to #{output}"
70
+ rescue ImageToPDF::ImageFormatError => e
71
+ STDERR.puts "Error: image format error: #{e}"
72
+ exit 2
73
+ rescue Exception => e
74
+ STDERR.puts "Error: unexpected exception (#{e.class}): #{e}"
75
+ exit 127
76
+ end
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative 'lib/image2pdf/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'image2pdf'
7
+ s.version = ImageToPDF::VERSION
8
+ s.date = '2015-11-27'
9
+
10
+ s.summary = 'Convert a set of images into a PDF document'
11
+ s.description = <<EOF
12
+ This is a pure Ruby command line program that converts a set of images
13
+ into a PDF document. It supports JPEG and PNG file formats.
14
+
15
+ Examples:
16
+ * image2pdf -o foo.pdf foo.jpg
17
+ * image2pdf -o bar.pdf bar/*.jpg
18
+ EOF
19
+
20
+ s.authors = ['physacco']
21
+ s.email = ['physacco@gmail.com']
22
+ s.homepage = 'https://github.com/physacco/image2pdf'
23
+ s.license = 'MIT'
24
+
25
+ s.files = Dir['lib/**/*.rb'] + Dir['bin/*'] +
26
+ ['README.md', 'LICENSE', 'image2pdf.gemspec']
27
+ s.executables = ['image2pdf']
28
+
29
+ s.platform = Gem::Platform::RUBY
30
+ s.required_ruby_version = '>= 2.0.0'
31
+ s.add_runtime_dependency 'prawn', '~> 2.0', '>= 2.0.0'
32
+ s.add_runtime_dependency 'dimensions', '~> 1.3', '>= 1.3.0'
33
+ end
@@ -0,0 +1,47 @@
1
+ # encoding: utf-8
2
+
3
+ require 'prawn'
4
+ require 'dimensions'
5
+ require_relative 'image2pdf/version'
6
+
7
+ module Prawn
8
+ module Images
9
+ def clear_image_registry
10
+ @image_registry.clear
11
+ end
12
+ end
13
+ end
14
+
15
+ module ImageToPDF
16
+
17
+ class ImageFormatError < Exception
18
+ end
19
+
20
+ class Image
21
+ attr_reader :filename, :dimensions
22
+
23
+ def initialize(filename)
24
+ @filename = filename
25
+ @dimensions = Dimensions.dimensions(filename)
26
+
27
+ if @dimensions.nil?
28
+ raise ImageFormatError.new(filename)
29
+ end
30
+ end
31
+ end
32
+
33
+ def self.convert(src_files, output)
34
+ images = src_files.map {|filename| Image.new(filename)}
35
+
36
+ Prawn::Document.generate(output,
37
+ :page_size => images[0].dimensions, :margin => 0) do
38
+ image images[0].filename
39
+
40
+ 1.upto(images.size - 1) do |i|
41
+ start_new_page :size => images[i].dimensions, :margin => 0
42
+ image images[i].filename
43
+ clear_image_registry
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,5 @@
1
+ # encoding: utf-8
2
+
3
+ module ImageToPDF
4
+ VERSION = '0.1.0'
5
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: image2pdf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - physacco
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: prawn
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: dimensions
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.3'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 1.3.0
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.3'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 1.3.0
53
+ description: |
54
+ This is a pure Ruby command line program that converts a set of images
55
+ into a PDF document. It supports JPEG and PNG file formats.
56
+
57
+ Examples:
58
+ * image2pdf -o foo.pdf foo.jpg
59
+ * image2pdf -o bar.pdf bar/*.jpg
60
+ email:
61
+ - physacco@gmail.com
62
+ executables:
63
+ - image2pdf
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - LICENSE
68
+ - README.md
69
+ - bin/image2pdf
70
+ - image2pdf.gemspec
71
+ - lib/image2pdf.rb
72
+ - lib/image2pdf/version.rb
73
+ homepage: https://github.com/physacco/image2pdf
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 2.0.0
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.4.5.1
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Convert a set of images into a PDF document
97
+ test_files: []