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);
?>