Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ img/test1-fuji.jpg Testcase for RT #49546
img/tiny.pgm
img/upside-down.bmp
img/xxe.svg Testcase for RT #118099
img/logo.svg Testcase for GH PR#19
img/ztxt.png PNG example with ztxt chunk
imgdump Test driver script
lib/Bundle/Image/Info/Everything.pm
Expand Down
1 change: 1 addition & 0 deletions img/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 12 additions & 2 deletions lib/Image/Info/SVG/XMLLibXMLReader.pm
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,18 @@ sub process_file {
# first XML element
my $root_name = $reader->name;
if ($root_name eq 'svg') {
$info->push_info(0, 'height', $reader->getAttribute('height'));
$info->push_info(0, 'width', $reader->getAttribute('width'));
my @dimensions;
my $viewbox = $reader->getAttribute('viewBox');
if ($viewbox) {
@dimensions =
map { int($_) }
split(/(?: |,)/, $viewbox)
}

my $height = $reader->getAttribute('height') || $dimensions[3];
my $width = $reader->getAttribute('width') || $dimensions[2];
$info->push_info(0, 'height', $height);
$info->push_info(0, 'width', $width);

my $version = $reader->getAttribute('version') || 'unknown';
$info->push_info(0, 'SVG_Version', $version);
Expand Down
16 changes: 13 additions & 3 deletions lib/Image/Info/SVG/XMLSimple.pm
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,19 @@ sub process_file {
# "image/svg+xml" is the official MIME type
$info->push_info(0, "file_media_type" => "image/svg+xml");

$info->push_info(0, "height", $img->{height});
$info->push_info(0, "width", $img->{width});
$info->push_info(0, "SVG_StandAlone", $info{standalone});
my @dimensions;
if ($img->{viewBox}) {
@dimensions =
map { int($_) }
split(/(?: |,)/, $img->{viewBox});
}

my $height = $img->{height} || $dimensions[3];
my $width = $img->{width} || $dimensions[2];

$info->push_info(0, "height", $height);
$info->push_info(0, "width", $width);
$info->push_info(0, "SVG_StandAlone", $info{standalone} || 'no');
$info->push_info(0, "SVG_Version", $img->{version} || 'unknown');

# XXX Description, title etc. could be tucked away in a <g> :-(
Expand Down
16 changes: 15 additions & 1 deletion t/svg.t
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ BEGIN
plan skip_all => "Need XML::Simple+XML::SAX::PurePerl or XML::LibXML::Reader+XML::Simple for this test";
}

plan tests => 14;
plan tests => 19;
}

use Image::Info qw(image_info dim);
Expand Down Expand Up @@ -67,6 +67,20 @@ is ($i->{SVG_Version}, '1.1', 'SVG_Version 1.1');

is (dim($i), '209x51', 'dim()');

#############################################################################
# third test file
$i = image_info("../img/logo.svg") ||
die ("Couldn't read logo.svg: $!");

#use Data::Dumper; print Dumper($i), "\n";

is ($i->{SVG_StandAlone}, 'no', 'SVG_StandAlone');
is ($i->{file_ext}, 'svg', 'file_ext');
is ($i->{file_media_type}, 'image/svg+xml', 'file_media_type');
is ($i->{SVG_Title}, 'Logo-rdv', 'title');

is (dim($i), '383x57', 'dim()');

#############################################################################
# first file without xml preamble
{
Expand Down
Loading