Skip to content

Commit 249f36d

Browse files
committed
use Prawn.image_handler.find to resolve the image handler for the image data
1 parent e085b1d commit 249f36d

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

lib/prawn/svg/elements/image.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,14 @@ def bounding_box
6767
protected
6868

6969
def image_dimensions(data)
70-
handler = if data[0, 3].unpack("C*") == [255, 216, 255]
71-
Prawn::Images::JPG
72-
elsif data[0, 8].unpack("C*") == [137, 80, 78, 71, 13, 10, 26, 10]
73-
Prawn::Images::PNG
74-
else
75-
raise SkipElementError, "Unsupported image type supplied to image tag; Prawn only supports JPG and PNG"
70+
unless (handler = find_image_handler(data))
71+
raise SkipElementError, 'Unsupported image type supplied to image tag'
7672
end
77-
7873
image = handler.new(data)
7974
[image.width.to_f, image.height.to_f]
8075
end
76+
77+
def find_image_handler(data)
78+
Prawn.image_handler.find(data) rescue nil
79+
end
8180
end

0 commit comments

Comments
 (0)