function resolve(path) if (not(pandoc.path.is_relative(path))) then return path end local input_path = PANDOC_STATE.input_files[1] local dir_path = pandoc.path.directory(input_path) return pandoc.path.join({dir_path, path}) end function Image(img) local path = resolve(img.src) local size = pandoc.pipe('xargs', {'identify', '-format', '%wx%h'}, path) local width, height = size:match("(%d+)x(%d+)") img.attributes.width = width img.attributes.height = height return img end