Add support for raw photo formats.
This commit is contained in:
parent
3849af5cd1
commit
8500fba8a0
63
3.0/modules/rawphoto/controllers/admin_rawphoto.php
Normal file
63
3.0/modules/rawphoto/controllers/admin_rawphoto.php
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
|
/**
|
||||||
|
* Gallery - a web based photo album viewer and editor
|
||||||
|
* Copyright (C) 2011 Chad Parry
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
class Admin_RawPhoto_Controller extends Admin_Controller {
|
||||||
|
public function index() {
|
||||||
|
print $this->_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 <code>%icc_path</code>",
|
||||||
|
array("icc_path" => $post->$field)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
34
3.0/modules/rawphoto/helpers/rawphoto_event.php
Normal file
34
3.0/modules/rawphoto/helpers/rawphoto_event.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
|
/**
|
||||||
|
* Gallery - a web based photo album viewer and editor
|
||||||
|
* Copyright (C) 2011 Chad Parry
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
class rawphoto_event_Core {
|
||||||
|
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 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");
|
||||||
|
}
|
||||||
|
}
|
88
3.0/modules/rawphoto/helpers/rawphoto_graphics.php
Normal file
88
3.0/modules/rawphoto/helpers/rawphoto_graphics.php
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
|
/**
|
||||||
|
* Gallery - a web based photo album viewer and editor
|
||||||
|
* Copyright (C) 2011 Chad Parry
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
class rawphoto_graphics {
|
||||||
|
static function detect_dcraw() {
|
||||||
|
$dcraw = new stdClass();
|
||||||
|
$path = system::find_binary("dcraw");
|
||||||
|
if (empty($path)) {
|
||||||
|
$dcraw->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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
36
3.0/modules/rawphoto/helpers/rawphoto_installer.php
Normal file
36
3.0/modules/rawphoto/helpers/rawphoto_installer.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
|
/**
|
||||||
|
* Gallery - a web based photo album viewer and editor
|
||||||
|
* Copyright (C) 2011 Chad Parry
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
class rawphoto_installer {
|
||||||
|
static function install() {
|
||||||
|
module::set_version("rawphoto", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static function activate() {
|
||||||
|
foreach (array("thumb", "resize") as $target) {
|
||||||
|
graphics::add_rule("rawphoto", $target, "rawphoto_graphics::convert", array(), 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static function deactivate() {
|
||||||
|
foreach (array("thumb", "resize") as $target) {
|
||||||
|
graphics::remove_rule("rawphoto", $target, "rawphoto_graphics::convert");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
3
3.0/modules/rawphoto/module.info
Normal file
3
3.0/modules/rawphoto/module.info
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
name = "Raw Photos"
|
||||||
|
description = "Use raw photos produced by a digital camera."
|
||||||
|
version = 1
|
42
3.0/modules/rawphoto/views/admin_rawphoto.html.php
Normal file
42
3.0/modules/rawphoto/views/admin_rawphoto.html.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?php defined("SYSPATH") or die("No direct script access.") ?>
|
||||||
|
<div id="g-rawphoto-admin">
|
||||||
|
<h2> <?= t("Raw Photos") ?> </h2>
|
||||||
|
<?= form::open("admin/rawphoto/saveprefs") ?>
|
||||||
|
<?= access::csrf_form_field() ?>
|
||||||
|
<p><?= t('<a href="%raw_url">Raw photo</a> processing depends on the ' .
|
||||||
|
'<a href="%dcraw_url">dcraw</a> 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/")) ?></p>
|
||||||
|
<fieldset>
|
||||||
|
<legend><?= t("Paths") ?></legend>
|
||||||
|
<? if ($dcraw->installed): ?>
|
||||||
|
<p><?= t("The dcraw tool was detected at <code>%path</code>.",
|
||||||
|
array("path" => $dcraw->path)) ?></p>
|
||||||
|
<? else: ?>
|
||||||
|
<p class="g-module-status g-error g-block"><?= $dcraw->error ?></p>
|
||||||
|
<? endif; ?>
|
||||||
|
<? if ($toolkit_name == "none"): ?>
|
||||||
|
<p class="g-module-status g-error g-block">
|
||||||
|
<?= t('No suitable graphics toolkit was detected. ' .
|
||||||
|
'Please <a href="%activate_url">activate</a> either ImageMagick or GraphicsMagick.',
|
||||||
|
array("activate_url" => url::site("admin/graphics"))) ?>
|
||||||
|
</p>
|
||||||
|
<? else: ?>
|
||||||
|
<p><?= t("The %toolkit_name graphics toolkit was detected.",
|
||||||
|
array("toolkit_name" => $toolkit_name)) ?></p>
|
||||||
|
<? endif; ?>
|
||||||
|
<? if (!empty($errors["IccPath"])): ?>
|
||||||
|
<p class="g-module-status g-error g-block"><?= $errors["IccPath"] ?></p>
|
||||||
|
<? endif; ?>
|
||||||
|
<?= form::label("IccPath", t('Path to <a href="%icc_url">ICC profile</a>', array("icc_url" =>
|
||||||
|
"http://www.permajet.com/30/Downloads/76/What_are_ICC_Profiles,_and_why_do_I_need_them.html"))) ?>
|
||||||
|
<?= form::input(array("name" => "IccPath", "id" => "IccPath"), $icc_path) ?>
|
||||||
|
<?if (empty($icc_path) || !empty($errors["IccPath"])): ?>
|
||||||
|
<em>An ICC profile is optional. If you don't know what it is, then you don't need it.</em>
|
||||||
|
<? endif; ?>
|
||||||
|
</fieldset>
|
||||||
|
<?= form::submit("SavePrefs", "Save") ?>
|
||||||
|
</form>
|
||||||
|
</div>
|
Reference in New Issue
Block a user