dragonfly_libvips 2.0.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 835350b6d18b031b00f0071279b84694ef940e58
4
- data.tar.gz: b306a0a01d08232767091e703772360526030795
3
+ metadata.gz: 06644e1c4dec0b4e785390a7414522c662018bcc
4
+ data.tar.gz: aaf43c2978f8a87992d0ccc13bf689a1f3b3a02f
5
5
  SHA512:
6
- metadata.gz: 4c54e214ddf782d3dbc3d09877de7f679c94c54df30ea510eb4b07bec5d02fcffa5481f34b987f79359f80a74c2de92b4abc09dc6c704fe71a3a2c38a54ddcde
7
- data.tar.gz: a0955d32cfd0e2d0eee0e1ec66e1dafab85bed3f963d06b2572f6ee5a8f13d9347bf26d09badff09ec6d5918a34545a4caa2556b7e9f1c5881178c2e08bfe248
6
+ metadata.gz: 670f2d8d7b42eaa5246496000cfafa31fb44e761fe1e643d883dbbaef5a723fc35ad522a864657e17a80ef1978601fae96570af0cb693543cd1a0d962de3bdbc
7
+ data.tar.gz: c84c9cf19b33c3b4b4c2cfa07670f51587b51e6e28cdd700792d48b6df704f0cad51473ec0bea240d356c6f4d7b4c51b197c34be21e42349c275db4ca7043403
data/.travis.yml CHANGED
@@ -11,8 +11,8 @@ before_install:
11
11
  - gem install bundler -v 1.12.5
12
12
  - sudo apt-get update
13
13
  - sudo apt-get install -y gobject-introspection libgirepository1.0-dev libglib2.0-dev libpoppler-glib-dev
14
- - curl -O http://www.vips.ecs.soton.ac.uk/supported/8.4/vips-8.4.5.tar.gz
15
- - tar zvxf vips-8.4.5.tar.gz && cd vips-8.4.5 && ./configure && sudo make && sudo make install
14
+ - curl -OL https://github.com/jcupitt/libvips/releases/download/v8.5.8/vips-8.5.8.tar.gz
15
+ - tar zvxf vips-8.5.8.tar.gz && cd vips-8.5.8 && ./configure && sudo make && sudo make install
16
16
  - export GI_TYPELIB_PATH=/usr/local/lib/girepository-1.0/
17
17
  - sudo ldconfig
18
18
 
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 2.1.0
4
+
5
+ * `thumb` process refactored for `Vips::Image.thumbnail`, with faster performance
6
+
3
7
  ## 2.0.1
4
8
 
5
9
  * `ruby-vips` updated to `>= 2.0.1`
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_dependency 'dragonfly', '~> 1.0'
22
- spec.add_dependency 'ruby-vips', '~> 2.0', '>= 2.0.1'
22
+ spec.add_dependency 'ruby-vips', '~> 2.0', '>= 2.0.6'
23
23
  spec.add_dependency 'activesupport', '>= 4.0'
24
24
 
25
25
  spec.add_development_dependency 'bundler', '~> 1.12'
@@ -1,12 +1,15 @@
1
+ require 'vips'
2
+
1
3
  module DragonflyLibvips
2
4
  module Analysers
3
5
  class ImageProperties
4
- def call(content)
5
- require 'vips'
6
+ DPI = 300
6
7
 
8
+ def call(content)
7
9
  input_options = {}
8
10
  input_options[:access] = :sequential
9
11
  input_options[:autorotate] = true if content.mime_type == 'image/jpeg'
12
+ input_options[:dpi] = DPI if content.mime_type == 'application/pdf'
10
13
 
11
14
  img = ::Vips::Image.new_from_file(content.path, input_options)
12
15
 
@@ -7,42 +7,56 @@ module DragonflyLibvips
7
7
  class Thumb
8
8
  OPERATORS = '><'.freeze
9
9
  RESIZE_GEOMETRY = /\A\d*x\d*[#{OPERATORS}]?\z/ # e.g. '300x200>'
10
- RESIZE_KEYS = %w(kernel).freeze
10
+ DPI = 300
11
11
 
12
12
  def call(content, geometry, options = {})
13
- options = options.deep_stringify_keys
13
+ options = options.deep_symbolize_keys
14
14
 
15
- format = options.fetch('format', content.ext)
15
+ filename = content.path
16
+ format = options.fetch(:format, content.ext)
16
17
 
17
- input_options = options.fetch('input_options', {})
18
- resize_options = options.fetch('resize_options', {})
19
- output_options = options.fetch('output_options', {})
18
+ input_options = options.fetch(:input_options, {})
19
+ input_options[:access] = input_options.fetch(:access, 'sequential')
20
+ input_options[:autorotate] = input_options.fetch(:autorotate, true) if content.mime_type == 'image/jpeg'
20
21
 
21
- input_options['access'] ||= 'sequential'
22
- if content.mime_type == 'image/jpeg'
23
- input_options['autorotate'] = true unless input_options.has_key?('autorotate')
22
+ if content.mime_type == 'application/pdf'
23
+ input_options[:dpi] = input_options.fetch(:dpi, DPI) if content.mime_type == 'application/pdf'
24
+ input_options[:page] = input_options.fetch(:page, 0) if content.mime_type == 'application/pdf'
25
+ else
26
+ input_options.delete(:page)
27
+ input_options.delete(:dpi)
24
28
  end
25
- output_options['profile'] ||= DragonflyLibvips::EPROFILE_PATH
26
29
 
27
- img = ::Vips::Image.new_from_file(content.path, input_options)
30
+ output_options = options.fetch(:output_options, {})
31
+ output_options[:profile] = input_options.fetch(:profile, DragonflyLibvips::EPROFILE_PATH)
32
+
33
+ img = ::Vips::Image.new_from_file(filename, input_options)
28
34
 
29
35
  dimensions = case geometry
30
- when RESIZE_GEOMETRY then DragonflyLibvips::Dimensions.call(geometry, img.width, img.height)
31
- else raise ArgumentError, "Didn't recognise the geometry string #{geometry}"
36
+ when RESIZE_GEOMETRY then DragonflyLibvips::Dimensions.call(geometry, img.width, img.height)
37
+ else raise ArgumentError, "Didn't recognise the geometry string: #{geometry}"
32
38
  end
33
39
 
34
- if dimensions.scale != 1
35
- img = img.resize(dimensions.scale, resize_options)
40
+ thumbnail_options = options.fetch(:thumbnail_options, {})
41
+ thumbnail_options[:auto_rotate] = input_options.fetch(:autorotate, true) if content.mime_type == 'image/jpeg'
42
+ thumbnail_options[:height] = thumbnail_options.fetch(:height, dimensions.height.ceil)
43
+ thumbnail_options[:size] ||= case geometry
44
+ when />\z/ then :down # do_not_resize_if_image_smaller_than_requested
45
+ when /<\z/ then :up # do_not_resize_if_image_larger_than_requested
46
+ else :both
36
47
  end
37
48
 
38
- content.update(img.write_to_buffer(".#{format}", output_options), 'format' => format)
49
+ filename += "[page=#{input_options[:page]}]" if content.mime_type == 'application/pdf'
50
+ thumb = ::Vips::Image.thumbnail(filename, dimensions.width.ceil, thumbnail_options)
51
+
52
+ content.update(thumb.write_to_buffer(".#{format}", output_options), 'format' => format)
39
53
  content.ext = format
40
54
  end
41
55
 
42
56
  def update_url(url_attributes, _, options = {})
43
- options = options.deep_stringify_keys
57
+ options = options.deep_symbolize_keys
44
58
 
45
- if format = options.fetch('format', nil)
59
+ if format = options.fetch(:format, nil)
46
60
  url_attributes.ext = format
47
61
  end
48
62
  end
@@ -1,3 +1,3 @@
1
1
  module DragonflyLibvips
2
- VERSION = '2.0.1'.freeze
2
+ VERSION = '2.1.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dragonfly_libvips
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Celizna
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-23 00:00:00.000000000 Z
11
+ date: 2017-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dragonfly
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: '2.0'
34
34
  - - ">="
35
35
  - !ruby/object:Gem::Version
36
- version: 2.0.1
36
+ version: 2.0.6
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '2.0'
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: 2.0.1
46
+ version: 2.0.6
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: activesupport
49
49
  requirement: !ruby/object:Gem::Requirement