Skip to content

Commit 2f40ba1

Browse files
committed
don't worry about converting known files
1 parent c286074 commit 2f40ba1

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

lib/obf/utils.rb

+11-5
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ def self.save_image(image, zipper=nil)
135135
end
136136
type = MIME::Types[image['content_type']]
137137
type = type && type[0]
138+
extension = nil
138139
if type.respond_to?(:preferred_extension)
139140
extension = type && ("." + type.preferred_extension)
140141
elsif type.respond_to?(:extensions)
@@ -152,11 +153,16 @@ def self.save_image(image, zipper=nil)
152153
return nil
153154
end
154155
file.close
155-
# TODO: maybe convert to jpg instead of png?
156-
# see https://github.com/prawnpdf/prawn/issues/324
157-
# in that case, fill the image with a white background, perhaps?
158-
`convert #{file.path} -density 1200 -resize 300x300 -background white -gravity center -extent 300x300 #{file.path}.png`
159-
"#{file.path}.png"
156+
if extension && ['image/png', 'image/jpeg', 'image/jpg', 'image/gif'].include?(image['content_type']) && image['width'] < 1000 && image['width'] == image['height']
157+
`cp #{file.path} #{file.path}.#{extension}`
158+
"#{file.path}.#{extension}"
159+
else
160+
# TODO: maybe convert to jpg instead of png?
161+
# see https://github.com/prawnpdf/prawn/issues/324
162+
# in that case, fill the image with a white background, perhaps?
163+
`convert #{file.path} -density 1200 -resize 300x300 -background white -gravity center -extent 300x300 #{file.path}.png`
164+
"#{file.path}.png"
165+
end
160166
end
161167

162168
def self.sound_raw(url)

0 commit comments

Comments
 (0)