From 078d81a5f1acbe7ccdde996a7d7a65bf592eb874 Mon Sep 17 00:00:00 2001 From: Chad Parry Date: Sat, 23 Apr 2011 16:42:13 -0600 Subject: [PATCH] Convert raw photos during an item_created event rather than a graphics rule. --- 3.0/modules/rawphoto/helpers/rawphoto_event.php | 13 +++++++++++++ 3.0/modules/rawphoto/helpers/rawphoto_graphics.php | 8 ++++---- 3.0/modules/rawphoto/helpers/rawphoto_installer.php | 6 ------ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/3.0/modules/rawphoto/helpers/rawphoto_event.php b/3.0/modules/rawphoto/helpers/rawphoto_event.php index afcabc10..d093804f 100644 --- a/3.0/modules/rawphoto/helpers/rawphoto_event.php +++ b/3.0/modules/rawphoto/helpers/rawphoto_event.php @@ -18,6 +18,19 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class rawphoto_event_Core { + static function item_created($item) { + if ($item->is_photo()) { + $input_file = $item->file_path(); + $output_file = tempnam(TMPPATH, "rawphoto-") . ".jpg"; + $success = rawphoto_graphics::convert($input_file, $output_file); + if ($success) { + $item->set_data_file($output_file); + $item->save(); + unlink($output_file); + } + } + } + static function admin_menu($menu, $theme) { $menu->get("settings_menu") ->append(Menu::factory("link") diff --git a/3.0/modules/rawphoto/helpers/rawphoto_graphics.php b/3.0/modules/rawphoto/helpers/rawphoto_graphics.php index 58387fd8..550b3c36 100644 --- a/3.0/modules/rawphoto/helpers/rawphoto_graphics.php +++ b/3.0/modules/rawphoto/helpers/rawphoto_graphics.php @@ -96,11 +96,11 @@ class rawphoto_graphics { exec($cmd, $output, $return_var); // Failure is common, because dcraw will abort unless the original image is a raw photo. $success = ($return_var == 0); + if (!$success) { + @unlink($output_file); + } } } - if (!$success) { - // Make sure the unmodified output file exists where it's expected to be. - copy($input_file, $output_file); - } + return $success; } } diff --git a/3.0/modules/rawphoto/helpers/rawphoto_installer.php b/3.0/modules/rawphoto/helpers/rawphoto_installer.php index 12709cfa..73ab31f2 100644 --- a/3.0/modules/rawphoto/helpers/rawphoto_installer.php +++ b/3.0/modules/rawphoto/helpers/rawphoto_installer.php @@ -23,17 +23,11 @@ class rawphoto_installer { } static function activate() { - foreach (array("thumb", "resize") as $target) { - graphics::add_rule("rawphoto", $target, "rawphoto_graphics::convert", array(), 10); - } $toolkit_id = module::get_var("gallery", "graphics_toolkit"); rawphoto_graphics::report_ppm_support($toolkit_id); } static function deactivate() { - foreach (array("thumb", "resize") as $target) { - graphics::remove_rule("rawphoto", $target, "rawphoto_graphics::convert"); - } site_status::clear("rawphoto_needs_ppm_support"); } }