image_to_pdf 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0be7725a3c51673f08602d16e15c2966797f0f72
4
+ data.tar.gz: a19caa30adcd71d2153607c5bcbb82fbf43bd79e
5
+ SHA512:
6
+ metadata.gz: 60b1481b50f2714765bf24f58081d1529a417ea9e876a0f2a93b472f9b2b3f501b009c845bd4181dc4096fcde418dba24731f4dd45229e28a44256d36399d458
7
+ data.tar.gz: 3ac95592f34a229261246def485841decaf2d08272a7b58d69468cb4756732d3752f9725f22d1bb7f726663bf8aa47b506d753be6d1f36321c3ad46c2fd9fa24
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Venkat
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # ImageToPdf
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/image_to_pdf`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'image_to_pdf'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install image_to_pdf
22
+
23
+ ## Usage
24
+
25
+ image_to_pdf gem usage is very simple.
26
+
27
+ ## for usage help
28
+ $ image_to_pdf -h [--help]
29
+
30
+ ## to check gem version
31
+ $ image_to_pdf -v [--version]
32
+
33
+ ## to convert image into pdf
34
+ $ image_to_pdf "sample image path"
35
+
36
+ ##Example:
37
+ $ image_to_pdf "/home/kishore/Desktop/app_store.png"
38
+
39
+ if you want try from rails console
40
+
41
+ ## to convert image into pdf
42
+ $ Image2pdf.convert("/home/kishore/Desktop/app_store.png")
43
+
44
+ ## Development
45
+
46
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
47
+
48
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
49
+
50
+ ## Contributing
51
+
52
+ 1. Fork it ( https://github.com/[my-github-username]/image_to_pdf/fork )
53
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
54
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
55
+ 4. Push to the branch (`git push origin my-new-feature`)
56
+ 5. Create a new Pull Request
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "image_to_pdf"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/image_to_pdf ADDED
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require 'getoptlong'
5
+ require 'image_to_pdf'
6
+
7
+ Usage = <<EOF
8
+ Usage: image_to_pdf [options] file1
9
+ Options:
10
+ -h, --help Print this help message and exit
11
+ -v, --version Print version information and exit
12
+ EOF
13
+
14
+ VersionInfo = "image_to_pdf v#{ImageToPdf::VERSION}"
15
+
16
+ def parse_arguments
17
+ opts = GetoptLong.new(
18
+ ['--help', '-h', GetoptLong::NO_ARGUMENT],
19
+ ['--version', '-v', GetoptLong::NO_ARGUMENT]
20
+ )
21
+
22
+ STDERR.puts ARGV.inspect
23
+
24
+ begin
25
+ opts.each do |opt, arg|
26
+ case opt
27
+ when '--help'
28
+ puts Usage
29
+ exit 0
30
+ when '--version'
31
+ puts VersionInfo
32
+ exit 0
33
+ end
34
+ end
35
+ rescue GetoptLong::MissingArgument
36
+ exit 1
37
+ end
38
+
39
+ if ARGV.size < 1
40
+ STDERR.puts "Error: no input files"
41
+ STDERR.puts Usage
42
+ exit 1
43
+ elsif ARGV.size == 1
44
+ filename = ARGV[0]
45
+ unless File.file?(filename) and File.readable?(filename)
46
+ STDERR.puts "Error: not a readable file: #{filename}"
47
+ exit 1
48
+ end
49
+
50
+ unless ['.png', '.jpg', '.jpeg'].include?(File.extname(filename))
51
+ STDERR.puts "Error: illegal file type: #{filename}"
52
+ exit 1
53
+ end
54
+ filename
55
+ end
56
+
57
+ # ARGV.each do |filename|
58
+ # unless File.file?(filename) and File.readable?(filename)
59
+ # STDERR.puts "Error: not a readable file: #{filename}"
60
+ # exit 1
61
+ # end
62
+
63
+ # unless ['.png', '.jpg', '.jpeg'].include?(File.extname(filename))
64
+ # STDERR.puts "Error: illegal file type: #{filename}"
65
+ # exit 1
66
+ # end
67
+ # end
68
+
69
+ end
70
+
71
+ image_path = parse_arguments
72
+
73
+ begin
74
+ ImageToPdf.convert(image_path)
75
+ rescue Exception => e
76
+ STDERR.puts "Error: unexpected exception (#{e.class}): #{e}"
77
+ exit 127
78
+ end
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'image_to_pdf/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "image_to_pdf"
8
+ spec.version = ImageToPdf::VERSION
9
+ spec.authors = ["Venkat"]
10
+ spec.email = ["venkat@param-solutions.com"]
11
+
12
+ spec.summary = %q{Converts image to pdf}
13
+ spec.description = %q{image2pdf accepts jpeg/png/gif/svg path as input and converts into a pdf file}
14
+ spec.homepage = "https://github.com/kishor557/image_to_pdf"
15
+ spec.license = "MIT"
16
+
17
+ # spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ # spec.bindir = "exe"
19
+ # spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+
21
+ spec.files = Dir['lib/**/*.rb'] + Dir['bin/*'] +
22
+ ['README.md', 'LICENSE.txt', 'image_to_pdf.gemspec']
23
+ spec.executables = ['image_to_pdf']
24
+
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.8"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_dependency 'rmagick', '~> 2.10', '>= 2.10.0'
30
+ end
@@ -0,0 +1,3 @@
1
+ module ImageToPdf
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,52 @@
1
+ require "image_to_pdf/version"
2
+ require 'rmagick'
3
+ require 'open-uri'
4
+ require 'uri'
5
+
6
+ ## Converts image to pdf
7
+ module ImageToPdf
8
+
9
+ # working in progress: accepts image urls and converts into pdf
10
+ def self.is_url?(str)
11
+ begin
12
+ res = open(str).status
13
+ true if res[0] == "200"
14
+ rescue => e
15
+ false
16
+ end
17
+ end
18
+
19
+ def self.to_pdf(path, filename, filep=".")
20
+ img = Magick::ImageList.new(path)
21
+
22
+ img = Magick::ImageList.new(path)
23
+ if %w(GIF PNG JPEG SVG).include? img.format
24
+ img.write(filep + "/" + filename + ".pdf")
25
+ STDOUT.puts "\033[107;31m Your file saved in #{path}\033[0m"
26
+ else
27
+ # raise StandardError, "Please enter valid PDF file path!"
28
+ STDOUT.puts "Error: Please enter valid PDF file path!"
29
+ end
30
+ end
31
+
32
+ def self.convert(path)
33
+ if is_url?(path)
34
+ filename = path.split("/").last
35
+ filename = "sample" if filename.empty?
36
+ downloaded_file = URI.parse("#{path}").open
37
+
38
+ File.open(filename, 'wb') { |f| f.write(downloaded_file.read) }
39
+ f = File.open(filename, "r")
40
+ name = File.basename(f,File.extname(f))
41
+ to_pdf(f.path, name)
42
+ File.delete(f)
43
+ else
44
+ extn = File.extname path
45
+ filep = File.dirname(path)
46
+ filename = File.basename path, extn
47
+ to_pdf(path, filename, filep)
48
+ end
49
+
50
+ end
51
+
52
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: image_to_pdf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Venkat
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-03-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rmagick
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.10'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 2.10.0
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '2.10'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 2.10.0
61
+ description: image2pdf accepts jpeg/png/gif/svg path as input and converts into a
62
+ pdf file
63
+ email:
64
+ - venkat@param-solutions.com
65
+ executables:
66
+ - image_to_pdf
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - LICENSE.txt
71
+ - README.md
72
+ - bin/console
73
+ - bin/image_to_pdf
74
+ - bin/setup
75
+ - image_to_pdf.gemspec
76
+ - lib/image_to_pdf.rb
77
+ - lib/image_to_pdf/version.rb
78
+ homepage: https://github.com/kishor557/image_to_pdf
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.4.6
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Converts image to pdf
102
+ test_files: []
103
+ has_rdoc: