本文整理汇总了PHP中Intervention\Image\ImageManagerStatic::canvas方法的典型用法代码示例。如果您正苦于以下问题:PHP ImageManagerStatic::canvas方法的具体用法?PHP ImageManagerStatic::canvas怎么用?PHP ImageManagerStatic::canvas使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Intervention\Image\ImageManagerStatic
的用法示例。
在下文中一共展示了ImageManagerStatic::canvas方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* @param string $name
* @param int $size
* @param string $background_color
* @param string $text_color
* @param string $font_file
* @return ImageManagerStatic
* @throws Exception
*/
public static function create($name = '', $size = 512, $background_color = '#666', $text_color = '#FFF', $font_file = '../../../font/OpenSans-Semibold.ttf')
{
if (strlen($name) <= 0) {
throw new Exception('Name must be at least 2 characters.');
}
if ($size <= 0) {
throw new Exception('Input must be greater than zero.');
}
if ($font_file === '../../../font/OpenSans-Semibold.ttf') {
$font_file = __DIR__ . "/" . $font_file;
}
if (!file_exists($font_file)) {
throw new Exception("Font file not found");
}
$str = "";
$name_ascii = strtoupper(Str::ascii($name));
$words = preg_split("/[\\s,_-]+/", $name_ascii);
if (count($words) >= 2) {
$str = $words[0][0] . $words[1][0];
} else {
$str = substr($name_ascii, 0, 2);
}
$img = ImageManagerStatic::canvas($size, $size, $background_color)->text($str, $size / 2, $size / 2, function ($font) use($size, $text_color, $font_file) {
$font->file($font_file);
$font->size($size / 2);
$font->color($text_color);
$font->align('center');
$font->valign('middle');
});
return $img;
}
示例2: testCanvas
public function testCanvas()
{
$manager = Mockery::mock('Intervention\\Image\\ImageManager');
$manager->shouldReceive('canvas')->with(100, 100, null)->once();
$managerStatic = new ImageManagerStatic($manager);
$managerStatic->canvas(100, 100);
}
示例3: testCanvas
public function testCanvas()
{
$manager = Mockery::mock('Intervention\\Image\\ImageManager');
$managerStatic = new ImageManagerStatic($manager);
$img = $managerStatic->canvas(100, 100);
$this->assertInstanceOf('Intervention\\Image\\Image', $img);
}
示例4: get
public function get($icon, $request, $response)
{
$info = pathinfo($icon);
$iconName = $info["filename"];
$extension = isset($info["extension"]) ? $info["extension"] : "png";
$size = $request->getParameter("size", 512);
$color = trim($request->getParameter("color", "777"), '#');
$filename = "icons/{$iconName}_{$size}_{$color}.{$extension}";
$targetFolder = realpath(".");
$targetLocation = "https://" . $_SERVER["HTTP_HOST"] . dirname($_SERVER["SCRIPT_NAME"]) . "/" . $filename;
if (is_file($targetFolder . '/' . $filename)) {
return $response->status(301)->header("Location", $targetLocation);
}
$ttf = realpath(dirname(__FILE__) . "/../webfonts/fontawesome/fontawesome-webfont.ttf");
$characters = (include realpath(dirname(__FILE__) . "/../webfonts/fontawesome/characters.php"));
if (!isset($characters[$iconName])) {
return $response->status(404);
}
$iconChar = html_entity_decode('&#' . $characters[$iconName] . ';');
$canvas = Image::canvas($size, $size);
$canvas->text($iconChar, $size / 2, $size / 2, function ($font) use($ttf, $size, $color) {
$font->file($ttf);
$font->size($size - 2);
$font->color('#' . $color);
$font->align('center');
$font->valign('center');
});
$canvas->save($targetFolder . '/' . $filename);
return $response->status(301)->header("Location", $targetLocation);
}
示例5: renderInternal
/**
* @param NodeInfo[] $nodes
* @return string
*/
protected function renderInternal(array $nodes)
{
/** @var \Intervention\Image\Image $img */
$img = ImageManagerStatic::canvas($this->treemap->width, $this->treemap->height);
/** @var NodeInfo $node */
foreach ($nodes as $node) {
if ($node->visible()) {
$rectangle = $node->rectangle();
$img->rectangle($rectangle->left, $rectangle->top, $rectangle->left + $rectangle->width - 1, $rectangle->top + $rectangle->height - 1, function (AbstractShape $draw) use($node) {
$draw->background($node->background());
});
$this->writeContent($img, $node);
}
}
return (string) $img->encode($this->format);
}
示例6: makeImage
/**
* Generate randomized images for testing
* @return string The generated filename
*/
public static function makeImage()
{
$height = $width = 5;
$scale = 100;
$filename = self::$tempDir . 'test_' . bin2hex(openssl_random_pseudo_bytes(8)) . ".jpg";
$img = Image::canvas($width, $height, '#000');
for ($x = 0; $x < $width; $x++) {
for ($y = 0; $y < $height; $y++) {
$color = self::randomColor();
$img->pixel($color, $x, $y);
}
}
$img->resize($width * $scale, $width * $scale);
$png = $img->encode('jpg');
$png->save($filename);
return $filename;
}
示例7: display
public function display($album_id, $photo_id, $size)
{
$album = with(RepositoryFactory::create('Gallery\\Album'))->get($album_id);
if ($album === null) {
return redirect('/');
}
$repository = RepositoryFactory::create('Gallery\\Photo');
$photo = $repository->get($photo_id);
$photo_file = storage_path(strtr('photos/{date}/{size}/{file_name}', ['{date}' => $photo->date, '{size}' => $size, '{file_name}' => $photo->file_name]));
if (file_exists($photo_file)) {
$image = Image::make($photo_file);
} else {
$image = Image::canvas('300', '300');
$image->text('404', 150, 126, function ($font) {
$font_file = resource_path('fonts') . '/monaco.ttf';
$font->file($font_file);
$font->size(48);
$font->align('center');
$font->valign('top');
});
}
return $image->response();
}
示例8: generateImage
/**
* Generate the Initialcon image.
*
* @param string $string
* @param int $size
* @param string $hexaColor
*/
private function generateImage($initials, $identifier, $size, $color)
{
$this->setInitials($initials);
$this->setIdentifier($identifier);
$this->setSize($size);
$textSize = $this->getTextSize();
if ($this->fontPath === null) {
$this->setFontPath(__DIR__ . '/OpenSans-Regular.ttf');
}
$fontFilePath = $this->getFontPath();
// prepage the color
if (null !== $color) {
$this->setColor($color);
}
$image = Image::canvas($size, $size, $this->getColor());
$image->text($this->initials, $size / 2, $size / 2, function ($font) use($textSize, $fontFilePath) {
$font->size($textSize);
$font->color('#ffffff');
$font->align('center');
$font->valign('middle');
$font->file($fontFilePath);
});
return $image;
}
示例9: _create_cached
/**
* Creates a cached cropped/resized version of the file
*/
private function _create_cached()
{
if (isset($this->url_params['c']) && $this->url_params['c']) {
// Resize to highest width or height with overflow on the larger side
$this->resize($this->url_params['w'], $this->url_params['h'], self::INVERSE);
// $this->image->resize($this->url_params['w'], $this->url_params['h']);
// Crop any overflow from the larger side
$this->image->crop($this->url_params['w'], $this->url_params['h'], 0, 0);
} elseif (isset($this->url_params['nc']) && $this->url_params['nc']) {
$img = Image::canvas($this->url_params['w'], $this->url_params['h'], $this->config['nc_color']);
// Resize to width and height
$this->resize($this->url_params['w'], $this->url_params['h'], self::AUTO);
$img->insert($this->image, 'center');
$this->image = $img;
} elseif (isset($this->url_params['a']) && $this->url_params['a']) {
// Just Resize automatically
$this->resize($this->url_params['w'], $this->url_params['h']);
} else {
// Just Resize
$this->resize($this->url_params['w'], $this->url_params['h'], self::INVERSE);
}
// Apply any valid watermark params
// $watermarks = array_get($this->config, 'watermarks');
// if ( ! empty($watermarks))
// {
// foreach ($watermarks as $key => $watermark)
// {
// if (key_exists($key, $this->url_params))
// {
// $image = Image::factory($watermark['image']);
// $this->image->watermark($image, $watermark['offset_x'], $watermark['offset_y'], $watermark['opacity']);
// }
// }
// }
// Save
if ($this->url_params['q']) {
// Save image with quality param
$this->image->save($this->cached_file, $this->url_params['q']);
} else {
// Save image with default quality
$this->image->save($this->cached_file, array_get($this->config, 'quality', 80));
}
}
示例10: correctSizedThumbnails
/**
* @testdox Image thumbnails are correctly resized.
* @test
*/
public function correctSizedThumbnails()
{
// Create a large image.
$img = Image::canvas(1000, 400, '#ccc');
$tmpFilename = $this->dataDir() . '/test-image.jpg';
$img->save($tmpFilename);
// Add it to an Item.
$item = new Item(null, $this->testUser);
$item->save(null, null, $tmpFilename);
// Check that the various sizes returned are correct.
$this->assertEquals('image/jpeg', $item->getMimeType());
$this->assertFileEquals($tmpFilename, $item->getCachePath('o'));
// Load the 'display' size.
$display = Image::make($item->getCachePath('d'));
$this->assertEquals(700, $display->getWidth());
$this->assertEquals(280, $display->getHeight());
// The thumbnail is always 200 x 200.
$thumb = Image::make($item->getCachePath('t'));
$this->assertEquals(200, $thumb->getWidth());
$this->assertEquals(200, $thumb->getHeight());
}
示例11: compile
/**
* @return $this
*/
public function compile()
{
$filePath = $this->getBaseFile();
// get file meta data...
$imageFile = new File($filePath);
// get our main image resource...
$image = ImageManagerStatic::make($imageFile->getPath());
// start with base image size
$canvas = ImageManagerStatic::canvas($imageFile->getWidth(), $imageFile->getHeight());
// apply the filters
$image = $this->applyFilters($canvas, $image, $this->getFilters());
// now save the image
$genFile = $this->generateFileName();
$image->save($genFile);
return $this;
}
示例12: initialize
/**
* @return Image
*/
protected function initialize()
{
$this->image = ImageManagerStatic::canvas(2408, 3508, '#fff');
$this->image->polygon([0, 0, 0, 400, 980, 400, 1250, 0], function (AbstractShape $shape) {
$shape->background($this->template->getFontColor());
});
// Draw header
$this->image->polygon([1250, 0, 980, 400, $this->image->getWidth(), 400, $this->image->getWidth(), 0], function (AbstractShape $shape) {
$shape->background($this->template->getPrimaryColor());
});
$this->image->polygon([0, 400, 0, 425, 675, 425, 755, 480, 800, 400], function (AbstractShape $shape) {
$shape->background($this->template->getPrimaryColor());
});
$color = $this->template->getPrimaryColor();
$color[0] = $color[0] + 90;
if ($color[0] > 255) {
$color[0] = 255;
}
$this->image->polygon([800, 400, 755, 480, 820, 500, 890, 400], function (AbstractShape $shape) use($color) {
$shape->background($color);
});
$this->image->polygon([890, 400, 870, 425, 970, 425, 990, 400], function (AbstractShape $shape) {
$shape->background($this->template->getPrimaryColor());
});
// Company address (Left header)
if ($this->template->getLogo()) {
$size = @getimagesize($this->template->getLogo());
if ($size) {
$this->image->insert($this->template->getLogo(), 'top-left', (int) ((980 - $size[0]) / 2), (int) ((186 - $size[1]) / 2));
}
}
$y = isset($size) ? 220 : 120;
$this->image->text($this->company->getZip() . ' ' . $this->company->getTown(), 450, $y, function (Font $font) {
$font->file($this->template->getFont());
$font->color($this->template->getColorOdd());
$font->align('right');
$font->size(27);
});
$this->image->text($this->company->getAddress(), 450, $y + 50, function (Font $font) {
$font->file($this->template->getFont());
$font->color($this->template->getColorOdd());
$font->align('right');
$font->size(27);
});
$this->image->text($this->company->getCountry(), 450, $y + 100, function (Font $font) {
$font->file($this->template->getFont());
$font->color($this->template->getColorOdd());
$font->align('right');
$font->size(27);
});
$multiplier = 0;
if ($this->company->getTin()) {
$this->image->text(Strings::upper($this->translate('vat')) . ': ' . $this->company->getTin(), 520, $y + $multiplier * 50, function (Font $font) {
$font->file($this->template->getFont());
$font->color($this->template->getColorOdd());
$font->align('left');
$font->size(27);
});
$multiplier++;
}
if ($this->company->getVaTin()) {
$this->image->text(Strings::upper($this->translate('vaTin')) . ': ' . $this->company->getVaTin(), 520, $y + $multiplier * 50, function (Font $font) {
$font->file($this->template->getFont());
$font->color($this->template->getColorOdd());
$font->align('left');
$font->size(27);
});
$multiplier++;
}
$this->image->text($this->company->hasTax() ? $this->translate('taxPay') : $this->translate('notTax'), 520, $y + $multiplier * 50, function (Font $font) {
$font->file($this->template->getFont());
$font->color($this->template->getColorOdd());
$font->align('left');
$font->size(27);
});
// Company name or full name
$this->image->text($this->company->getName(), 1775, 100, function (Font $font) {
$font->file($this->template->getFont());
$font->color($this->template->getColorOdd());
$font->align('center');
$font->size(35);
});
// Payment informations
$this->image->text(Strings::upper($this->translate('paymentData')), 1500, 500, function (Font $font) {
$font->file($this->template->getFont());
$font->color($this->template->getPrimaryColor());
$font->align('left');
$font->valign('top');
$font->size(65);
});
$this->image->polygon([1450, 580, 1450, 620, 1480, 590, $this->image->getWidth(), 590, $this->image->getWidth(), 580], function (AbstractShape $shape) {
$shape->background($this->template->getPrimaryColor());
});
$this->itemsHeader();
$this->image->rectangle(0, $this->image->getHeight() - 80, $this->image->getWidth(), $this->image->getHeight(), function (AbstractShape $shape) {
$shape->background($this->template->getFontColor());
});
//.........这里部分代码省略.........