-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdragonfly_libvips.rb
65 lines (57 loc) · 1.21 KB
/
dragonfly_libvips.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# frozen_string_literal: true
require "dragonfly"
require "dragonfly_libvips/dimensions"
require "dragonfly_libvips/plugin"
require "dragonfly_libvips/version"
require "vips"
module DragonflyLibvips
class UnsupportedFormat < RuntimeError; end
class UnsupportedOutputFormat < RuntimeError; end
CMYK_PROFILE_PATH = File.expand_path("../vendor/cmyk.icm", __dir__)
EPROFILE_PATH = File.expand_path("../vendor/sRGB_v4_ICC_preference.icc", __dir__)
SUPPORTED_FORMATS = begin
output = `vips -l | grep -i ForeignLoad`
output.scan(/\.(\w{1,4})/).flatten.compact.sort.map(&:downcase).uniq
end
SUPPORTED_OUTPUT_FORMATS = begin
output = `vips -l | grep -i ForeignSave`
output.scan(/\.(\w{1,4})/).flatten.compact.sort.map(&:downcase).uniq
end - %w[
csv
fit
fits
fts
mat
pbm
pfm
pgm
ppm
raw
v
vips
]
FORMATS_WITHOUT_PROFILE_SUPPORT = %w[
avif
bmp
dz
gif
hdr
heic
heif
j2c
j2k
jp2
jpc
jpt
jxl
szi
webp
]
private
def self.stringify_keys(hash = {})
hash.transform_keys { |k| k.to_s }
end
def self.symbolize_keys(hash = {})
hash.transform_keys { |k| k.to_sym }
end
end