--- src/extension/internal/image-resolution.cpp 2012-12-27 08:26:07 +0000 +++ src/extension/internal/image-resolution.cpp 2012-12-27 08:43:49 +0000 @@ -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 @@ if (!ok_) { readexif(fn); } + if (!ok_) { + readmagick(fn); + } } bool ImageResolution::ok() const { @@ -334,6 +340,33 @@ #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 */ + } } } --- src/extension/internal/image-resolution.h 2012-12-26 06:42:18 +0000 +++ src/extension/internal/image-resolution.h 2012-12-26 14:39:58 +0000 @@ -18,19 +18,20 @@ class ImageResolution { public: - ImageResolution(char const *fn); - bool ok() const; - double x() const; - double y() const; + ImageResolution(char const *fn); + bool ok() const; + double x() const; + double y() const; private: - bool ok_; - double x_; - double y_; + bool ok_; + double x_; + double y_; private: - void readpng(char const *fn); - void readexif(char const *fn); - void readexiv(char const *fn); - void readjfif(char const *fn); + void readpng(char const *fn); + void readexif(char const *fn); + void readexiv(char const *fn); + void readjfif(char const *fn); + void readmagick(char const *fn); }; }