本文整理汇总了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);
}
示例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'));
//.........这里部分代码省略.........
示例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);
}
示例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'));
}