Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse out Ghostscript warnings in identfication #522

Merged
merged 1 commit into from Nov 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/mini_magick/image/info.rb
Expand Up @@ -42,7 +42,7 @@ def clear

def cheap_info(value)
@info.fetch(value) do
format, width, height, size = self["%m %w %h %b"].split(" ")
format, width, height, size = parse_warnings(self["%m %w %h %b"]).split(" ")

path = @path
path = path.match(/\[\d+\]$/).pre_match if path =~ /\[\d+\]$/
Expand All @@ -61,6 +61,16 @@ def cheap_info(value)
rescue ArgumentError, TypeError
raise MiniMagick::Invalid, "image data can't be read"
end

def parse_warnings(raw_info)
return raw_info unless raw_info.split("\n").size > 1

raw_info.split("\n").each do |line|
# must match "%m %w %h %b"
return line if line.match? /^[A-Z]+ \d+ \d+ \d+B$/
end
raise TypeError
end

def colorspace
@info["colorspace"] ||= self["%r"]
Expand Down