= t('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/")) ?>
+
+ = form::submit("SavePrefs", "Save") ?>
+
+
From 6013e96cf352309a45635e4759cfc8cbaf7c7ed0 Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Thu, 21 Apr 2011 20:15:20 -0600
Subject: [PATCH 02/32] Report as a site status when the graphics toolkit
doesn't support Raw Photos.
---
.../rawphoto/controllers/admin_rawphoto.php | 1 +
.../rawphoto/helpers/rawphoto_event.php | 4 ++++
.../rawphoto/helpers/rawphoto_graphics.php | 20 ++++++++++++++++++-
.../rawphoto/helpers/rawphoto_installer.php | 3 +++
.../rawphoto/views/admin_rawphoto.html.php | 2 +-
5 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/3.0/modules/rawphoto/controllers/admin_rawphoto.php b/3.0/modules/rawphoto/controllers/admin_rawphoto.php
index f4460476..8935f1a5 100644
--- a/3.0/modules/rawphoto/controllers/admin_rawphoto.php
+++ b/3.0/modules/rawphoto/controllers/admin_rawphoto.php
@@ -29,6 +29,7 @@ class Admin_RawPhoto_Controller extends Admin_Controller {
$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) ?
diff --git a/3.0/modules/rawphoto/helpers/rawphoto_event.php b/3.0/modules/rawphoto/helpers/rawphoto_event.php
index 04d5cf78..afcabc10 100644
--- a/3.0/modules/rawphoto/helpers/rawphoto_event.php
+++ b/3.0/modules/rawphoto/helpers/rawphoto_event.php
@@ -31,4 +31,8 @@ class rawphoto_event_Core {
"bay", "bmq", "cr2", "crw", "cs1", "dc2", "dcr", "dng", "fff", "k25", "kdc",
"mos", "mrw", "nef", "orf", "pef", "raf", "raw", "rdc", "srf", "x3f");
}
+
+ 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
index 258ad17e..0a2f7349 100644
--- a/3.0/modules/rawphoto/helpers/rawphoto_graphics.php
+++ b/3.0/modules/rawphoto/helpers/rawphoto_graphics.php
@@ -39,6 +39,23 @@ class rawphoto_graphics {
return $dcraw;
}
+ static function get_supported_toolkits() {
+ return array("imagemagick" => "ImageMagick",
+ "graphicsmagick" => "GraphicsMagick");
+ }
+
+ 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();
@@ -52,7 +69,7 @@ class rawphoto_graphics {
$cmd .= escapeshellarg($input_file);
// Then use the graphics toolkit to convert the stream to a JPEG.
- $cmd .= "| ";
+ $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");
@@ -77,6 +94,7 @@ class rawphoto_graphics {
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);
}
}
diff --git a/3.0/modules/rawphoto/helpers/rawphoto_installer.php b/3.0/modules/rawphoto/helpers/rawphoto_installer.php
index 54d80780..12709cfa 100644
--- a/3.0/modules/rawphoto/helpers/rawphoto_installer.php
+++ b/3.0/modules/rawphoto/helpers/rawphoto_installer.php
@@ -26,11 +26,14 @@ class rawphoto_installer {
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");
}
}
diff --git a/3.0/modules/rawphoto/views/admin_rawphoto.html.php b/3.0/modules/rawphoto/views/admin_rawphoto.html.php
index ac7e9727..71e2f699 100644
--- a/3.0/modules/rawphoto/views/admin_rawphoto.html.php
+++ b/3.0/modules/rawphoto/views/admin_rawphoto.html.php
@@ -20,7 +20,7 @@
if ($toolkit_name == "none"): ?>
= t('No suitable graphics toolkit was detected. ' .
- 'Please activate either ImageMagick or GraphicsMagick.',
+ 'Activate either ImageMagick or GraphicsMagick.',
array("activate_url" => url::site("admin/graphics"))) ?>
else: ?>
From b27680866507baccbd93d582ee437f3b3c4fcef1 Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Thu, 21 Apr 2011 23:02:38 -0600
Subject: [PATCH 03/32] Use the "self" reference.
---
3.0/modules/rawphoto/helpers/rawphoto_graphics.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/3.0/modules/rawphoto/helpers/rawphoto_graphics.php b/3.0/modules/rawphoto/helpers/rawphoto_graphics.php
index 0a2f7349..58387fd8 100644
--- a/3.0/modules/rawphoto/helpers/rawphoto_graphics.php
+++ b/3.0/modules/rawphoto/helpers/rawphoto_graphics.php
@@ -45,7 +45,7 @@ class rawphoto_graphics {
}
static function report_ppm_support($toolkit_id) {
- if (array_key_exists($toolkit_id, rawphoto_graphics::get_supported_toolkits())) {
+ if (array_key_exists($toolkit_id, self::get_supported_toolkits())) {
site_status::clear("rawphoto_needs_ppm_support");
} else {
site_status::warning(
@@ -58,7 +58,7 @@ class rawphoto_graphics {
static function convert($input_file, $output_file) {
$success = false;
- $dcraw = rawphoto_graphics::detect_dcraw();
+ $dcraw = self::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 ";
From 50d7febb6472d3b797928693f2d47f20913b6777 Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Fri, 22 Apr 2011 14:43:47 -0600
Subject: [PATCH 04/32] Don't forget to escape unsafe characters in error
messages.
---
3.0/modules/rawphoto/views/admin_rawphoto.html.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/3.0/modules/rawphoto/views/admin_rawphoto.html.php b/3.0/modules/rawphoto/views/admin_rawphoto.html.php
index 71e2f699..eadec8f9 100644
--- a/3.0/modules/rawphoto/views/admin_rawphoto.html.php
+++ b/3.0/modules/rawphoto/views/admin_rawphoto.html.php
@@ -15,7 +15,7 @@
= t("The dcraw tool was detected at %path.",
array("path" => $dcraw->path)) ?>
endif; ?>
= form::label("IccPath", t('Path to ICC profile', array("icc_url" =>
"http://www.permajet.com/30/Downloads/76/What_are_ICC_Profiles,_and_why_do_I_need_them.html"))) ?>
From 078d81a5f1acbe7ccdde996a7d7a65bf592eb874 Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Sat, 23 Apr 2011 16:42:13 -0600
Subject: [PATCH 06/32] 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");
}
}
From c39fc9a7ffedd6c0f9c14e71d11989ac1b491e58 Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Sat, 23 Apr 2011 21:20:47 -0600
Subject: [PATCH 07/32] Use the system::tempnam substitute so that extensions
are handled safely.
---
3.0/modules/rawphoto/helpers/rawphoto_event.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/3.0/modules/rawphoto/helpers/rawphoto_event.php b/3.0/modules/rawphoto/helpers/rawphoto_event.php
index d093804f..8c612bd0 100644
--- a/3.0/modules/rawphoto/helpers/rawphoto_event.php
+++ b/3.0/modules/rawphoto/helpers/rawphoto_event.php
@@ -21,7 +21,7 @@ class rawphoto_event_Core {
static function item_created($item) {
if ($item->is_photo()) {
$input_file = $item->file_path();
- $output_file = tempnam(TMPPATH, "rawphoto-") . ".jpg";
+ $output_file = system::tempnam(TMPPATH, "rawphoto-", ".jpg");
$success = rawphoto_graphics::convert($input_file, $output_file);
if ($success) {
$item->set_data_file($output_file);
From dd6c9f2298cf5108e8226468322de8ef2a5d2c70 Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Sat, 23 Apr 2011 22:52:43 -0600
Subject: [PATCH 08/32] Update a deprecated method and poor preg syntax so that
the Keep Original module will work.
---
3.0/modules/keeporiginal/helpers/keeporiginal_event.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/3.0/modules/keeporiginal/helpers/keeporiginal_event.php b/3.0/modules/keeporiginal/helpers/keeporiginal_event.php
index 8febcb35..a5c29d3f 100644
--- a/3.0/modules/keeporiginal/helpers/keeporiginal_event.php
+++ b/3.0/modules/keeporiginal/helpers/keeporiginal_event.php
@@ -26,7 +26,7 @@ class keeporiginal_event_Core {
// Figure out where the original copy should be stashed at.
$temp_path = str_replace(VARPATH . "albums/", "", $input_file);
$original_image = VARPATH . "original/" . $temp_path;
- $individual_dirs = split("[/\]", "original/" . $temp_path);
+ $individual_dirs = preg_split("|[/\\\\]|", "original/" . $temp_path);
// If any original file does not already exist, then create a folder structure
// similar to that found in VARPATH/albums/ and copy the photo over before
// rotating it.
From e3db324d20e0f2c2fc9e0692d404520062d50851 Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Sat, 23 Apr 2011 23:12:35 -0600
Subject: [PATCH 09/32] Extend the Keep Original module so that it is triggered
by updated data files.
---
3.0/modules/keeporiginal/helpers/keeporiginal_event.php | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/3.0/modules/keeporiginal/helpers/keeporiginal_event.php b/3.0/modules/keeporiginal/helpers/keeporiginal_event.php
index a5c29d3f..b026aee1 100644
--- a/3.0/modules/keeporiginal/helpers/keeporiginal_event.php
+++ b/3.0/modules/keeporiginal/helpers/keeporiginal_event.php
@@ -20,7 +20,10 @@
class keeporiginal_event_Core {
static function graphics_rotate($input_file, $output_file, $options) {
// Make a copy of the original fullsized image before rotating it.
+ self::preserve($input_file);
+ }
+ static function preserve($input_file) {
// If $input_file is located in VARPATH/albums/ then assume its a fullsize photo.
if (strncmp($input_file, VARPATH . "albums/", strlen(VARPATH . "albums/")) == 0) {
// Figure out where the original copy should be stashed at.
@@ -71,6 +74,9 @@ class keeporiginal_event_Core {
// VARPATH/original/ as well.
if ($old->is_photo() || $old->is_album()) {
+ if (isset($new->data_file)) {
+ self::preserve($old->file_path());
+ }
if ($old->file_path() != $new->file_path()) {
$old_original = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $old->file_path());
$new_original = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $new->file_path());
From 79f0bc872ec5ca7856cc6226b1c5b423887f68ba Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Sun, 24 Apr 2011 08:10:22 -0600
Subject: [PATCH 10/32] Use the new get_data_file() helper instead of reaching
inside the item.
---
3.0/modules/keeporiginal/helpers/keeporiginal_event.php | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/3.0/modules/keeporiginal/helpers/keeporiginal_event.php b/3.0/modules/keeporiginal/helpers/keeporiginal_event.php
index b026aee1..982eb808 100644
--- a/3.0/modules/keeporiginal/helpers/keeporiginal_event.php
+++ b/3.0/modules/keeporiginal/helpers/keeporiginal_event.php
@@ -74,8 +74,9 @@ class keeporiginal_event_Core {
// VARPATH/original/ as well.
if ($old->is_photo() || $old->is_album()) {
- if (isset($new->data_file)) {
- self::preserve($old->file_path());
+ $data_file = $new->get_data_file();
+ if (isset($data_file)) {
+ self::preserve($old->file_path());
}
if ($old->file_path() != $new->file_path()) {
$old_original = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $old->file_path());
From ab93a47867ddcfa19de06b21008faaa4858f4cee Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Sun, 24 Apr 2011 08:22:32 -0600
Subject: [PATCH 11/32] Mark an internal helper method as private.
---
3.0/modules/keeporiginal/helpers/keeporiginal_event.php | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/3.0/modules/keeporiginal/helpers/keeporiginal_event.php b/3.0/modules/keeporiginal/helpers/keeporiginal_event.php
index 982eb808..5652bee6 100644
--- a/3.0/modules/keeporiginal/helpers/keeporiginal_event.php
+++ b/3.0/modules/keeporiginal/helpers/keeporiginal_event.php
@@ -20,10 +20,10 @@
class keeporiginal_event_Core {
static function graphics_rotate($input_file, $output_file, $options) {
// Make a copy of the original fullsized image before rotating it.
- self::preserve($input_file);
+ self::_preserve($input_file);
}
- static function preserve($input_file) {
+ static function _preserve($input_file) {
// If $input_file is located in VARPATH/albums/ then assume its a fullsize photo.
if (strncmp($input_file, VARPATH . "albums/", strlen(VARPATH . "albums/")) == 0) {
// Figure out where the original copy should be stashed at.
@@ -76,7 +76,7 @@ class keeporiginal_event_Core {
if ($old->is_photo() || $old->is_album()) {
$data_file = $new->get_data_file();
if (isset($data_file)) {
- self::preserve($old->file_path());
+ self::_preserve($old->file_path());
}
if ($old->file_path() != $new->file_path()) {
$old_original = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $old->file_path());
From add2406b9b5004edfc5aa5203dc8c2997231599f Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Sun, 24 Apr 2011 08:53:42 -0600
Subject: [PATCH 12/32] Add a TODO to point out that the original's extension
shouldn't be changed.
---
3.0/modules/keeporiginal/helpers/keeporiginal_event.php | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/3.0/modules/keeporiginal/helpers/keeporiginal_event.php b/3.0/modules/keeporiginal/helpers/keeporiginal_event.php
index 5652bee6..513cb606 100644
--- a/3.0/modules/keeporiginal/helpers/keeporiginal_event.php
+++ b/3.0/modules/keeporiginal/helpers/keeporiginal_event.php
@@ -112,6 +112,7 @@ class keeporiginal_event_Core {
}
// Move the file to its new location.
+ // TODO: If the files have different extensions, then the old extension should be preserved.
@rename($old_original, $new_original);
}
}
@@ -135,4 +136,4 @@ class keeporiginal_event_Core {
}
}
}
-}
\ No newline at end of file
+}
From 7b8ceac55852ca51c1ba214ff9fd7059820e5336 Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Sun, 24 Apr 2011 10:00:37 -0600
Subject: [PATCH 13/32] Warn the user if they are using the Raw Photos module
but not the Keep Original module.
---
3.0/modules/rawphoto/controllers/admin_rawphoto.php | 1 +
3.0/modules/rawphoto/views/admin_rawphoto.html.php | 7 +++++++
2 files changed, 8 insertions(+)
diff --git a/3.0/modules/rawphoto/controllers/admin_rawphoto.php b/3.0/modules/rawphoto/controllers/admin_rawphoto.php
index 8935f1a5..c2e1bfb6 100644
--- a/3.0/modules/rawphoto/controllers/admin_rawphoto.php
+++ b/3.0/modules/rawphoto/controllers/admin_rawphoto.php
@@ -25,6 +25,7 @@ class Admin_RawPhoto_Controller extends Admin_Controller {
private function _get_view($errors = array(), $icc_path = null) {
$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 = rawphoto_graphics::detect_dcraw();
$toolkit_names = array("imagemagick" => "ImageMagick",
"graphicsmagick" => "GraphicsMagick");
diff --git a/3.0/modules/rawphoto/views/admin_rawphoto.html.php b/3.0/modules/rawphoto/views/admin_rawphoto.html.php
index 71e2f699..dc71d229 100644
--- a/3.0/modules/rawphoto/views/admin_rawphoto.html.php
+++ b/3.0/modules/rawphoto/views/admin_rawphoto.html.php
@@ -9,6 +9,13 @@
array("raw_url" =>
"http://www.adamcoupe.com/whitepapers/photography_technique_benefits_of_shooting_in_raw.htm",
"dcraw_url" => "http://www.cybercom.net/~dcoffin/dcraw/")) ?>
+ if (!$is_keeporiginal_active): ?>
+
+ = t('The photos will not be preserved in their raw format unless you ' .
+ 'activate the Keep Original module.',
+ array("modules_url" => url::site("admin/modules"))) ?>
+