diff --git a/3.0/modules/rawphoto/controllers/admin_rawphoto.php b/3.0/modules/rawphoto/controllers/admin_rawphoto.php new file mode 100644 index 00000000..0cf169f9 --- /dev/null +++ b/3.0/modules/rawphoto/controllers/admin_rawphoto.php @@ -0,0 +1,74 @@ +_get_view(); + } + + private function _get_view($errors = array(), $icc_path = null) { + $dcraw = rawphoto_graphics::detect_dcraw(); + rawphoto_graphics::report_dcraw_support($dcraw); + + $view = new Admin_View("admin.html"); + $view->content = new View("admin_rawphoto.html"); + $view->content->is_keeporiginal_active = module::is_active("keeporiginal"); + $view->content->dcraw = $dcraw; + $toolkit_names = array("imagemagick" => "ImageMagick", + "graphicsmagick" => "GraphicsMagick"); + $toolkit_id = module::get_var("gallery", "graphics_toolkit"); + $toolkit_names = rawphoto_graphics::get_supported_toolkits(); + $view->content->toolkit_name = array_key_exists($toolkit_id, $toolkit_names) ? + $toolkit_names[$toolkit_id] : "none"; + $view->content->icc_path = isset($icc_path) ? + $icc_path : module::get_var("rawphoto", "icc_path"); + $view->content->errors = $errors; + return $view; + } + + public function saveprefs() { + // Prevent Cross Site Request Forgery + access::verify_csrf(); + + $post = new Validation($_POST); + $post->add_callbacks("IccPath", array($this, "_validate_icc_path")); + $icc_path = Input::instance()->post("IccPath"); + if ($post->validate()) { + module::set_var("rawphoto", "icc_path", $icc_path); + message::success(t("Your preferences have been saved.")); + } else { + message::error(t("Your preferences are not valid.")); + } + + print $this->_get_view($post->errors(), $icc_path); + } + + public function _validate_icc_path(Validation $post, $field) { + if (!empty($post->$field)) { + if (!@is_file($post->$field)) { + $post->add_error($field, t("No ICC profile exists at the location %icc_path", + array("icc_path" => $post->$field))); + } + $dcraw = rawphoto_graphics::detect_dcraw(); + if (version_compare($dcraw->version, "8.00", "<")) { + $post->add_error($field, t("Versions of dcraw before 8.00 do not support an ICC profile")); + } + } + } +} diff --git a/3.0/modules/rawphoto/helpers/rawphoto_event.php b/3.0/modules/rawphoto/helpers/rawphoto_event.php new file mode 100644 index 00000000..7abcd02c --- /dev/null +++ b/3.0/modules/rawphoto/helpers/rawphoto_event.php @@ -0,0 +1,66 @@ +is_photo()) { + $input_file = $item->file_path(); + $output_file = system::temp_filename("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") + ->id("rawphoto") + ->label(t("Raw Photos")) + ->url(url::site("admin/rawphoto"))); + } + + static function legal_photo_extensions($extensions_wrapper) { + array_push($extensions_wrapper->extensions, + "3fr", "arw", "bay", "bmq", "cr2", "crw", "cs1", "dc2", "dcr", "dng", "erf", + "fff", "k25", "kdc", "mef", "mos", "mrw", "nef", "orf", "pef", "raf", "raw", + "rdc", "rw2", "sr2", "srf", "x3f"); + } + + static function legal_photo_types($types_wrapper) { + array_push($types_wrapper->types, + // Most raw photos are detected as TIFF. + "image/tiff", + // Minolta raw photos are mis-detected as wireless bitmap format. + "image/vnd.wap.wbmp", + // All other raw photos have unrecognized formats. + ""); + } + + static function module_change($changes) { + rawphoto_version::report_item_conversion_support(); + } + + static function graphics_toolkit_change($toolkit_id) { + rawphoto_graphics::report_ppm_support($toolkit_id); + } +} diff --git a/3.0/modules/rawphoto/helpers/rawphoto_graphics.php b/3.0/modules/rawphoto/helpers/rawphoto_graphics.php new file mode 100644 index 00000000..4a8da2ae --- /dev/null +++ b/3.0/modules/rawphoto/helpers/rawphoto_graphics.php @@ -0,0 +1,128 @@ +installed = false; + $dcraw->error = t("The dcraw tool could not be located on your system."); + } else { + $dcraw->path = $path; + if (!@is_file($path)) { + $dcraw->installed = false; + $dcraw->error = t("The dcraw tool is installed, " . + "but PHP's open_basedir restriction " . + "prevents Gallery from using it."); + } else if (!preg_match('/^Raw [Pp]hoto [Dd]ecoder(?: "dcraw")? v(\S+)$/m', + shell_exec(escapeshellcmd($path) . " 2>&1"), $matches)) { + $dcraw->installed = false; + $dcraw->error = t("The dcraw tool is installed, " . + "but the version is not recognized."); + } else { + $dcraw->version = $matches[1]; + $dcraw->installed = true; + } + } + return $dcraw; + } + + static function get_supported_toolkits() { + return array("imagemagick" => "ImageMagick", + "graphicsmagick" => "GraphicsMagick"); + } + + static function report_dcraw_support($dcraw) { + if ($dcraw->installed) { + site_status::clear("rawphoto_needs_dcraw"); + } else { + site_status::warning( + t('The Raw Photos module requires the dcraw tool to be installed.', + array("dcraw_url" => "http://www.cybercom.net/~dcoffin/dcraw/")), + "rawphoto_needs_dcraw"); + } + } + + static function report_ppm_support($toolkit_id) { + if (array_key_exists($toolkit_id, rawphoto_graphics::get_supported_toolkits())) { + site_status::clear("rawphoto_needs_ppm_support"); + } else { + site_status::warning( + t('The Raw Photos module requires a supporting graphics toolkit. ' . + 'Activate either ImageMagick or GraphicsMagick.', + array("activate_url" => url::site("admin/graphics"))), + "rawphoto_needs_ppm_support"); + } + } + + static function convert($input_file, $output_file) { + $success = false; + $dcraw = rawphoto_graphics::detect_dcraw(); + if ($dcraw->installed) { + // Use dcraw to convert from a raw image to a standard pixmap. + $cmd = escapeshellcmd($dcraw->path) . " -c -w "; + if (version_compare($dcraw->version, "6.00", ">=")) { + $cmd .= "-t 0 "; + } + if (version_compare($dcraw->version, "8.81", ">=")) { + $cmd .= "-W "; + } + $icc_path = module::get_var("rawphoto", "icc_path"); + if (!empty($icc_path) && version_compare($dcraw->version, "8.00", ">=")) { + $cmd .= "-p " . escapeshellarg($icc_path) . " "; + } + $cmd .= escapeshellarg($input_file); + + // Then use the graphics toolkit to convert the stream to a JPEG. + $cmd .= " | "; + $toolkit_id = module::get_var("gallery", "graphics_toolkit"); + $toolkit_path = module::get_var("gallery", "graphics_toolkit_path"); + $image_quality = module::get_var("gallery", "image_quality"); + $toolkit_compat = false; + switch ($toolkit_id) { + case 'imagemagick': + $cmd .= escapeshellcmd("$toolkit_path/convert"); + $cmd .= " -quality " . escapeshellarg($image_quality . "%"); + $cmd .= " - " . escapeshellarg($output_file); + $toolkit_compat = true; + break; + case 'graphicsmagick': + $cmd .= escapeshellcmd("$toolkit_path/gm"); + $cmd .= " convert -quality " . escapeshellarg($image_quality . "%"); + $cmd .= " - " . escapeshellarg($output_file); + $toolkit_compat = true; + break; + default: + log::warning("rawphoto", "Cannot convert raw photo with graphics toolkit: " . + $toolkit_id->active); + } + + if ($toolkit_compat) { + 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); + } + } + } + return $success; + } +} diff --git a/3.0/modules/rawphoto/helpers/rawphoto_installer.php b/3.0/modules/rawphoto/helpers/rawphoto_installer.php new file mode 100644 index 00000000..466c41e3 --- /dev/null +++ b/3.0/modules/rawphoto/helpers/rawphoto_installer.php @@ -0,0 +1,38 @@ +=")) { + site_status::clear("rawphoto_needs_item_conversion_support"); + } else { + site_status::warning( + t("The Raw Photos module requires Gallery %version or higher.", + array("version" => rawphoto_version::MIN_RELEASE_VERSION)), + "rawphoto_needs_item_conversion_support"); + } + } else { + if (version_compare(gallery::build_number(), rawphoto_version::MIN_BUILD_NUMBER, ">=")) { + site_status::clear("rawphoto_needs_item_conversion_support"); + } else { + site_status::warning( + t("The Raw Photos module requires Gallery %version, build %build_number or higher.", + array("version" => gallery::VERSION, + "build_number" => rawphoto_version::MIN_BUILD_NUMBER)), + "rawphoto_needs_item_conversion_support"); + } + } + } +} diff --git a/3.0/modules/rawphoto/module.info b/3.0/modules/rawphoto/module.info new file mode 100644 index 00000000..c5cfc0eb --- /dev/null +++ b/3.0/modules/rawphoto/module.info @@ -0,0 +1,7 @@ +name = "Raw Photos" +description = "Use raw photos produced by a digital camera." +version = 3 +author_name = "Chad Parry" +author_url = "http://codex.gallery2.org/User:Chadparry" +info_url = "http://codex.gallery2.org/Gallery3:Modules:rawphoto" +discuss_url = "http://gallery.menalto.com/node/101817" diff --git a/3.0/modules/rawphoto/views/admin_rawphoto.html.php b/3.0/modules/rawphoto/views/admin_rawphoto.html.php new file mode 100644 index 00000000..93b92e0b --- /dev/null +++ b/3.0/modules/rawphoto/views/admin_rawphoto.html.php @@ -0,0 +1,50 @@ + +
+

+ + +

Raw photo processing depends on the ' . + 'dcraw tool, which must be installed separately. ' . + 'It also depends on either the ImageMagick or GraphicsMagick graphics toolkits.', + array("raw_url" => + "http://www.adamcoupe.com/whitepapers/photography_technique_benefits_of_shooting_in_raw.htm", + "dcraw_url" => "http://www.cybercom.net/~dcoffin/dcraw/")) ?>

+ +

+ activate the Keep Original module.', + array("modules_url" => url::site("admin/modules"))) ?> +

+ +
+ + installed): ?> +

dcraw tool was detected at %path " . + "with version %version.", + array("path" => $dcraw->path, "version" => $dcraw->version)) ?>

+ +

error ?>

+ + +

+ Activate either ImageMagick or GraphicsMagick.', + array("activate_url" => url::site("admin/graphics"))) ?> +

+ +

$toolkit_name)) ?>

+ + +

+ + ICC profile', array("icc_url" => + "http://www.permajet.com/30/Downloads/76/What_are_ICC_Profiles,_and_why_do_I_need_them.html"))) ?> + "IccPath", "id" => "IccPath"), $icc_path) ?> + + An ICC profile is optional. If you don't know what it is, then you don't need it. + +
+ + +