Index: extensions/Ajax_Thumbnailer/main.inc.php
===================================================================
--- extensions/Ajax_Thumbnailer/main.inc.php (revision 4549)
+++ extensions/Ajax_Thumbnailer/main.inc.php (revision 10441)
@@ -9,152 +9,27 @@
*/
-ini_set('error_reporting', E_ALL);
-ini_set('display_errors', true);
-
if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
-class AjaxThumbnailer
+add_event_handler('ws_add_methods', 'add_thumbnail_create_method');
+
+function add_thumbnail_create_method($arr)
{
- /* This function is almost the same as the ont in admin/thumbnail.php , tuned
- for web-service purposes */
- function RatioResizeImg($path, $newWidth, $newHeight, $tn_ext,$gd_version=2) {
- global $conf, $lang, $page;
-
- $starttime = get_moment();
+ include_once('ws_functions.inc.php');
+}
- if (!function_exists('gd_info'))
- return new PwgError(WS_ERR_INVALID_PARAM, 'no gd');
+add_event_handler('loc_begin_admin', 'ajaxThumbnailer_admin_modify');
- if (!file_exists($path))
- return new PwgError(WS_ERR_INVALID_PARAM, 'file not found');
+function ajaxThumbnailer_admin_modify()
+{
+ global $page, $template;
- $filename = basename($path);
- $dirname = dirname($path);
+ if (isset($_GET['page']) and $_GET['page'] == 'thumbnail')
+ {
+ load_language('plugin.lang', dirname(__FILE__).'/');
+ $template->set_extent(dirname(__FILE__).'/AjaxThumbnailer.tpl', 'thumbnail');
+ }
+}
- // extension of the picture filename
- $extension = get_extension($filename);
-
- if (in_array($extension, array('jpg', 'JPG', 'jpeg', 'JPEG'))) {
- $srcImage = @imagecreatefromjpeg($path);
- }
- elseif ($extension == 'png' or $extension == 'PNG') {
- $srcImage = @imagecreatefrompng($path);
- } else {
- unset($extension);
- }
-
- if ( isset( $srcImage ) ) {
- // width/height
- $srcWidth = imagesx( $srcImage );
- $srcHeight = imagesy( $srcImage );
- $ratioWidth = $srcWidth/$newWidth;
- $ratioHeight = $srcHeight/$newHeight;
-
- // maximal size exceeded ?
- if ( ( $ratioWidth > 1 ) or ( $ratioHeight > 1 ) ) {
- if ( $ratioWidth < $ratioHeight) {
- $destWidth = $srcWidth/$ratioHeight;
- $destHeight = $newHeight;
- } else {
- $destWidth = $newWidth;
- $destHeight = $srcHeight/$ratioWidth;
- }
- } else {
- $destWidth = $srcWidth;
- $destHeight = $srcHeight;
- }
- // according to the GD version installed on the server
- if ( $gd_version == 2 ) {
- // GD 2.0 or more recent -> good results (but slower)
- $destImage = imagecreatetruecolor( $destWidth, $destHeight);
- imagecopyresampled( $destImage, $srcImage, 0, 0, 0, 0,
- $destWidth,$destHeight,$srcWidth,$srcHeight );
- } else {
- // GD prior to version 2 -> pretty bad results :-/ (but fast)
- $destImage = imagecreate( $destWidth, $destHeight);
- imagecopyresized( $destImage, $srcImage, 0, 0, 0, 0,
- $destWidth,$destHeight,$srcWidth,$srcHeight );
- }
-
- if (($tndir = mkget_thumbnail_dir($dirname)) == false) {
- return new PwgError(WS_ERR_INVALID_PARAM, '['.$tndir.'] : '.l10n('no_write_access'));
- }
-
- $dest_file = $tndir.'/'.$conf['prefix_thumbnail'];
- $dest_file.= get_filename_wo_extension($filename);
- $dest_file.= '.'.$tn_ext;
-
- // creation and backup of final picture
- if (!is_writable($tndir))
- return new PwgError(WS_ERR_INVALID_PARAM, '['.$tndir.'] : '.l10n('no_write_access'));
-
- imagejpeg($destImage, $dest_file, $conf['tn_compression_level']);
- // freeing memory ressources
- imagedestroy( $srcImage );
- imagedestroy( $destImage );
-
- list($tn_width, $tn_height) = getimagesize($dest_file);
- $tn_size = floor(filesize($dest_file) / 1024).' KB';
-
- $endtime = get_moment();
-
- $info = array( 'path' => $path,
- 'tn_file' => $dest_file,
- 'tn_width' => $tn_width,
- 'tn_height' => $tn_height,
- 'tn_size' => $tn_size,
- 'tn_time' => number_format(($endtime - $starttime) * 1000, 2, '.', ' ').' ms');
- return $info;
- } else {
- // error
- $err=l10n('tn_no_support');
- if ( isset( $extension ) )
- $err .= l10n('tn_format').' '.$extension;
- else
- $err .= l10n('tn_thisformat');
- return new PwgError(WS_ERR_INVALID_PARAM, $err);
- }
- }
-
- function plugin_admin_menu($menu) {
- array_push($menu,
- array(
- 'NAME' => 'Ajax Thumbnailer',
- 'URL' => get_admin_plugin_menu_link(dirname(__FILE__).'/admin/thumbnailer_admin.php')
- )
- );
- return $menu;
- }
-
- function ws_methods($arr) {
- $service = &$arr[0];
- $service->addMethod('pwg.thumbnail.create', array($this,'create_thumb'),
- array(
- 'picture'=>array(),
- 'width'=>array('default'=>"128"),
- 'height'=>array('default'=>"128"),
- 'ext'=>array('default'=>"jpg")
- ),
- 'Creates a thumbnail for a given image,
-
picture is the name of the picture to create thumbnail from.'
- );
-
- }
-
- function create_thumb($params, $service) {
- $picture = $params['picture'];
- $width = (integer)$params['width'];
- $height = (integer)$params['height'];
- $gd_version = (integer)$params['gd_version'];
- $ext =$params['ext'];
- return $this->RatioResizeImg($picture,$width,$height,$ext,$gd_version);
- }
-
-}
-$obj = new AjaxThumbnailer();
-
-add_event_handler('ws_add_methods', array(&$obj, 'ws_methods'));
-add_event_handler('get_admin_plugin_menu_links', array(&$obj, 'plugin_admin_menu') );
-set_plugin_data($plugin['id'], $obj);
+//add_event_handler('get_admin_plugin_menu_links', 'ajaxThumbnailer_admin_menu');
?>