本文整理汇总了PHP中sfImage::create方法的典型用法代码示例。如果您正苦于以下问题:PHP sfImage::create方法的具体用法?PHP sfImage::create怎么用?PHP sfImage::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfImage
的用法示例。
在下文中一共展示了sfImage::create方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: transform
/**
* Apply the transformation to the image and returns the image thumbnail
*/
protected function transform(sfImage $image)
{
$resource_w = $image->getWidth();
$resource_h = $image->getHeight();
$scale_w = $this->getWidth() / $resource_w;
$scale_h = $this->getHeight() / $resource_h;
switch ($this->getMethod()) {
case 'deflate':
case 'inflate':
return $image->resize($this->getWidth(), $this->getHeight());
case 'left':
$image->scale(max($scale_w, $scale_h));
return $image->crop(0, (int) round(($image->getHeight() - $this->getHeight()) / 2), $this->getWidth(), $this->getHeight());
case 'right':
$image->scale(max($scale_w, $scale_h));
return $image->crop($image->getWidth() - $this->getWidth(), (int) round(($image->getHeight() - $this->getHeight()) / 2), $this->getWidth(), $this->getHeight());
case 'top':
$image->scale(max($scale_w, $scale_h));
return $image->crop((int) round(($image->getWidth() - $this->getWidth()) / 2), 0, $this->getWidth(), $this->getHeight());
case 'bottom':
$image->scale(max($scale_w, $scale_h));
return $image->crop((int) round(($image->getWidth() - $this->getWidth()) / 2), $image->getHeight() - $this->getHeight(), $this->getWidth(), $this->getHeight());
case 'center':
$image->scale(max($scale_w, $scale_h));
$left = (int) round(($image->getWidth() - $this->getWidth()) / 2);
$top = (int) round(($image->getHeight() - $this->getHeight()) / 2);
return $image->crop($left, $top, $this->getWidth(), $this->getHeight());
case 'scale':
return $image->scale(min($scale_w, $scale_h));
case 'fit':
default:
$img = clone $image;
$image->create($this->getWidth(), $this->getHeight());
// Set a background color if specified
if (!is_null($this->getBackground()) && $this->getBackground() != '') {
$image->fill(0, 0, $this->getBackground());
}
$img->scale(min($this->getWidth() / $img->getWidth(), $this->getHeight() / $img->getHeight()));
$image->overlay($img, 'center');
return $image;
}
}