本文整理匯總了PHP中WideImage_Image::doCreate方法的典型用法代碼示例。如果您正苦於以下問題:PHP WideImage_Image::doCreate方法的具體用法?PHP WideImage_Image::doCreate怎麽用?PHP WideImage_Image::doCreate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類WideImage_Image
的用法示例。
在下文中一共展示了WideImage_Image::doCreate方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: execute
/**
* Returns a cropped image
*
* @param WideImage_Image $img
* @param smart_coordinate $left
* @param smart_coordinate $top
* @param smart_coordinate $width
* @param smart_coordinate $height
* @return WideImage_Image
*/
function execute($img, $left, $top, $width, $height)
{
$width = WideImage_Coordinate::fix($width, $img->getWidth(), $width);
$height = WideImage_Coordinate::fix($height, $img->getHeight(), $height);
$left = WideImage_Coordinate::fix($left, $img->getWidth(), $width);
$top = WideImage_Coordinate::fix($top, $img->getHeight(), $height);
if ($left < 0) {
$width = $left + $width;
$left = 0;
}
if ($width > $img->getWidth() - $left) {
$width = $img->getWidth() - $left;
}
if ($top < 0) {
$height = $top + $height;
$top = 0;
}
if ($height > $img->getHeight() - $top) {
$height = $img->getHeight() - $top;
}
if ($width <= 0 || $height <= 0) {
throw new WideImage_Exception("Can't crop outside of an image.");
}
$new = $img->doCreate($width, $height);
if ($img->isTransparent() || $img instanceof WideImage_PaletteImage) {
$new->copyTransparencyFrom($img);
imagecopyresized($new->getHandle(), $img->getHandle(), 0, 0, $left, $top, $width, $height, $width, $height);
} else {
$new->alphaBlending(false);
$new->saveAlpha(true);
imagecopyresampled($new->getHandle(), $img->getHandle(), 0, 0, $left, $top, $width, $height, $width, $height);
}
return $new;
}