aboutsummaryrefslogtreecommitdiffstats
path: root/admin/derivatives.php
diff options
context:
space:
mode:
Diffstat (limited to 'admin/derivatives.php')
-rw-r--r--admin/derivatives.php97
1 files changed, 95 insertions, 2 deletions
diff --git a/admin/derivatives.php b/admin/derivatives.php
index fbf1ccffb..fde3e0db3 100644
--- a/admin/derivatives.php
+++ b/admin/derivatives.php
@@ -28,6 +28,7 @@ $errors = array();
if ( isset($_POST['d']) )
{
$pderivatives = $_POST['d'];
+ $pwatermark = $_POST['w'];
// step 1 - sanitize HTML input
foreach($pderivatives as $type => &$pderivative)
@@ -86,10 +87,55 @@ if ( isset($_POST['d']) )
$prev_w = intval($pderivative['w']);
$prev_h = intval($pderivative['h']);
}
+
+ $v = intval($pderivative['sharpen']);
+ if ($v<0 || $v>100)
+ {
+ $errors[$type]['sharpen'] = '[0..100]';
+ }
+ $v = intval($pderivative['quality']);
+ if ($v<=0 || $v>100)
+ {
+ $errors[$type]['quality'] = '(0..100]';
+ }
+ }
+ $v = intval($pwatermark['xpos']);
+ if ($v<0 || $v>100)
+ {
+ $errors['watermark']['xpos'] = '[0..100]';
}
+ $v = intval($pwatermark['ypos']);
+ if ($v<0 || $v>100)
+ {
+ $errors['watermark']['ypos'] = '[0..100]';
+ }
+ $v = intval($pwatermark['opacity']);
+ if ($v<=0 || $v>100)
+ {
+ $errors['watermark']['opacity'] = '(0..100]';
+ }
+
+
// step 3 - save data
if (count($errors)==0)
{
+ $watermark = new WatermarkParams();
+ $watermark->file = $pwatermark['file'];
+ $watermark->xpos = intval($pwatermark['xpos']);
+ $watermark->ypos = intval($pwatermark['ypos']);
+ $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->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)
@@ -106,11 +152,15 @@ if ( isset($_POST['d']) )
{
$new_params = new DerivativeParams(
new SizingParams(
- array($pderivative['w'],$pderivative['h']),
+ array(intval($pderivative['w']), intval($pderivative['h'])),
round($pderivative['crop'] / 100, 2),
- array($pderivative['minw'],$pderivative['minh'])
+ 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];
@@ -126,6 +176,22 @@ if ( isset($_POST['d']) )
{
$same = false;
}
+
+ 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 && $watermark_changed )
+ )
+ {
+ $same = false;
+ }
if (!$same)
{
@@ -182,6 +248,7 @@ if ( isset($_POST['d']) )
else
{
$template->assign('derivatives', $pderivatives);
+ $template->assign('watermark', $pwatermark);
$template->assign('ferrors', $errors);
}
}
@@ -224,11 +291,37 @@ if (count($errors)==0)
{
$tpl_var['minw'] = $tpl_var['minh'] = "";
}
+ $tpl_var['sharpen'] = $params->sharpen;
+ $tpl_var['quality'] = $params->quality;
}
$tpl_vars[$type]=$tpl_var;
}
$template->assign('derivatives', $tpl_vars);
+
+ $wm = ImageStdParams::get_watermark();
+ $template->assign('watermark', array(
+ 'file' => $wm->file,
+ 'minw' => $wm->min_size[0],
+ 'minh' => $wm->min_size[1],
+ 'xpos' => $wm->xpos,
+ 'ypos' => $wm->ypos,
+ 'xrepeat' => $wm->xrepeat,
+ 'opacity' => $wm->opacity,
+ ));
+}
+
+$watermark_files = array();
+foreach (glob(PHPWG_ROOT_PATH.'themes/default/watermarks/*.png') as $file)
+{
+ $watermark_files[] = substr($file, strlen(PHPWG_ROOT_PATH));
+}
+$watermark_filemap = array( '' => '---' );
+foreach( $watermark_files as $file)
+{
+ $display = basename($file);
+ $watermark_filemap[$file] = $display;
}
+$template->assign('watermark_files', $watermark_filemap);
$template->set_filename('derivatives', 'derivatives.tpl');
$template->assign_var_from_handle('ADMIN_CONTENT', 'derivatives');