aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2012-02-05 14:58:14 +0000
committerrvelices <rv-github@modusoptimus.com>2012-02-05 14:58:14 +0000
commit8d86e7b399fbda576306453c332cd9daeb44bdde (patch)
tree4288b52b6052b9aeed9704e3ed12f12426c187d8
parentcb36388114b6d7b35a71243c5ad23854da12fe33 (diff)
multisize
- watermarks loaded also from local dir - fix/simplify algo for cropping - imagick use scaleImage (fast) before resizeImage (slow) if the original is a lot bigger than the requested size git-svn-id: http://piwigo.org/svn/trunk@13035 68402e56-0260-453c-a942-63ccdbb3a9ee
-rw-r--r--admin/derivatives.php42
-rw-r--r--admin/include/image.class.php5
-rw-r--r--include/derivative_params.inc.php36
3 files changed, 38 insertions, 45 deletions
diff --git a/admin/derivatives.php b/admin/derivatives.php
index a40e3f3c3..556ff7fec 100644
--- a/admin/derivatives.php
+++ b/admin/derivatives.php
@@ -67,7 +67,7 @@ if ( isset($_POST['d']) )
{
$errors[$type]['crop'] = '[0..100]';
}
-
+
if ($v!=0)
{
$v = intval($pderivative['minw']);
@@ -81,13 +81,13 @@ if ( isset($_POST['d']) )
$errors[$type]['minh'] = '[0..'.intval($pderivative['h']).']';
}
}
-
+
if (count($errors)==0)
{
$prev_w = intval($pderivative['w']);
$prev_h = intval($pderivative['h']);
}
-
+
$v = intval($pderivative['sharpen']);
if ($v<0 || $v>100)
{
@@ -126,16 +126,16 @@ if ( isset($_POST['d']) )
$watermark->xrepeat = intval($pwatermark['xrepeat']);
$watermark->opacity = intval($pwatermark['opacity']);
$watermark->min_size = array(intval($pwatermark['minw']),intval($pwatermark['minh']));
-
+
$old_watermark = ImageStdParams::get_watermark();
- $watermark_changed =
+ $watermark_changed =
$watermark->file != $old_watermark->file
|| $watermark->xpos != $old_watermark->xpos
|| $watermark->ypos != $old_watermark->ypos
|| $watermark->xrepeat != $old_watermark->xrepeat
|| $watermark->opacity != $old_watermark->opacity;
ImageStdParams::set_watermark($watermark);
-
+
$enabled = ImageStdParams::get_defined_type_map();
$disabled = @unserialize( @$conf['disabled_derivatives'] );
if ($disabled===false)
@@ -143,24 +143,24 @@ if ( isset($_POST['d']) )
$disabled = array();
}
$changed_types = array();
-
+
foreach(ImageStdParams::get_all_types() as $type)
{
$pderivative = $pderivatives[$type];
-
+
if ($pderivative['enabled'])
{
$new_params = new DerivativeParams(
- new SizingParams(
+ new SizingParams(
array(intval($pderivative['w']), intval($pderivative['h'])),
round($pderivative['crop'] / 100, 2),
array(intval($pderivative['minw']), intval($pderivative['minh']))
- )
+ )
);
$new_params->sharpen = intval($pderivative['sharpen']);
$new_params->quality = intval($pderivative['quality']);
ImageStdParams::apply_global($new_params);
-
+
if (isset($enabled[$type]))
{
$old_params = $enabled[$type];
@@ -171,28 +171,28 @@ if ( isset($_POST['d']) )
$same = false;
}
- if ( $same && $new_params->sizing->max_crop != 0
+ if ( $same && $new_params->sizing->max_crop != 0
&& !size_equals($old_params->sizing->min_size, $new_params->sizing->min_size) )
{
$same = false;
}
- if ( $same &&
+ if ( $same &&
( $new_params->sharpen != $old_params->sharpen
|| $new_params->quality > $old_params->quality)
)
{
$same = false;
}
-
+
if ($same &&
- ( $new_params->use_watermark != $old_params->use_watermark
+ ( $new_params->use_watermark != $old_params->use_watermark
|| $new_params->use_watermark && $watermark_changed )
)
{
$same = false;
}
-
+
if (!$same)
{
$new_params->last_mod_time = time();
@@ -228,7 +228,7 @@ if ( isset($_POST['d']) )
{
$enabled_by[$type] = $enabled[$type];
}
- }
+ }
ImageStdParams::set_and_save($enabled_by);
if (count($disabled)==0)
{
@@ -240,7 +240,7 @@ if ( isset($_POST['d']) )
conf_update_param('disabled_derivatives', addslashes(serialize($disabled)) );
}
$conf['disabled_derivatives']=serialize($disabled);
-
+
if (count($changed_types))
{
clear_derivative_cache($changed_types);
@@ -298,7 +298,7 @@ if (count($errors)==0)
$tpl_vars[$type]=$tpl_var;
}
$template->assign('derivatives', $tpl_vars);
-
+
$wm = ImageStdParams::get_watermark();
$template->assign('watermark', array(
'file' => $wm->file,
@@ -316,6 +316,10 @@ foreach (glob(PHPWG_ROOT_PATH.'themes/default/watermarks/*.png') as $file)
{
$watermark_files[] = substr($file, strlen(PHPWG_ROOT_PATH));
}
+foreach (glob(PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'watermarks/*.png') as $file)
+{
+ $watermark_files[] = substr($file, strlen(PHPWG_ROOT_PATH));
+}
$watermark_filemap = array( '' => '---' );
foreach( $watermark_files as $file)
{
diff --git a/admin/include/image.class.php b/admin/include/image.class.php
index 19b936afc..86ef35a69 100644
--- a/admin/include/image.class.php
+++ b/admin/include/image.class.php
@@ -423,6 +423,11 @@ class image_imagick implements imageInterface
function resize($width, $height)
{
$this->image->setInterlaceScheme(Imagick::INTERLACE_LINE);
+ if ($this->get_width()%2 == 0 && $this->get_height()%2 == 0
+ && $this->get_width() > 3*$width)
+ {
+ $this->image->scaleImage($this->get_width()/2, $this->get_height()/2);
+ }
return $this->image->resizeImage($width, $height, Imagick::FILTER_LANCZOS, 0.9);
}
diff --git a/include/derivative_params.inc.php b/include/derivative_params.inc.php
index ba1b1dce7..15c78c9aa 100644
--- a/include/derivative_params.inc.php
+++ b/include/derivative_params.inc.php
@@ -70,7 +70,7 @@ final class ImageRect
return $this->b - $this->t;
}
- function crop_h($pixels, $coi, $force)
+ function crop_h($pixels, $coi)
{
if ($this->width() <= $pixels)
return;
@@ -82,15 +82,7 @@ final class ImageRect
$coir = ceil($this->r * char_to_fraction($coi[2]));
$availableL = $coil > $this->l ? $coil - $this->l : 0;
$availableR = $coir < $this->r ? $this->r - $coir : 0;
- if ($availableL + $availableR <= $pixels)
- {
- if (!$force)
- {
- $pixels = $availableL + $availableR;
- $tlcrop = $availableL;
- }
- }
- else
+ if ($availableL + $availableR >= $pixels)
{
if ($availableL < $tlcrop)
{
@@ -106,7 +98,7 @@ final class ImageRect
$this->r -= $pixels - $tlcrop;
}
- function crop_v($pixels, $coi, $force)
+ function crop_v($pixels, $coi)
{
if ($this->height() <= $pixels)
return;
@@ -118,15 +110,7 @@ final class ImageRect
$coib = ceil($this->b * char_to_fraction($coi[3]));
$availableT = $coit > $this->t ? $coit - $this->t : 0;
$availableB = $coib < $this->b ? $this->b - $coib : 0;
- if ($availableT + $availableB <= $pixels)
- {
- if (!$force)
- {
- $pixels = $availableT + $availableB;
- $tlcrop = $availableT;
- }
- }
- else
+ if ($availableT + $availableB >= $pixels)
{
if ($availableT < $tlcrop)
{
@@ -198,9 +182,9 @@ final class SizingParams
$h = $destCrop->height() / $ratio_w;
if ($h < $this->min_size[1])
{
- $idealCropPx = $destCrop->width() - round($destCrop->height() * $this->ideal_size[0] / $this->min_size[1], 0);
+ $idealCropPx = $destCrop->width() - floor($destCrop->height() * $this->ideal_size[0] / $this->min_size[1]);
$maxCropPx = round($this->max_crop * $destCrop->width());
- $destCrop->crop_h( min($idealCropPx, $maxCropPx), $coi, false);
+ $destCrop->crop_h( min($idealCropPx, $maxCropPx), $coi);
}
}
else
@@ -208,9 +192,9 @@ final class SizingParams
$w = $destCrop->width() / $ratio_h;
if ($w < $this->min_size[0])
{
- $idealCropPx = $destCrop->height() - round($destCrop->width() * $this->ideal_size[1] / $this->min_size[0], 0);
+ $idealCropPx = $destCrop->height() - floor($destCrop->width() * $this->ideal_size[1] / $this->min_size[0]);
$maxCropPx = round($this->max_crop * $destCrop->height());
- $destCrop->crop_v( min($idealCropPx, $maxCropPx), $coi, false);
+ $destCrop->crop_v( min($idealCropPx, $maxCropPx), $coi);
}
}
}
@@ -267,7 +251,7 @@ final class DerivativeParams
{
return array('last_mod_time', 'sizing', 'sharpen', 'quality');
}
-
+
function add_url_tokens(&$tokens)
{
$this->sizing->add_url_tokens($tokens);
@@ -288,7 +272,7 @@ final class DerivativeParams
{
return $this->sizing->ideal_size[1];
}
-
+
function is_identity($in_size)
{
if ($in_size[0] > $this->sizing->ideal_size[0] or