當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。