Skip to content

Commit

Permalink
Merge pull request #150 from mojavelinux/issue-149-find-image-handler
Browse files Browse the repository at this point in the history
use Prawn.image_handler.find to resolve the image handler for the image data
  • Loading branch information
mogest authored Jun 1, 2022
2 parents e085b1d + 249f36d commit be7281d
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lib/prawn/svg/elements/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,14 @@ def bounding_box
protected

def image_dimensions(data)
handler = if data[0, 3].unpack("C*") == [255, 216, 255]
Prawn::Images::JPG
elsif data[0, 8].unpack("C*") == [137, 80, 78, 71, 13, 10, 26, 10]
Prawn::Images::PNG
else
raise SkipElementError, "Unsupported image type supplied to image tag; Prawn only supports JPG and PNG"
unless (handler = find_image_handler(data))
raise SkipElementError, 'Unsupported image type supplied to image tag'
end

image = handler.new(data)
[image.width.to_f, image.height.to_f]
end

def find_image_handler(data)
Prawn.image_handler.find(data) rescue nil
end
end

0 comments on commit be7281d

Please sign in to comment.