oximg 0.11.0 → 0.13.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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -0
  3. data/lib/oximg/version.rb +1 -1
  4. data/lib/oximg.rb +34 -11
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f9240896922269e6e8e96d3fa5b78de6e67b53aa58c1bfe93d20c0e15487def
4
- data.tar.gz: 55b613d8b18ba178ed408ac16d867bc5728eae62eb9374ea9a0653c8108994da
3
+ metadata.gz: d8e96e80504c2840392866e6e3368bdc104960acc9353fee80817d2e031dd46c
4
+ data.tar.gz: f6b4a232dfb65542f5cc9dff93671201d43ce39a2d59f242847db439ffe5f68b
5
5
  SHA512:
6
- metadata.gz: 49173ccb9d336081d7670a8e4e5abcbc329a1dc25c623d4c414f75aac4bd083bebb1ff416382f8a2d1edeb5dc84ff27947cb7b9e76c9405ca8e1afb763bff59a
7
- data.tar.gz: 9e6d1cb6eceecaf1324d7f818f99b1596f664e442f9889e195f728a115c7895d36c35dd69abac3bba054c3b6caabdc82765b7c567a51bf8b53c94ea7aeaf15f3
6
+ metadata.gz: f1e6a68ea85cda538c21119eb5e1afff1e05f95b9278b9105330c3133c362ddb8c9d9b6719a459e7c492921fa36bf239a6566adad5ab1ec54175d7af293b3846
7
+ data.tar.gz: a84ed15c22a74222331e4f43444d182a7c9950ae4e646e2db7283463619776bfc937eeffa8e83a0a6c2cb71724102961f2ce9b342059d0806ef4003d754cc53a
data/README.md CHANGED
@@ -22,6 +22,10 @@ Oximg.probe("in.jpg")
22
22
  #=> {content_type: "image/jpeg", format: :jpeg, width: 4000, height: 3000}
23
23
  ```
24
24
 
25
+ A GIF source is read and probed like the others (`format: :gif`), but
26
+ nothing encodes GIF: it leaves as the destination's format, WebP when
27
+ the name does not say, and `:gif` is not a `format:` you can ask for.
28
+
25
29
  ## Resizing
26
30
 
27
31
  ```ruby
data/lib/oximg/version.rb CHANGED
@@ -7,5 +7,5 @@ module Oximg
7
7
  # names a binary it does not carry. `Oximg.version` reports what the
8
8
  # resolved executable actually is, which can differ when it comes
9
9
  # from PATH.
10
- VERSION = "0.11.0"
10
+ VERSION = "0.13.0"
11
11
  end
data/lib/oximg.rb CHANGED
@@ -45,10 +45,25 @@ module Oximg
45
45
  "image/jpeg" => :jpeg,
46
46
  "image/png" => :png,
47
47
  "image/webp" => :webp,
48
- "image/avif" => :avif
48
+ "image/avif" => :avif,
49
+ "image/gif" => :gif
49
50
  }.freeze
50
51
 
51
- PROBE_LINE = /:\s+(\S+)\s+(\d+)x(\d+)\s+\(\d+\s+stored\s+pixels\)\s*\z/
52
+ # The line `oximg probe` prints (src/cli.rs):
53
+ #
54
+ # in.gif: image/gif 120x90 (10800 stored pixels), 3 frames, 1500ms, looping forever
55
+ #
56
+ # The three fields the gem reports are pinned exactly. Everything after
57
+ # the comma — the animation summary, printed for an animated source
58
+ # only — is information the gem does not expose, and is deliberately
59
+ # left unparsed rather than matched: a pattern that stopped at
60
+ # `pixels)` is what broke probe when the CLI added that summary, and a
61
+ # pattern that spelled the summary out would break again on the next
62
+ # field. What is refused is output that is not exactly that one line:
63
+ # a field missing, a continuation without the comma, or anything
64
+ # printed before or after it. stderr is captured separately, so a
65
+ # warning never lands here.
66
+ PROBE_LINE = /\A[^\n]*: (\S+) (\d+)x(\d+) \(\d+ stored pixels\)(?:,[^\n]*)?\n?\z/
52
67
 
53
68
  class << self
54
69
  # Absolute path to the executable in use; raises
@@ -96,15 +111,7 @@ module Oximg
96
111
  # dimensions are the stored ones (an EXIF rotation is not applied).
97
112
  def probe(source)
98
113
  out, = Binary.run("probe", expand(source, "source"))
99
- match = out.match(PROBE_LINE)
100
- raise ProcessingError, "unparsable probe output: #{out.inspect}" unless match
101
-
102
- {
103
- content_type: match[1],
104
- format: CONTENT_TYPE_FORMATS[match[1]],
105
- width: Integer(match[2]),
106
- height: Integer(match[3])
107
- }
114
+ parse_probe(out)
108
115
  end
109
116
 
110
117
  # The argv `resize` would run, minus the executable. Public because
@@ -126,6 +133,22 @@ module Oximg
126
133
 
127
134
  private
128
135
 
136
+ # The hash `probe` builds from the line the CLI printed. Separate
137
+ # from `probe` so the parser can be tested against every line the
138
+ # CLI can print — the still form, each loop spelling — without a
139
+ # binary present; private because nothing outside needs it.
140
+ def parse_probe(output)
141
+ match = output.match(PROBE_LINE)
142
+ raise ProcessingError, "unparsable probe output: #{output.inspect}" unless match
143
+
144
+ {
145
+ content_type: match[1],
146
+ format: CONTENT_TYPE_FORMATS[match[1]],
147
+ width: Integer(match[2]),
148
+ height: Integer(match[3])
149
+ }
150
+ end
151
+
129
152
  # Absolute paths throughout: a relative name beginning with "-"
130
153
  # would otherwise reach the CLI's argument parser as a flag, and
131
154
  # the caller rarely controls what an uploaded file is called.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oximg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - oximg contributors