source: extensions/regenerateWebsize/ws_functions.inc.php @ 10358

Revision 10358, 1.8 KB checked in by patdenice, 9 years ago (diff)

Add Websize Renegeration plugin.

Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5global $conf;
6
7$service = &$arr[0];
8$service->addMethod(
9  'pwg.images.regenerateWebsize',
10  'ws_images_regenerateWebsize',
11  array(
12    'image_id'  => array(),
13    'maxwidth'  => array('default'=>$conf['upload_form_websize_maxwidth']),
14    'maxheight' => array('default'=>$conf['upload_form_websize_maxheight']),
15    'quality'   => array('default'=>$conf['upload_form_websize_quality']),
16  ),
17  'Regenerate websize images from HD with given arguments.'
18);
19
20function ws_images_regenerateWebsize($params, &$service)
21{
22  global $conf;
23
24  if (!is_admin())
25    return new PwgError(401, 'Access denied');
26
27  $query='
28SELECT id, path, has_high, width, height
29FROM '.IMAGES_TABLE.'
30WHERE id = '.(int)$params['image_id'].'
31;';
32
33  $image = pwg_db_fetch_assoc(pwg_query($query));
34  if ($image == null)
35    return new PwgError(404, "image_id not found");
36
37  include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
38
39  if (!empty( $image['has_high'] ))
40  {
41    trigger_event(
42      'upload_image_resize',
43      false,
44      file_path_for_type($image['path'], 'high'),
45      $image['path'],
46      $params['maxwidth'],
47      $params['maxheight'],
48      $params['quality'],
49      true
50      );
51
52    return true;
53  }
54  /*
55  elseif (!empty($image['width']) and !empty($image['height'])
56    and ($image['width'] > $params['maxwidth'] or $image['height'] > $params['maxheight']))
57  {
58    trigger_event(
59      'upload_image_resize',
60      false,
61      $image['path'],
62      $image['path'],
63      min($params['maxwidth'], $image['width']),
64      min($params['maxheight'], $image['height']),
65      $params['quality'],
66      true
67      );
68
69    return true;
70  }
71  */
72  return false;
73}
74
75?>
Note: See TracBrowser for help on using the repository browser.