thumbnailer-taq 0.1.0

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: 522d835d684044d2cb8c439d3870269bdda38078
4
+ data.tar.gz: 6fcf7c53975d53875d0584b92a62f63542d1ad9f
5
+ SHA512:
6
+ metadata.gz: a66942f8f01ec0ee5244b6ed57aa1f5f68e066bb58a8ff9bc86eabdb13bb7efec31046bc2bb78c85c6e07160d25369f0770ef0fda0d2b44c71fbb3ee5601b182
7
+ data.tar.gz: 837e8bae83211da52e913f6e0c3d6332c6b29ecd7ba64750873ad222fc0be99f9be2f33110a8eabc1fe921980011ca38376ff380caa3d28c492a1d55653e26f8
Binary file
Binary file
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.14.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in thumbnailer.gemspec
4
+ gemspec
@@ -0,0 +1,83 @@
1
+ # Thumbnailer
2
+
3
+ A simple way to create thumbnails.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'thumbnailer'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install thumbnailer
20
+
21
+ ## Usage
22
+
23
+ ### Creating from a file
24
+
25
+ ```ruby
26
+ thumb = Thumbnailer::File.new('ruby-logo.png')
27
+ thumb.create # creates thumb_ruby-logo.png with 1/10 of the original size
28
+ ```
29
+
30
+ ### Creating from a file mask
31
+
32
+ ```ruby
33
+ thumb = Thumbnailer::Files.new('*.png')
34
+ thumb.create # creates thumb_<file>.png files
35
+ ```
36
+
37
+ ## Creating from a PDF file
38
+
39
+ ```ruby
40
+ thumb = Thumbnailer::PDF.new('test.pdf')
41
+ thumb.create # creates thumb_<file>_<page>.png files for all pages
42
+ ```
43
+
44
+ #### Options
45
+
46
+ We can send some options to customize the output
47
+
48
+ ```ruby
49
+ thumb = Thumbnailer::File.new('ruby-logo.png', prefix: 'custom_thumb_')
50
+ thumb.create # creates custom_thumb_ruby-logo.png with 1/10 of the original size
51
+
52
+ thumb = Thumbnailer::File.new('ruby-logo.png', ratio: 5)
53
+ thumb.create # creates thumb_ruby-logo.png with 1/5 of the original size
54
+
55
+ thumb = Thumbnailer::File.new('ruby-logo.png', dir: '/tmp')
56
+ thumb.create # creates thumb_ruby-logo.png on /tmp
57
+
58
+ thumb = Thumbnailer::File.new('ruby-logo.png', width: 35, height: 35)
59
+ thumb.create # creates thumb_ruby-logo.png with 35 x 35 size
60
+
61
+ thumb = Thumbnailer::PDF.new('test.pdf', page: 2)
62
+ thumb.create # creates thumb_<file>_2.png files for page 2
63
+
64
+ thumb = Thumbnailer::PDF.new('test.pdf', pages: [1, 3])
65
+ thumb.create # creates thumb_<file>_<page>.png files for pages 1 and 3
66
+ ```
67
+
68
+ ## Development
69
+
70
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
71
+ `rake test` to run the tests. You can also run `bin/console` for an interactive
72
+ prompt that will allow you to experiment.
73
+
74
+ To install this gem onto your local machine, run `bundle exec rake install`. To
75
+ release a new version, update the version number in `version.rb`, and then run
76
+ `bundle exec rake release`, which will create a git tag for the version, push
77
+ git commits and tags, and push the `.gem` file to
78
+ [rubygems.org](https://rubygems.org).
79
+
80
+ ## Contributing
81
+
82
+ Bug reports and pull requests are welcome on GitHub at
83
+ https://github.com/taq/thumbnailer.
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "thumbnailer"
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(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,21 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDhTCCAm2gAwIBAgIBATANBgkqhkiG9w0BAQUFADBEMQwwCgYDVQQDDAN0YXEx
3
+ HzAdBgoJkiaJk/IsZAEZFg9ldXN0YXF1aW9yYW5nZWwxEzARBgoJkiaJk/IsZAEZ
4
+ FgNjb20wHhcNMTcwNDE4MTUxMDAwWhcNMTgwNDE4MTUxMDAwWjBEMQwwCgYDVQQD
5
+ DAN0YXExHzAdBgoJkiaJk/IsZAEZFg9ldXN0YXF1aW9yYW5nZWwxEzARBgoJkiaJ
6
+ k/IsZAEZFgNjb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCgbmiP
7
+ QaEUU+D2pt+bMbtLSsf/SSR2dUXhkSdmlnu/MmwnnCqxiVR6A5VjO92Y/KZj4eQo
8
+ Jvtdu4z5RbFWM+2sinTExAXOlTSN+zBwxttEvZ14G5TkGW+kWGzB38/G/hM29vdQ
9
+ A8qW4rb8sS3cD1ZWoauSE6osElX8AZo4YvqJv17I2erVNXyXUKExn9Ygz0S9PyeT
10
+ 317HkbY3KbBzxgS6jkc5DyjY4dKIyUkY/Qmccak9iGz+zt1IwOAymZQHWkuJ3vPq
11
+ 3Z+2qb/hndJUuedxMLjVn1dqNpwSyiTWzP016JjmoslKE7WiwUiHtLWxSWw+M/Am
12
+ PwZ6OBzMnTHYm5jzAgMBAAGjgYEwfzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAd
13
+ BgNVHQ4EFgQUmcicuSbO/JUYUG4wfIL3wLooHmIwIgYDVR0RBBswGYEXdGFxQGV1
14
+ c3RhcXVpb3JhbmdlbC5jb20wIgYDVR0SBBswGYEXdGFxQGV1c3RhcXVpb3Jhbmdl
15
+ bC5jb20wDQYJKoZIhvcNAQEFBQADggEBADwqsNlTmpU80KJTz4jHbFb/YhaHDSix
16
+ qfOrxslFGoPVJCz+awdM4MmEIyjJ6P/3HN/WsZck1WPj0U5VOFMeMXR32XVEvmbZ
17
+ TmuPI5dHxwGkPW5xT9hXhiCPCkASNEDSwmjYuuy44xj7zGx2Bj5796XSl1AiaVLW
18
+ XlV0J9wQjOFla0d9vUwdKTYFpbH6d/Fab6HbSIf6jgem3m7PjBJArNXxUccrmuK4
19
+ ZicxpsZW3yGgBEPYQAbwh/1N/5PyCNgvq/1BswuEULyBIwpEIF/cK8JbY3r8wBHk
20
+ t/dEawxBL2P4+zSwyt/tcWgpqJlAHJce2CWOIk/+Ze2MUHmWeaAxHvU=
21
+ -----END CERTIFICATE-----
@@ -0,0 +1,6 @@
1
+ require 'mini_magick'
2
+
3
+ require_relative 'thumbnailer/base'
4
+ require_relative 'thumbnailer/file'
5
+ require_relative 'thumbnailer/files'
6
+ require_relative 'thumbnailer/pdf'
@@ -0,0 +1,74 @@
1
+ require "thumbnailer/version"
2
+
3
+ module Thumbnailer
4
+ class Base
5
+ protected
6
+ attr_accessor :object
7
+
8
+ public
9
+ attr_reader :width, :height, :image_width, :image_height, :prefix, :dir, :sequence
10
+
11
+ def initialize(options = {})
12
+ @options = options
13
+ @object = options[:object]
14
+ @ratio = options[:ratio] || 2
15
+ @width = options[:width]
16
+ @height = options[:height]
17
+ @image_width = nil
18
+ @image_height = nil
19
+ @prefix = options[:prefix] || 'thumb_'
20
+ @dir = options[:dir]
21
+ @sequence = nil
22
+
23
+ extract_image_size
24
+ end
25
+
26
+ def output
27
+ path = "#{@dir}/#{@prefix}#{@file}"
28
+ path = path.gsub(/\.(\w+)$/, ".#{@options[:format]}") if @options[:format].to_s.size > 0
29
+ path = insert_page(path)
30
+ path
31
+ end
32
+
33
+ def create
34
+ write
35
+ end
36
+
37
+ def write
38
+ resize
39
+ @object.write(output)
40
+ end
41
+
42
+ private
43
+
44
+ def insert_page(path)
45
+ return path if @options[:sequence].to_i <= 0
46
+ matcher = path.match(/(?<prefix>.*)(\.)(?<ext>\w+)$/)
47
+ "#{matcher[:prefix]}_#{@options[:sequence]}.#{matcher[:ext]}"
48
+ end
49
+
50
+ def resize
51
+ return if @object.nil?
52
+ @width, @heigth = avail_thumb_size
53
+ @object.resize("#{@width}x#{@height}")
54
+ end
55
+
56
+ def extract_image_size
57
+ return if !@object
58
+ @image_width, @image_height = @object[:width], @object[:height]
59
+ avail_thumb_size
60
+ end
61
+
62
+ def avail_thumb_size
63
+ width, height = create_prop_size
64
+ @width = width if @width.nil?
65
+ @height = height if @height.nil?
66
+ end
67
+
68
+ def create_prop_size
69
+ width = (@image_width / @ratio).to_i if @image_width
70
+ height = (@image_height / @ratio).to_i if @image_height
71
+ [ width, height ]
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,25 @@
1
+ module Thumbnailer
2
+ class File < Base
3
+ attr_reader :path
4
+
5
+ def initialize(path, options = {})
6
+ super(options)
7
+ @path = path
8
+ @file = @options[:file]
9
+ @file = ::File.basename(@path) if @file.nil? && !@path.nil?
10
+ @dir = @options[:dir]
11
+ @dir = ::File.dirname(@path) if @dir.nil? && !@path.nil?
12
+ @prefix = @options[:prefix] if @options[:prefix]
13
+ @object = extract_image(@path) if !@options[:object]
14
+ end
15
+
16
+ private
17
+
18
+ def extract_image(file)
19
+ raise Errno::ENOENT unless ::File.exist?(file)
20
+ @object = ::MiniMagick::Image.open(file)
21
+ extract_image_size
22
+ @object
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,18 @@
1
+ module Thumbnailer
2
+ class Files < Base
3
+ attr_reader :collection, :size
4
+
5
+ def initialize(path, options = {})
6
+ super(options)
7
+ @collection = Dir.glob(path)
8
+ @size = @collection.size
9
+ end
10
+
11
+ def create
12
+ @collection.each do |path|
13
+ file = File.new(path, @options)
14
+ file.create
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,54 @@
1
+ module Thumbnailer
2
+ class PDF < Base
3
+ attr_reader :collection, :size, :format
4
+
5
+ def initialize(path, options = {})
6
+ super(options)
7
+ @path = path
8
+ @collection = extract_collection
9
+ @size = @collection.size
10
+ @format = options[:format] || 'png'
11
+ end
12
+
13
+ def create
14
+ extract_page
15
+ extract_pages
16
+ sequences = extract_sequences
17
+
18
+ @collection.each do |image|
19
+ sequence = sequences.next
20
+ image.format(@format, 1)
21
+
22
+ @options[:object] = image
23
+ @options[:format] = @format
24
+ @options[:sequence] = sequence
25
+
26
+ file = File.new(@path, @options)
27
+ file.create
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def extract_sequences
34
+ return (1..@collection.size).to_a.each if !@options[:page] && !@options[:pages]
35
+ return [ @options[:page] ].each if @options[:page]
36
+ return @options[:pages].each if @options[:pages]
37
+ end
38
+
39
+ def extract_page
40
+ return if !@options[:page]
41
+ @collection = [ @collection[@options[:page] - 1] ]
42
+ end
43
+
44
+ def extract_pages
45
+ return if !@options[:pages]
46
+ @collection = @options[:pages].map { |page| @collection[page - 1] }
47
+ end
48
+
49
+ def extract_collection
50
+ ::MiniMagick::Image.open(@path).pages
51
+ end
52
+ end
53
+ end
54
+
@@ -0,0 +1,3 @@
1
+ module Thumbnailer
2
+ VERSION = "0.1.0"
3
+ end
@@ -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 'thumbnailer/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "thumbnailer-taq"
8
+ spec.version = Thumbnailer::VERSION
9
+ spec.authors = ["Eustáquio Rangel"]
10
+ spec.email = ["taq@eustaquiorangel.com"]
11
+
12
+ spec.summary = %q{A simple way to create thumbnails.}
13
+ spec.homepage = "http://github.com/taq/thumbnailer"
14
+ spec.licenses = [ 'GPL-2.0' ]
15
+
16
+ spec.signing_key = '/home/taq/.gemcert/gem-private_key.pem'
17
+ spec.cert_chain = ['gem-public_cert.pem']
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
+ f.match(%r{^(test|spec|features)/})
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.14"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "minitest", "~> 5.0"
29
+ spec.add_development_dependency "mini_magick", "~> 4.7"
30
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thumbnailer-taq
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Eustáquio Rangel
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDhTCCAm2gAwIBAgIBATANBgkqhkiG9w0BAQUFADBEMQwwCgYDVQQDDAN0YXEx
14
+ HzAdBgoJkiaJk/IsZAEZFg9ldXN0YXF1aW9yYW5nZWwxEzARBgoJkiaJk/IsZAEZ
15
+ FgNjb20wHhcNMTcwNDE4MTUxMDAwWhcNMTgwNDE4MTUxMDAwWjBEMQwwCgYDVQQD
16
+ DAN0YXExHzAdBgoJkiaJk/IsZAEZFg9ldXN0YXF1aW9yYW5nZWwx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
+ date: 2017-04-18 00:00:00.000000000 Z
34
+ dependencies:
35
+ - !ruby/object:Gem::Dependency
36
+ name: bundler
37
+ requirement: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.14'
42
+ type: :development
43
+ prerelease: false
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '1.14'
49
+ - !ruby/object:Gem::Dependency
50
+ name: rake
51
+ requirement: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '10.0'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '10.0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: minitest
65
+ requirement: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '5.0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '5.0'
77
+ - !ruby/object:Gem::Dependency
78
+ name: mini_magick
79
+ requirement: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '4.7'
84
+ type: :development
85
+ prerelease: false
86
+ version_requirements: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '4.7'
91
+ description:
92
+ email:
93
+ - taq@eustaquiorangel.com
94
+ executables: []
95
+ extensions: []
96
+ extra_rdoc_files: []
97
+ files:
98
+ - ".gitignore"
99
+ - ".travis.yml"
100
+ - Gemfile
101
+ - README.md
102
+ - Rakefile
103
+ - bin/console
104
+ - bin/setup
105
+ - gem-public_cert.pem
106
+ - lib/thumbnailer.rb
107
+ - lib/thumbnailer/base.rb
108
+ - lib/thumbnailer/file.rb
109
+ - lib/thumbnailer/files.rb
110
+ - lib/thumbnailer/pdf.rb
111
+ - lib/thumbnailer/version.rb
112
+ - thumbnailer.gemspec
113
+ homepage: http://github.com/taq/thumbnailer
114
+ licenses:
115
+ - GPL-2.0
116
+ metadata: {}
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubyforge_project:
133
+ rubygems_version: 2.6.11
134
+ signing_key:
135
+ specification_version: 4
136
+ summary: A simple way to create thumbnails.
137
+ test_files: []
@@ -0,0 +1,3 @@
1
+ :���W�:L;@��32I)iN�Wc'?�&d�x����#b�"�M��FZE��E_�<��WK$��� �0C��8%޸�����m�PS�nO���6�V�~�d��D�s�@�}�
2
+ q�l��T� ti��:�����k���3V��E���UQ:
3
+ 4.�_����