From 5a75b3f90a53941f04f32dc8f22c25f2f855ad2e Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Sun, 12 May 2013 14:49:26 +0200 Subject: Fix for Bug #1085949 (Use ImageMagick fallback when importing bitmap resolution). Fixed bugs: - https://launchpad.net/bugs/1085949 (bzr r12330) --- src/extension/internal/image-resolution.cpp | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/extension/internal/image-resolution.cpp') diff --git a/src/extension/internal/image-resolution.cpp b/src/extension/internal/image-resolution.cpp index 51a3fe9c1..3c254a59c 100644 --- a/src/extension/internal/image-resolution.cpp +++ b/src/extension/internal/image-resolution.cpp @@ -21,6 +21,9 @@ #ifdef HAVE_JPEG #define IR_TRY_JFIF 1 #endif +#ifdef WITH_IMAGE_MAGICK +#include +#endif namespace Inkscape { namespace Extension { @@ -39,6 +42,9 @@ ImageResolution::ImageResolution(char const *fn) { if (!ok_) { readexif(fn); } + if (!ok_) { + readmagick(fn); + } } bool ImageResolution::ok() const { @@ -328,6 +334,33 @@ void ImageResolution::readjfif(char const *) { #endif +#ifdef WITH_IMAGE_MAGICK +void ImageResolution::readmagick(char const *fn) { + Magick::Image image; + try { + image.read(fn); + } catch (...) {} + Magick::Geometry geo = image.density(); + std::string type = image.magick(); + + if (type == "PNG") { // PNG only supports pixelspercentimeter + x_ = (double)geo.width() * 2.54; + y_ = (double)geo.height() * 2.54; + } else { + x_ = (double)geo.width(); + y_ = (double)geo.height(); + } + ok_ = true; +} + +#else + +// Dummy implementation +void ImageResolution::readmagick(char const *) { +} + +#endif /* WITH_IMAGE_MAGICK */ + } } } -- cgit v1.2.3