Skip to content

Commit

Permalink
Add triggers for image and thumbnail resizing.
Browse files Browse the repository at this point in the history
git-svn-id: http://piwigo.org/svn/trunk@5957 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
patdenice committed Apr 24, 2010
1 parent 9ffeaaf commit 8a1b7a4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
18 changes: 15 additions & 3 deletions admin/include/functions_upload.inc.php
Expand Up @@ -17,6 +17,10 @@
//
// 4) register in database

// add default event handler for image and thumbnail resize
add_event_handler('upload_image_resize', 'pwg_image_resize', EVENT_HANDLER_PRIORITY_NEUTRAL, 6);
add_event_handler('upload_thumbnail_resize', 'pwg_image_resize', EVENT_HANDLER_PRIORITY_NEUTRAL, 6);

function add_uploaded_file($source_filepath, $original_filename=null, $categories=null, $level=null)
{
global $conf;
Expand Down Expand Up @@ -60,7 +64,8 @@ function add_uploaded_file($source_filepath, $original_filename=null, $categorie
rename($file_path, $high_path);
$high_infos = pwg_image_infos($high_path);

pwg_image_resize(
trigger_event('upload_image_resize',
false,
$high_path,
$file_path,
$conf['upload_form_websize_maxwidth'],
Expand All @@ -75,7 +80,8 @@ function add_uploaded_file($source_filepath, $original_filename=null, $categorie
$thumb_dir = dirname($thumb_path);
prepare_directory($thumb_dir);

pwg_image_resize(
trigger_event('upload_thumbnail_resize',
false,
$file_path,
$thumb_path,
$conf['upload_form_thumb_maxwidth'],
Expand Down Expand Up @@ -169,8 +175,14 @@ function need_resize($image_filepath, $max_width, $max_height)
return false;
}

function pwg_image_resize($source_filepath, $destination_filepath, $max_width, $max_height, $quality)
function pwg_image_resize($result, $source_filepath, $destination_filepath, $max_width, $max_height, $quality)
{
if ($result !== false)
{
//someone hooked us - so we skip
return $result;
}

if (!function_exists('gd_info'))
{
return false;
Expand Down
20 changes: 18 additions & 2 deletions admin/thumbnail.php
Expand Up @@ -32,10 +32,16 @@
// RatioResizeImg creates a new picture (a thumbnail since it is supposed to
// be smaller than original picture !) in the sub directory named
// "thumbnail".
function RatioResizeImg($path, $newWidth, $newHeight, $tn_ext)
function RatioResizeImg($info, $path, $newWidth, $newHeight, $tn_ext)
{
global $conf, $lang, $page;

if ($info !== false)
{
//someone hooked us - so we skip
return $info;
}

if (!function_exists('gd_info'))
{
return;
Expand Down Expand Up @@ -157,6 +163,9 @@ function RatioResizeImg($path, $newWidth, $newHeight, $tn_ext)
array_push($page['errors'], l10n('GD library is missing'));
}

// add default event handler for thumbnail resize
add_event_handler('thumbnail_resize', 'RatioResizeImg', EVENT_HANDLER_PRIORITY_NEUTRAL, 5);

// +-----------------------------------------------------------------------+
// | template initialization |
// +-----------------------------------------------------------------------+
Expand Down Expand Up @@ -251,7 +260,14 @@ function RatioResizeImg($path, $newWidth, $newHeight, $tn_ext)
}

$starttime = get_moment();
if ($info = RatioResizeImg($path,$_POST['width'],$_POST['height'],'jpg'))
if ($info = trigger_event('thumbnail_resize',
false,
$path,
$_POST['width'],
$_POST['height'],
'jpg'
)
)
{
$endtime = get_moment();
$info['time'] = ($endtime - $starttime) * 1000;
Expand Down

0 comments on commit 8a1b7a4

Please sign in to comment.