当前位置: 首页>>代码示例>>PHP>>正文


PHP Image::resizeCanvas方法代码示例

本文整理汇总了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();
             });
         }
     }
 }
开发者ID:Monori,项目名称:imgback,代码行数:50,代码来源:ImageHandler.php

示例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);
//.........这里部分代码省略.........
开发者ID:Vrian7ipx,项目名称:repocas,代码行数:101,代码来源:ImageTest.php

示例3: runExpand

 public function runExpand(Image $image, $width, $color)
 {
     return $image->resizeCanvas($width * 2, $width * 2, 'center', true, $color);
 }
开发者ID:placers,项目名称:imgproxy,代码行数:4,代码来源:Border.php

示例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);
 }
开发者ID:jorzhikgit,项目名称:MLM-Nexus,代码行数:15,代码来源:_ide_helper.php

示例5: original

 static function original(\Intervention\Image\Image $img, $w, $h)
 {
     $max = max($w, $h);
     return $img->resizeCanvas($max * 2, $max * 2);
 }
开发者ID:larakit,项目名称:lk,代码行数:5,代码来源:HelperImage.php


注:本文中的Intervention\Image\Image::resizeCanvas方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。