diff --git a/MANIFEST b/MANIFEST
index 47c9380..afd8c58 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -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
diff --git a/img/logo.svg b/img/logo.svg
new file mode 100644
index 0000000..4dad3e2
--- /dev/null
+++ b/img/logo.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/lib/Image/Info/SVG/XMLLibXMLReader.pm b/lib/Image/Info/SVG/XMLLibXMLReader.pm
index 6afa880..a26115b 100644
--- a/lib/Image/Info/SVG/XMLLibXMLReader.pm
+++ b/lib/Image/Info/SVG/XMLLibXMLReader.pm
@@ -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);
diff --git a/lib/Image/Info/SVG/XMLSimple.pm b/lib/Image/Info/SVG/XMLSimple.pm
index f28b09b..6719f5e 100644
--- a/lib/Image/Info/SVG/XMLSimple.pm
+++ b/lib/Image/Info/SVG/XMLSimple.pm
@@ -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 :-(
diff --git a/t/svg.t b/t/svg.t
index ee1bf3d..81657e0 100755
--- a/t/svg.t
+++ b/t/svg.t
@@ -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);
@@ -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
{