image_processing 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of image_processing might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c6647897aed5a610f76eae2edef4327ec092653
4
- data.tar.gz: '09335920e634fc2cb83a8be2111dda2c340421e2'
3
+ metadata.gz: 908334dfbdaa9424701386bb8c1722d23679f726
4
+ data.tar.gz: abbc3ca67468cedb3729aae261e04e49f1d19cf7
5
5
  SHA512:
6
- metadata.gz: f1fbf330dc866bcabe44121cdf1f27ee488db46cbcdcc0d6cbfae07b95c9064740047d5faf63a02fc2ce6e11e14b8cf425dfa59ae716ff964ec5947a5e98be96
7
- data.tar.gz: 332f2ad092e5ea7a5bda88388d152d11f8a788cd7659cb53e8370a83fcd5358c4078d677af6d89e594adfa04e050d12b2fcd4dcb1d2586020449b5285f098cb1
6
+ metadata.gz: 151d52c9bba7feb70a516cda8e59b865e4684993646703219d0806aa0a92b6511cbd15d6af0b0f6d83b948a85926a35a465ccc4bc96531a68e499c4556743ed7
7
+ data.tar.gz: bcfb395d26a68bfe7cb21994a319fc982bbd8702a83123d7ac825064c582e46a5bedf3c33263b7f0f6b28e6420786ec1e54b029abf54ed90c487ad52539318ff
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 1.1.0 (2018-04-05)
2
+
3
+ * [minimagick] Disallow splitting multi-layer images into multiple single-layer
4
+ images by default to avoid unexpected behaviour, but can be re-enabled with
5
+ the `:allow_splitting` saver option (@janko-m)
6
+
7
+ * [core] Add `#apply` for applying a list of operations (@janko-m)
8
+
1
9
  ## 1.0.0 (2018-04-04)
2
10
 
3
11
  * Depend on `mini_magick` and `ruby-vips` gems (@janko-m, @mokolabs)
data/README.md CHANGED
@@ -5,7 +5,7 @@ when handling image uploads.
5
5
 
6
6
  This gem can process images with either [ImageMagick] or [libvips] libraries.
7
7
  ImageMagick is a good default choice, especially if you are migrating from
8
- another gem or library that uses ImageMagick. libvips is a newer library that
8
+ another gem or library that uses ImageMagick. Libvips is a newer library that
9
9
  can process images [very rapidly][libvips performance] (up to 10x faster than
10
10
  ImageMagick).
11
11
 
@@ -16,6 +16,10 @@ module ImageProcessing
16
16
  branch saver: options
17
17
  end
18
18
 
19
+ def apply(operations)
20
+ operation :apply, operations
21
+ end
22
+
19
23
  def custom(&block)
20
24
  operation :custom, block
21
25
  end
@@ -70,12 +70,13 @@ module ImageProcessing
70
70
  magick
71
71
  end
72
72
 
73
- def save_image(magick, destination_path, **options)
73
+ def save_image(magick, destination_path, allow_splitting: false, **options)
74
74
  apply_options(magick, options)
75
75
 
76
76
  magick << destination_path
77
-
78
77
  magick.call
78
+
79
+ disallow_split_layers!(destination_path) unless allow_splitting
79
80
  end
80
81
 
81
82
  private
@@ -94,14 +95,7 @@ module ImageProcessing
94
95
  end
95
96
 
96
97
  def apply_options(magick, define: {}, **options)
97
- options.each do |option, value|
98
- case value
99
- when true, nil then magick.send(option)
100
- when false then magick.send(option).+
101
- else magick.send(option, *value)
102
- end
103
- end
104
-
98
+ apply(magick, options)
105
99
  apply_define(magick, define)
106
100
  end
107
101
 
@@ -121,6 +115,15 @@ module ImageProcessing
121
115
  magick.args.replace args + magick.args
122
116
  magick
123
117
  end
118
+
119
+ def disallow_split_layers!(destination_path)
120
+ layers = Dir[destination_path.sub(/\.\w+$/, '-*\0')]
121
+
122
+ if layers.any?
123
+ layers.each { |path| File.delete(path) }
124
+ raise Error, "Multi-layer image is being converted into a single-layer format. You should either process individual layers or set :allow_splitting to true. See https://github.com/janko-m/image_processing/wiki/Splitting-a-PDF-into-multiple-images for how to process each layer individually."
125
+ end
126
+ end
124
127
  end
125
128
 
126
129
  extend Chainable
@@ -4,6 +4,16 @@ module ImageProcessing
4
4
  @pipeline = pipeline
5
5
  end
6
6
 
7
+ def apply(image, operations)
8
+ operations.inject(image) do |result, (name, args)|
9
+ if args == true || args.nil?
10
+ apply_operation(name, result)
11
+ else
12
+ apply_operation(name, result, *args)
13
+ end
14
+ end
15
+ end
16
+
7
17
  def apply_operation(name, image, *args)
8
18
  if respond_to?(name)
9
19
  public_send(name, image, *args)
@@ -1,3 +1,3 @@
1
1
  module ImageProcessing
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: image_processing
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janko Marohnić
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-04 00:00:00.000000000 Z
11
+ date: 2018-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mini_magick