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


PHP Image::canvas方法代码示例

本文整理汇总了PHP中Intervention\Image\Image::canvas方法的典型用法代码示例。如果您正苦于以下问题:PHP Image::canvas方法的具体用法?PHP Image::canvas怎么用?PHP Image::canvas使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Intervention\Image\Image的用法示例。


在下文中一共展示了Image::canvas方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: generate

 public function generate($filename, $sex = null, $all = false)
 {
     $parts = array('background', 'face', 'clothes', 'hair', 'eyes', 'mouth');
     if (!in_array($sex, array('male', 'female'))) {
         $sex = 1 === mt_rand(1, 2) ? 'male' : 'female';
     }
     $img = \Intervention\Image\Image::canvas($this->size, $this->size);
     foreach ($parts as $part) {
         $images = glob(__DIR__ . '/img/' . $sex . '/' . $part . '/*.{jpg,jpeg,png,gif}', GLOB_BRACE);
         if (!$all) {
             $images = array_filter($images, function ($image) {
                 $path_parts = pathinfo($image);
                 return false === stristr($path_parts['filename'], 'all-');
             });
         }
         $img->insert($images[array_rand($images)]);
     }
     $img->save($filename);
 }
开发者ID:vantoozz,项目名称:biticon,代码行数:19,代码来源:Biticon.php

示例2: testTrimWithTolerance

 public function testTrimWithTolerance()
 {
     // prepare test image
     $canvas = Image::canvas(1, 1, '000000');
     $canvas->resizeCanvas(5, 5, 'center', false, '808080');
     $canvas->resizeCanvas(11, 11, 'center', false, 'ffffff');
     $this->assertEquals($canvas->width, 11);
     $this->assertEquals($canvas->height, 11);
     $this->assertEquals('#000000', $canvas->pickColor(5, 5, 'hex'));
     $this->assertEquals('#808080', $canvas->pickColor(3, 3, 'hex'));
     $this->assertEquals('#ffffff', $canvas->pickColor(0, 0, 'hex'));
     $img = clone $canvas;
     $img->trim();
     // trim without tolerance (should trim away ffffff)
     $this->assertEquals($img->width, 5);
     $this->assertEquals($img->height, 5);
     $this->assertEquals('#000000', $img->pickColor(2, 2, 'hex'));
     $this->assertEquals('#808080', $img->pickColor(0, 0, 'hex'));
     $img = clone $canvas;
     $img->trim(null, null, 30);
     // trim with 40 tolerance (should not touch 808080)
     $this->assertEquals($img->width, 5);
     $this->assertEquals($img->height, 5);
     $this->assertEquals('#000000', $img->pickColor(2, 2, 'hex'));
     $this->assertEquals('#808080', $img->pickColor(0, 0, 'hex'));
     $img = clone $canvas;
     $img->trim(null, null, 50);
     // trim with 50 tolerance (should only leave 000000)
     $this->assertEquals($img->width, 1);
     $this->assertEquals($img->height, 1);
     $this->assertEquals('#000000', $img->pickColor(0, 0, 'hex'));
     $img = clone $canvas;
     $img->trim(null, null, 100);
     // trim with 100 tolerance (should leave image as is)
     $this->assertEquals($img->width, 11);
     $this->assertEquals($img->height, 11);
     $this->assertEquals('#000000', $img->pickColor(5, 5, 'hex'));
     $this->assertEquals('#808080', $img->pickColor(3, 3, 'hex'));
     $this->assertEquals('#ffffff', $img->pickColor(0, 0, 'hex'));
     // prepare test image
     $canvas = Image::canvas(1, 1, '000000');
     $canvas->resizeCanvas(5, 5, 'center', false, '804040');
     $canvas->resizeCanvas(11, 11, 'center', false, 'ffffff');
     $this->assertEquals($canvas->width, 11);
     $this->assertEquals($canvas->height, 11);
     $this->assertEquals('#000000', $canvas->pickColor(5, 5, 'hex'));
     $this->assertEquals('#804040', $canvas->pickColor(3, 3, 'hex'));
     $this->assertEquals('#ffffff', $canvas->pickColor(0, 0, 'hex'));
     $img = clone $canvas;
     $img->trim();
     // trim without tolerance (should trim away ffffff)
     $this->assertEquals($img->width, 5);
     $this->assertEquals($img->height, 5);
     $this->assertEquals('#000000', $img->pickColor(2, 2, 'hex'));
     $this->assertEquals('#804040', $img->pickColor(0, 0, 'hex'));
     $img = clone $canvas;
     $img->trim(null, null, 30);
     // trim with 40 tolerance (should not touch 804040)
     $this->assertEquals($img->width, 5);
     $this->assertEquals($img->height, 5);
     $this->assertEquals('#000000', $img->pickColor(2, 2, 'hex'));
     $this->assertEquals('#804040', $img->pickColor(0, 0, 'hex'));
     $img = clone $canvas;
     $img->trim(null, null, 50);
     // trim with 50 tolerance (should not touch 804040)
     $this->assertEquals($img->width, 5);
     $this->assertEquals($img->height, 5);
     $this->assertEquals('#000000', $img->pickColor(2, 2, 'hex'));
     $this->assertEquals('#804040', $img->pickColor(0, 0, 'hex'));
     $img = clone $canvas;
     $img->trim(null, null, 80);
     // trim with 80 tolerance (should only leave 000000)
     $this->assertEquals($img->width, 1);
     $this->assertEquals($img->height, 1);
     $this->assertEquals('#000000', $img->pickColor(0, 0, 'hex'));
     $img = clone $canvas;
     $img->trim(null, null, 100);
     // trim with 100 tolerance (should leave image as is)
     $this->assertEquals($img->width, 11);
     $this->assertEquals($img->height, 11);
     $this->assertEquals('#000000', $img->pickColor(5, 5, 'hex'));
     $this->assertEquals('#804040', $img->pickColor(3, 3, 'hex'));
     $this->assertEquals('#ffffff', $img->pickColor(0, 0, 'hex'));
     // prepare test image
     $canvas = Image::canvas(1, 1, 'ffffff');
     // core
     $canvas->resizeCanvas(5, 5, 'center', false, 'd90000');
     // 85%
     $canvas->resizeCanvas(11, 11, 'center', false, '008000');
     // 50%
     $canvas->resizeCanvas(16, 16, 'center', false, '333333');
     // 20%
     $canvas->resizeCanvas(20, 20, 'center', false, '000000');
     // outer
     $this->assertEquals($canvas->width, 20);
     $this->assertEquals($canvas->height, 20);
     $this->assertEquals('#ffffff', $canvas->pickColor(9, 9, 'hex'));
     $this->assertEquals('#d90000', $canvas->pickColor(7, 7, 'hex'));
     $this->assertEquals('#008000', $canvas->pickColor(4, 4, 'hex'));
     $this->assertEquals('#333333', $canvas->pickColor(2, 2, 'hex'));
//.........这里部分代码省略.........
开发者ID:Vrian7ipx,项目名称:repocas,代码行数:101,代码来源:ImageTest.php

示例3: canvas

 /**
  * Create a new empty image resource
  *
  * @param int $width
  * @param int $height
  * @param mixed $bgcolor
  * @return \Intervention\Image\Image 
  * @static 
  */
 public static function canvas($width, $height, $bgcolor = null)
 {
     return \Intervention\Image\Image::canvas($width, $height, $bgcolor);
 }
开发者ID:jorzhikgit,项目名称:MLM-Nexus,代码行数:13,代码来源:_ide_helper.php

示例4: testFillImageWithPath

 public function testFillImageWithPath()
 {
     $img = Image::canvas(32, 32)->fill('public/tile.png');
     $this->assertInstanceOf('Intervention\\Image\\Image', $img);
     $this->assertInternalType('int', $img->width);
     $this->assertInternalType('int', $img->height);
     $this->assertEquals($img->width, 32);
     $this->assertEquals($img->height, 32);
     $this->assertEquals('#b4e000', $img->pickColor(0, 0, 'hex'));
     $this->assertEquals('#445160', $img->pickColor(31, 31, 'hex'));
 }
开发者ID:rosskmurphy,项目名称:Laravel-4-login-registration,代码行数:11,代码来源:ImageTest.php


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