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..f4460476 --- /dev/null +++ b/3.0/modules/rawphoto/controllers/admin_rawphoto.php @@ -0,0 +1,63 @@ +_get_view(); + } + + private function _get_view($errors = array(), $icc_path = null) { + $view = new Admin_View("admin.html"); + $view->content = new View("admin_rawphoto.html"); + $view->content->dcraw = rawphoto_graphics::detect_dcraw(); + $toolkit_names = array("imagemagick" => "ImageMagick", + "graphicsmagick" => "GraphicsMagick"); + $toolkit_id = module::get_var("gallery", "graphics_toolkit"); + $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) && !@is_file($post->$field)) { + $post->add_error($field, t("No ICC profile exists at the location %icc_path", + array("icc_path" => $post->$field))); + } + } +} 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..04d5cf78 --- /dev/null +++ b/3.0/modules/rawphoto/helpers/rawphoto_event.php @@ -0,0 +1,34 @@ +get("settings_menu") + ->append(Menu::factory("link") + ->id("rawphoto") + ->label(t("Raw Photos")) + ->url(url::site("admin/rawphoto"))); + } + + static function upload_extensions($extensions_wrapper) { + array_push($extensions_wrapper->extensions, + "bay", "bmq", "cr2", "crw", "cs1", "dc2", "dcr", "dng", "fff", "k25", "kdc", + "mos", "mrw", "nef", "orf", "pef", "raf", "raw", "rdc", "srf", "x3f"); + } +} 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..258ad17e --- /dev/null +++ b/3.0/modules/rawphoto/helpers/rawphoto_graphics.php @@ -0,0 +1,88 @@ +installed = false; + $dcraw->error = t("The dcraw tool could not be located on your system."); + } else { + if (@is_file($path) && preg_match('/^Raw [Pp]hoto [Dd]ecoder(?: "dcraw")? v(\S+)$/m', + shell_exec($path), $matches)) { + $dcraw->installed = true; + $dcraw->path = $path; + $dcraw->version = $matches[1]; + } else { + $dcraw->installed = false; + $dcraw->error = t("The dcraw tool is installed, but PHP's open_basedir restriction " . + "prevents Gallery from using it."); + } + } + return $dcraw; + } + + 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 -W -t 0 "; + $icc_path = module::get_var("rawphoto", "icc_path"); + if (!empty($icc_path)) { + $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); + $success = ($return_var == 0); + } + } + if (!$success) { + // Make sure the unmodified output file exists where it's expected to be. + copy($input_file, $output_file); + } + } +} 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..54d80780 --- /dev/null +++ b/3.0/modules/rawphoto/helpers/rawphoto_installer.php @@ -0,0 +1,36 @@ + +
+

+ + +

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/")) ?>

+
+ + installed): ?> +

%path.", + array("path" => $dcraw->path)) ?>

+ +

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. + +
+ + +