Skip to content

Commit

Permalink
resolves asciidoctor#540 allow image type to be specified using forma…
Browse files Browse the repository at this point in the history
…t attribute
  • Loading branch information
mojavelinux committed Sep 5, 2016
1 parent 54911c0 commit 5f42d07
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions lib/asciidoctor-pdf/asciidoctor_ext/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions lib/asciidoctor-pdf/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)))
Expand All @@ -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) }
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 5f42d07

Please sign in to comment.