metakgp-images2pdfs 1.0.3

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6f1586d59975cc04fd9b48958057f03ce0f3756d
4
+ data.tar.gz: eebbb642525ac78ba2cdb0a4383a1f7544cd0145
5
+ SHA512:
6
+ metadata.gz: adbd761e95c305c7d42b8eedcee8ebe2b9059ffbfd1ebfbe6b60746a207f412a0dcd22a03baf648cca154365598c668def1911fab9e51f925567a72291fbff10
7
+ data.tar.gz: 42fd35b3a3c5a993071a0e14241fa38318fb0c2b809a941c2a69e713324be14369d329e2fdb7be6c748797fd697aa68aedb9ae2fbdadb25e09bb4188ec9c310e
@@ -0,0 +1,52 @@
1
+ require 'rmagick'
2
+
3
+ # Get images directory as argument from terminal
4
+ def convert images_directory , pdfs_directory
5
+
6
+ # Get all files from that directory
7
+ all_images = Dir.entries(images_directory)
8
+
9
+ #Segregate only the required the question paper images , just in case the directory contains other files
10
+ all_images.keep_if { |a| ((a.start_with? "mid-") || (a.start_with? "end-")) && ((a.end_with? ".jpg") || (a.end_with? ".png") || (a.end_with? ".tif") || (a.end_with? ".gif") || (a.end_with? ".svg") || (a.end_with? ".bmp"))}
11
+
12
+ #Store number of images as a variable to show % finished
13
+ number_of_images = all_images.count
14
+
15
+ # Initialisation of variables like Array of names of papers , eg. mid-spring-2016-MA20104
16
+ Dir.chdir(images_directory)
17
+ papernames_array = []
18
+ i = 0
19
+ all_images = all_images.sort
20
+ stack = Magick::ImageList.new
21
+
22
+ #Loop through all paper images & batch merge them into PDFs , even if a paper has 3 pages / images
23
+ all_images.each do |file|
24
+ papernames_array[i] = file[0..22]
25
+ if i == 0
26
+ Dir.chdir(images_directory)
27
+ stack = Magick::ImageList.new
28
+ incoming = Magick::ImageList.new file
29
+ stack.concat(incoming)
30
+ else
31
+ if papernames_array[i].eql? papernames_array[i-1]
32
+ Dir.chdir(images_directory)
33
+ incoming = Magick::ImageList.new file
34
+ stack.concat(incoming)
35
+ else
36
+ Dir.chdir(pdfs_directory)
37
+ stack.write(papernames_array[i-1]+".pdf")
38
+ Dir.chdir(images_directory)
39
+ stack = Magick::ImageList.new
40
+ incoming = Magick::ImageList.new file
41
+ stack.concat(incoming)
42
+ end
43
+ if i == number_of_images-1
44
+ Dir.chdir(pdfs_directory)
45
+ stack.write(papernames_array[i]+".pdf")
46
+ end
47
+ end
48
+ i = i + 1
49
+ percentage = (i.to_f/number_of_images.to_f) * 100
50
+ puts "Processing #{i}/#{number_of_images} images , #{percentage}% done"
51
+ end
52
+ end
@@ -0,0 +1,17 @@
1
+ require_relative 'convert'
2
+ class Images2pdfs
3
+
4
+ def initialize images_directory="" , pdfs_directory=""
5
+ if ((Dir.exists? images_directory) && (Dir.exists? pdfs_directory))
6
+ convert(images_directory,pdfs_directory)
7
+ else
8
+ if !(Dir.exists? images_directory)
9
+ puts "Images directory doesn't seem to exist - Check again!"
10
+ end
11
+ if !(Dir.exists? pdfs_directory)
12
+ puts "PDFs directory doesn't seem to exist - Check again!"
13
+ end
14
+ end
15
+ end
16
+
17
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: metakgp-images2pdfs
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Athitya Kumar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-01 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Special Gem for MetaKGP members - to convert all images in a directory
14
+ to PDFs in another directory. Supports multi-page Question paper images too. Please
15
+ follow the naming scheme for papers - for example, end-autumn-2016-MA20104-kdfh87.jpg
16
+ in case of single-page Question paper & mid-spring-2016-MA20104-1.jpg , mid-spring-2016-MA20104-2.jpg
17
+ in case of multi-page Question papers. Currently supports .bmp , .jpg, .png, .tif,
18
+ .gif, .svg image formats. TO USE , simply add require 'metakgp-images2pdfs' and
19
+ 'Images2pdfs.new(images_directory,pdf_directory)'.
20
+ email: athityakumar@gmail.com
21
+ executables: []
22
+ extensions: []
23
+ extra_rdoc_files: []
24
+ files:
25
+ - lib/convert.rb
26
+ - lib/metakgp-images2pdfs.rb
27
+ homepage: http://rubygems.org/gems/metakgp-images2pdfs
28
+ licenses:
29
+ - MIT
30
+ metadata: {}
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubyforge_project:
47
+ rubygems_version: 2.6.4
48
+ signing_key:
49
+ specification_version: 4
50
+ summary: Converts Question Paper images to PDFs
51
+ test_files: []