From 8f4720b1d8df9e894dca59c5ac4c28e5b35208d1 Mon Sep 17 00:00:00 2001 From: Robin Liao Date: Sat, 3 Sep 2011 00:26:28 -0700 Subject: [PATCH] Added a fallback for mini_magic + ImageMagic for platforms where it is more than difficult to compile the ImageResizer --- Gemfile | 4 ++++ Gemfile.lock | 4 ++++ lib/danbooru_image_resizer/danbooru_image_resizer.rb | 6 +++++- .../danbooru_image_resizer_fallback.rb | 11 +++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 lib/danbooru_image_resizer/danbooru_image_resizer_fallback.rb diff --git a/Gemfile b/Gemfile index 6818d1ba1..d595b94f4 100644 --- a/Gemfile +++ b/Gemfile @@ -31,3 +31,7 @@ gem "whenever", :require => false group :development do gem 'pry' end + +group :osx do + gem 'mini_magick' +end diff --git a/Gemfile.lock b/Gemfile.lock index 4f01274a9..cb34376b9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -76,6 +76,8 @@ GEM method_source (0.6.0) ruby_parser (>= 2.0.5) mime-types (1.16) + mini_magick (3.3) + subexec (~> 0.1.0) mocha (0.9.12) multi_json (1.0.3) net-http-digest_auth (1.1.1) @@ -130,6 +132,7 @@ GEM hike (~> 1.2) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) + subexec (0.1.0) super_exception_notifier (3.0.13) actionmailer rake @@ -165,6 +168,7 @@ DEPENDENCIES mechanize memcache-client meta_search! + mini_magick mocha nokogiri pg diff --git a/lib/danbooru_image_resizer/danbooru_image_resizer.rb b/lib/danbooru_image_resizer/danbooru_image_resizer.rb index 0f4c8f628..c7da3dc4c 100644 --- a/lib/danbooru_image_resizer/danbooru_image_resizer.rb +++ b/lib/danbooru_image_resizer/danbooru_image_resizer.rb @@ -1,4 +1,8 @@ -require 'danbooru_image_resizer/danbooru_image_resizer.so' +begin + require 'danbooru_image_resizer/danbooru_image_resizer.so' +rescue LoadError + require 'danbooru_image_resizer/danbooru_image_resizer_fallback' +end module Danbooru def resize(file_ext, read_path, write_path, output_size, output_quality) diff --git a/lib/danbooru_image_resizer/danbooru_image_resizer_fallback.rb b/lib/danbooru_image_resizer/danbooru_image_resizer_fallback.rb new file mode 100644 index 000000000..10a04a91f --- /dev/null +++ b/lib/danbooru_image_resizer/danbooru_image_resizer_fallback.rb @@ -0,0 +1,11 @@ +module Danbooru + def resize_image(extension, original_path, destination_path, width, height, quality) + require 'mini_magick' + image = MiniMagick::Image.open(original_path) + image.resize "#{width}x#{height}" + image.format extension + image.write destination_path + end + + module_function :resize_image +end