From 9bd335079fec10d9d552d6ba3b94c9f46310abaf Mon Sep 17 00:00:00 2001 From: Pierre Inglebert Date: Wed, 2 Apr 2014 21:04:01 +0200 Subject: [PATCH 1/2] check input files with vips foreign lib --- src/sharp.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sharp.cc b/src/sharp.cc index c7bca46a..b8902c7d 100755 --- a/src/sharp.cc +++ b/src/sharp.cc @@ -98,21 +98,21 @@ class ResizeWorker : public NanAsyncWorker { (baton->err).append("Unsupported input buffer"); return; } - } else if (is_jpeg(baton->file_in)) { + } else if (vips_foreign_is_a("jpegload", baton->file_in.c_str())) { if (vips_jpegload((baton->file_in).c_str(), &in, "access", baton->access_method, NULL)) { return resize_error(baton, in); } - } else if (is_png(baton->file_in)) { + } else if (vips_foreign_is_a("pngload", baton->file_in.c_str())) { inputImageType = PNG; if (vips_pngload((baton->file_in).c_str(), &in, "access", baton->access_method, NULL)) { return resize_error(baton, in); } - } else if (is_webp(baton->file_in)) { + } else if (vips_foreign_is_a("webpload", baton->file_in.c_str())) { inputImageType = WEBP; if (vips_webpload((baton->file_in).c_str(), &in, "access", baton->access_method, NULL)) { return resize_error(baton, in); } - } else if (is_tiff(baton->file_in)) { + } else if (vips_foreign_is_a("tiffload", baton->file_in.c_str())) { inputImageType = TIFF; if (vips_tiffload((baton->file_in).c_str(), &in, "access", baton->access_method, NULL)) { return resize_error(baton, in); From 19bec9346eee9068a8d9411c3e87c393507d2fbc Mon Sep 17 00:00:00 2001 From: Pierre Inglebert Date: Wed, 2 Apr 2014 22:17:41 +0200 Subject: [PATCH 2/2] add libmagick load support --- README.md | 2 +- src/sharp.cc | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index de2df328..78b5c5d2 100755 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ This module is powered by the blazingly fast [libvips](https://github.com/jcupit ### Install libvips on Mac OS - brew install homebrew/science/vips --with-webp + brew install homebrew/science/vips --with-webp --with-graphicsmagick The _gettext_ dependency of _libvips_ [can lead](https://github.com/lovell/sharp/issues/9) to a `library not found for -lintl` error. If so, please try: diff --git a/src/sharp.cc b/src/sharp.cc index b8902c7d..b8409ef4 100755 --- a/src/sharp.cc +++ b/src/sharp.cc @@ -33,7 +33,8 @@ typedef enum { JPEG, PNG, WEBP, - TIFF + TIFF, + MAGICK } ImageType; unsigned char MARKER_JPEG[] = {0xff, 0xd8}; @@ -117,6 +118,11 @@ class ResizeWorker : public NanAsyncWorker { if (vips_tiffload((baton->file_in).c_str(), &in, "access", baton->access_method, NULL)) { return resize_error(baton, in); } + } else if(vips_foreign_is_a("magickload", (baton->file_in).c_str())) { + inputImageType = MAGICK; + if (vips_magickload((baton->file_in).c_str(), &in, "access", baton->access_method, NULL)) { + return resize_error(baton, in); + } } else { resize_error(baton, in); (baton->err).append("Unsupported input file " + baton->file_in);