本文整理汇总了PHP中Intervention\Image\Image::resizeCanvas方法的典型用法代码示例。如果您正苦于以下问题:PHP Image::resizeCanvas方法的具体用法?PHP Image::resizeCanvas怎么用?PHP Image::resizeCanvas使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Intervention\Image\Image
的用法示例。
在下文中一共展示了Image::resizeCanvas方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fit
protected function fit()
{
if ($this->width !== null || $this->height !== null) {
if ($this->fit === self::FIT_CROP && $this->width && $this->height) {
$this->image->fit($this->width, $this->height, function ($constraint) {
/* @var $constraint \Intervention\Image\Constraint */
$constraint->aspectRatio();
});
return;
}
if ($this->fit === self::FIT_MIN || $this->fit === self::FIT_MAX) {
if ($this->fit === self::FIT_MAX) {
$this->image->resize($this->width, $this->height, function ($constraint) {
/* @var $constraint \Intervention\Image\Constraint */
$constraint->aspectRatio();
$constraint->upsize();
});
$this->image->resizeCanvas($this->width, $this->height, 'top-left');
}
if ($this->fit === self::FIT_MIN) {
$height = $this->image->getHeight() < $this->height ? $this->image->getHeight() : $this->height;
$width = $this->image->getWidth() < $this->width ? $this->image->getWidth() : $this->width;
$this->image->fit($width, $height, function ($constraint) {
/* @var $constraint \Intervention\Image\Constraint */
$constraint->aspectRatio();
$constraint->upsize();
});
}
return;
}
if ($this->fit === self::FIT_CLIP) {
$this->image->resize($this->width, $this->height, function ($constraint) {
/* @var $constraint \Intervention\Image\Constraint */
$constraint->aspectRatio();
$constraint->upsize();
});
return;
}
if ($this->fit === self::FIT_SCALE) {
$this->image->resize($this->width, $this->height);
return;
}
if ($this->fit === self::FIT_CLAMP) {
$this->image->resize($this->width, $this->height, function ($constraint) {
/* @var $constraint \Intervention\Image\Constraint */
$constraint->aspectRatio();
});
}
}
}
示例2: testResizeCanvas
public function testResizeCanvas()
{
$img = $this->getTestImage();
$img->resizeCanvas(300, 200);
// pin center
$this->assertInstanceOf('Intervention\\Image\\Image', $img);
$this->assertInternalType('int', $img->width);
$this->assertInternalType('int', $img->height);
$this->assertEquals($img->width, 300);
$this->assertEquals($img->height, 200);
$this->assertEquals('#ffe8bc', $img->pickColor(0, 0, 'hex'));
$this->assertEquals('#ffaf1c', $img->pickColor(299, 199, 'hex'));
$img = $this->getTestImage();
$img->resizeCanvas(300, 200, 'top-left');
$this->assertInstanceOf('Intervention\\Image\\Image', $img);
$this->assertInternalType('int', $img->width);
$this->assertInternalType('int', $img->height);
$this->assertEquals($img->width, 300);
$this->assertEquals($img->height, 200);
$this->assertEquals('#ffffff', $img->pickColor(0, 0, 'hex'));
$this->assertEquals('#fee3ae', $img->pickColor(299, 199, 'hex'));
$img = $this->getTestImage();
$img->resizeCanvas(300, 200, 'top');
$this->assertInstanceOf('Intervention\\Image\\Image', $img);
$this->assertInternalType('int', $img->width);
$this->assertInternalType('int', $img->height);
$this->assertEquals($img->width, 300);
$this->assertEquals($img->height, 200);
$this->assertEquals('#fffbf2', $img->pickColor(0, 0, 'hex'));
$this->assertEquals('#ffc559', $img->pickColor(299, 199, 'hex'));
$img = $this->getTestImage();
$img->resizeCanvas(300, 200, 'top-right');
$this->assertInstanceOf('Intervention\\Image\\Image', $img);
$this->assertInternalType('int', $img->width);
$this->assertInternalType('int', $img->height);
$this->assertEquals($img->width, 300);
$this->assertEquals($img->height, 200);
$this->assertEquals('#ffe2ae', $img->pickColor(0, 0, 'hex'));
$this->assertEquals('#ffac12', $img->pickColor(299, 199, 'hex'));
$img = $this->getTestImage();
$img->resizeCanvas(300, 200, 'left');
$this->assertInstanceOf('Intervention\\Image\\Image', $img);
$this->assertInternalType('int', $img->width);
$this->assertInternalType('int', $img->height);
$this->assertEquals($img->width, 300);
$this->assertEquals($img->height, 200);
$this->assertEquals('#fefdf9', $img->pickColor(0, 0, 'hex'));
$this->assertEquals('#ffca6a', $img->pickColor(299, 199, 'hex'));
$img = $this->getTestImage();
$img->resizeCanvas(300, 200, 'right');
$this->assertInstanceOf('Intervention\\Image\\Image', $img);
$this->assertInternalType('int', $img->width);
$this->assertInternalType('int', $img->height);
$this->assertEquals($img->width, 300);
$this->assertEquals($img->height, 200);
$this->assertEquals('#ffca66', $img->pickColor(0, 0, 'hex'));
$this->assertEquals('#ffa600', $img->pickColor(299, 199, 'hex'));
$img = $this->getTestImage();
$img->resizeCanvas(300, 200, 'bottom-left');
$this->assertInstanceOf('Intervention\\Image\\Image', $img);
$this->assertInternalType('int', $img->width);
$this->assertInternalType('int', $img->height);
$this->assertEquals($img->width, 300);
$this->assertEquals($img->height, 200);
$this->assertEquals('#ffedcc', $img->pickColor(0, 0, 'hex'));
$this->assertEquals('#ffb42b', $img->pickColor(299, 199, 'hex'));
$img = $this->getTestImage();
$img->resizeCanvas(300, 200, 'bottom');
$this->assertInstanceOf('Intervention\\Image\\Image', $img);
$this->assertInternalType('int', $img->width);
$this->assertInternalType('int', $img->height);
$this->assertEquals($img->width, 300);
$this->assertEquals($img->height, 200);
$this->assertEquals('#ffd179', $img->pickColor(0, 0, 'hex'));
$this->assertEquals('#ffa600', $img->pickColor(299, 199, 'hex'));
$img = $this->getTestImage();
$img->resizeCanvas(300, 200, 'bottom-right');
$this->assertInstanceOf('Intervention\\Image\\Image', $img);
$this->assertInternalType('int', $img->width);
$this->assertInternalType('int', $img->height);
$this->assertEquals($img->width, 300);
$this->assertEquals($img->height, 200);
$this->assertEquals('#ffb42a', $img->pickColor(0, 0, 'hex'));
$this->assertEquals('#ffa600', $img->pickColor(299, 199, 'hex'));
// resize relative from center 5px border in magenta
$img = $this->getTestImage();
$img->resizeCanvas(10, 10, 'center', true, 'ff00ff');
$this->assertInstanceOf('Intervention\\Image\\Image', $img);
$this->assertInternalType('int', $img->width);
$this->assertInternalType('int', $img->height);
$this->assertEquals($img->width, 810);
$this->assertEquals($img->height, 610);
$this->assertEquals('#ff00ff', $img->pickColor(0, 0, 'hex'));
$this->assertEquals('#ff00ff', $img->pickColor(809, 609, 'hex'));
// resize just width
$img = $this->getTestImage();
$img->resizeCanvas(300, null);
$this->assertInstanceOf('Intervention\\Image\\Image', $img);
$this->assertInternalType('int', $img->width);
$this->assertInternalType('int', $img->height);
//.........这里部分代码省略.........
示例3: runExpand
public function runExpand(Image $image, $width, $color)
{
return $image->resizeCanvas($width * 2, $width * 2, 'center', true, $color);
}
示例4: resizeCanvas
/**
* Resize image canvas
*
* @param int $width
* @param int $height
* @param string $anchor
* @param boolean $relative
* @param mixed $bgcolor
* @return \Intervention\Image\Image
* @static
*/
public static function resizeCanvas($width, $height, $anchor = null, $relative = false, $bgcolor = null)
{
return \Intervention\Image\Image::resizeCanvas($width, $height, $anchor, $relative, $bgcolor);
}
示例5: original
static function original(\Intervention\Image\Image $img, $w, $h)
{
$max = max($w, $h);
return $img->resizeCanvas($max * 2, $max * 2);
}