1
0

Convert raw photos during an item_created event rather than a graphics rule.

This commit is contained in:
Chad Parry 2011-04-23 16:42:13 -06:00
parent 1347f0305e
commit 078d81a5f1
3 changed files with 17 additions and 10 deletions

View File

@ -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")

View File

@ -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;
}
}

View File

@ -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");
}
}