diff --git a/lib/asciidoctor-pdf/asciidoctor_ext/image.rb b/lib/asciidoctor-pdf/asciidoctor_ext/image.rb index 019723d0e..9528652d0 100644 --- a/lib/asciidoctor-pdf/asciidoctor_ext/image.rb +++ b/lib/asciidoctor-pdf/asciidoctor_ext/image.rb @@ -2,17 +2,17 @@ module Asciidoctor module Image class << self def image_type path - (::File.extname path).downcase[1..-1] + (::File.extname path)[1..-1].downcase end end def image_type - ::File.extname(inline? ? target : (attr 'target')).downcase[1..-1] + (attr 'format', nil, false) || ::File.extname(inline? ? target : (attr 'target'))[1..-1].downcase end def target_with_image_type image_path = inline? ? (target) : (attr 'target') - [image_path, (::File.extname image_path).downcase[1..-1]] + [image_path, (attr 'format', nil, false) || (::File.extname image_path)[1..-1].downcase] end end end diff --git a/lib/asciidoctor-pdf/converter.rb b/lib/asciidoctor-pdf/converter.rb index b1bd053e5..5100195f1 100644 --- a/lib/asciidoctor-pdf/converter.rb +++ b/lib/asciidoctor-pdf/converter.rb @@ -798,7 +798,7 @@ def convert_image node warn %(asciidoctor: WARNING: GIF image format not supported. Please convert #{target} to PNG.) end - unless (image_path = resolve_image_path node, target) && (::File.readable? image_path) + unless (image_path = resolve_image_path node, target, image_type) && (::File.readable? image_path) valid_image = false warn %(asciidoctor: WARNING: image to embed not found or not readable: #{image_path || target}) end @@ -1510,7 +1510,7 @@ def convert_inline_image node warn %(asciidoctor: WARNING: GIF image format not supported. Please convert #{target} to PNG.) unless scratch? valid = false end - unless (image_path = resolve_image_path node, target) && (::File.readable? image_path) + unless (image_path = resolve_image_path node, target, image_type) && (::File.readable? image_path) warn %(asciidoctor: WARNING: image to embed not found or not readable: #{image_path || target}) unless scratch? valid = false end @@ -2517,7 +2517,7 @@ def resolve_imagesdir doc def resolve_image_path node, image_path = nil, image_type = nil imagesdir = resolve_imagesdir(doc = node.document) image_path ||= node.attr 'target' - image_type ||= ::Asciidoctor::Image.image_type image_path + image_type ||= ((node.attr 'format', nil, false) || (::Asciidoctor::Image.image_type image_path)) # handle case when image is a URI if (node.is_uri? image_path) || (imagesdir && (node.is_uri? imagesdir) && (image_path = (node.normalize_web_path image_path, imagesdir, false))) @@ -2532,7 +2532,7 @@ def resolve_image_path node, image_path = nil, image_type = nil else ::OpenURI end - tmp_image = ::Tempfile.new ['image-', %(.#{image_type})] + tmp_image = ::Tempfile.new ['image-', %(.#{image_type || 'jpg'})] tmp_image.binmode if (binary = image_type != 'svg') begin open(image_path, (binary ? 'rb' : 'r')) {|fd| tmp_image.write(fd.read) } @@ -2560,7 +2560,7 @@ def resolve_background_image doc, theme, key return bg_image if bg_image == 'none' if (bg_image.include? ':') && bg_image =~ ImageAttributeValueRx - # QUESTION should we support width and height in this case? + # QUESTION should we support width, height, and format in this case? bg_image = $1 end