本文整理汇总了PHP中Intervention\Image\Image::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP Image::insert方法的具体用法?PHP Image::insert怎么用?PHP Image::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Intervention\Image\Image
的用法示例。
在下文中一共展示了Image::insert方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testInsertPng8WithAlphaChannel
public function testInsertPng8WithAlphaChannel()
{
$img = new Image(null, 16, 16, '#ff0000');
$img->insert('public/png8.png');
$this->assertEquals('#ff0000', $img->pickColor(0, 0, 'hex'));
$this->assertEquals('#8c8c8c', $img->pickColor(10, 10, 'hex'));
}
示例2: insert
/**
* Insert another image on top of the current image
*
* @param mixed $source
* @param integer $pos_x
* @param integer $pos_y
* @param string $anchor
* @return \Intervention\Image\Image
* @static
*/
public static function insert($source, $pos_x = 0, $pos_y = 0, $anchor = null)
{
return \Intervention\Image\Image::insert($source, $pos_x, $pos_y, $anchor);
}
示例3: watermark
/**
* Watermark
*
* @param string $path
* @param integer $opacity
*
* @return Imagine
*/
public function watermark($path, $position = 'center', $opacity = null)
{
if ($this->isImage($path)) {
$watermark = $this->manager->make($path);
$width = $this->image->width();
$height = $this->image->height();
if ($watermark->width() > $width || $watermark->height() > $height) {
$watermark->resize($width, $height, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
}
if (!is_null($opacity) && $opacity >= 0 && $opacity <= 100) {
$watermark->opacity($opacity);
}
$this->image->insert($watermark, $position);
}
return $this;
}
示例4: run
/**
* Perform image manipulations.
* @param Request $request The request object.
* @param Image $image The source image.
* @return Image The manipulated image.
*/
public function run(Request $request, Image $image)
{
//die('watermarking');
// Get the image source of the mark
if (!($mark = $this->getMark($request->get('mark')))) {
return $image;
}
// Still here? Cool...
// Get the position
$position = $this->resolvePosition($request->get('markalign'));
$padding = $this->getMarkPadding($request->get('markpad'));
if ($scale = $this->getMarkScale($request->get('markscale'))) {
$mark->resize(round($image->width() * ($scale / 100)), null, function ($constraint) {
$constraint->aspectRatio();
});
}
// Insert the watermark
$image->insert($mark, $position, $padding, $padding);
// Continue
return $image;
}
示例5: watermark
protected function watermark()
{
if ($this->watermark) {
// create an image manager instance with favored driver
$manager = new ImageManager(array('driver' => 'imagick'));
/* @var $watermark \Intervention\Image\Image */
$watermark = $manager->make($this->watermark);
if ($this->watermarkScale) {
$scale = (double) sprintf('0.%s', $this->watermarkScale);
$watermark->resize($watermark->getWidth() * $scale, $watermark->getHeight() * $scale, function ($constraint) {
/* @var $constraint \Intervention\Image\Constraint */
$constraint->aspectRatio();
$constraint->upsize();
});
}
$align = null;
if ($this->watermarkAlign) {
$tmp = explode(',', strtolower($this->watermarkAlign));
if (in_array('top', $tmp) && in_array('left', $tmp)) {
$align = 'top-left';
} elseif (in_array('top', $tmp) && in_array('right', $tmp)) {
$align = 'top-right';
} elseif (in_array('bottom', $tmp) && in_array('right', $tmp)) {
$align = 'bottom-right';
} elseif (in_array('bottom', $tmp) && in_array('left', $tmp)) {
$align = 'bottom-left';
} else {
$align = strtolower($this->watermarkAlign);
}
}
if ($this->watermarkAlpha) {
$watermark->opacity($this->watermarkAlpha);
}
if ($this->watermarkPadding) {
$watermark->resizeCanvas($watermark->getWidth() + $this->watermarkPadding, $watermark->getHeight() + $this->watermarkPadding);
}
$this->image->insert($watermark, $align, $this->watermarkX, $this->watermarkY);
}
}
示例6: addWatermark
protected function addWatermark()
{
$watermark = base_path() . \Config::get('chuc.indexer.watermark');
$this->image->insert($watermark, 'center');
return $this;
}
示例7: insert
/**
* Save rendered image to output file
* @param string $outputImagePath The path to which the image (with text) will be saved
* @api
*/
public function insert($imageObj, $x, $y, $anchor)
{
return $this->image->insert($imageObj, $x, $y, $anchor);
}
示例8: applyFilter
public function applyFilter(Image $image)
{
return $image->insert($this->watermarkPath, $this->position, $this->coordinatesX, $this->coordinatesY);
}
示例9: handle
/**
* Handle the image manipulation request
* @param \Intervention\Image\Image $image
* @param array $options
* @return \Intervention\Image\Image
*/
public function handle($image, $options)
{
$options = array_merge($this->defaults, $options);
return $image->insert($options['source'], $options['position'], $options['x'], $options['y']);
}
示例10: applyFilters
/**
* @param Image $canvas
* @param Image $baseImage
* @param $filters array Filter name and args to be compiled
* @return Image
*/
public function applyFilters(Image $canvas, Image $baseImage, $filters)
{
// first check if we have a filter that applies the base image
$writeBaseImage = true;
foreach ($filters as $filter) {
// build filter object...
if ($filterObj = $this->getFilter($filter['filter'])) {
if ($filterObj->writesBaseImageToCanvas()) {
$writeBaseImage = false;
break;
}
}
}
// if no filters wrote the base image on the canvas, we presume that should always be done first.. do it now.
if ($writeBaseImage === true) {
$canvas->insert($baseImage, null, 0, 0);
// should we center?
}
// now apply all filters to canvas
foreach ($filters as $filter) {
// build filter object...
if ($filterObj = $this->getFilter($filter['filter'])) {
// build args off parsed filter
$fArgs = $filterObj->buildArgs($filter);
// write filter to our current canvas
$canvas = $this->applyFilter($canvas, $baseImage, $filterObj, $fArgs);
}
}
return $canvas;
}
示例11: missingMethod
public function missingMethod($args)
{
if (count($args) < 3) {
return parent::missingMethod($args);
}
if ($args[0] == 'force') {
array_shift($args);
}
$modelKeyword = $args[0];
$modelClass = \Devhook::getClassByKey($modelKeyword);
$id = $args[1];
$file = $args[2];
$parts = explode('-', $file);
if (count($parts) == 3) {
list($field, $sizeKey, $file) = $parts;
@(list($imageId, $ext) = explode('.', $file));
} else {
$imageId = false;
@(list($field, $file) = $parts);
@(list($sizeKey, $ext) = explode('.', $file));
}
if (!$field || !$sizeKey || $ext != 'jpg') {
return parent::missingMethod($args);
}
$model = $modelClass::find($id);
if (!$model || !$model->{$field}) {
return parent::missingMethod($args);
}
// $fileExt = pathinfo($model->$field, PATHINFO_EXTENSION);
$fields = (array) $model->getFields();
$modelField = isset($fields[$field]) ? $fields[$field] : false;
if (!$modelField || empty($modelField->type)) {
return parent::missingMethod($args);
}
$imageTypes = array('image');
$type = $modelField->type;
$sizes = (array) $modelField->settings('sizes');
$imageAdminThumb = Config::get('devhook.imageAdminThumb');
if (!in_array($type, $imageTypes) || empty($sizes[$sizeKey])) {
return parent::missingMethod($args);
}
$watermark = $modelField->settings('watermark');
$size = $sizes[$sizeKey];
$width = $size[0];
$hegiht = $size[1];
$crop = isset($size[2]) ? $size[2] : false;
$quality = isset($size[3]) ? $size[3] : 95;
if ($imageId) {
$imageFile = \Image::where('imageable_type', $modelKeyword)->where('imageable_id', $id)->find($imageId);
if (!$imageFile) {
return parent::missingMethod($args);
}
$imageFile = $imageFile->path;
} else {
$imageFile = $model->{$field};
}
ini_set('memory_limit', '200M');
$image = new IMG(public_path($imageFile));
if ($crop) {
$image->grab($width, $hegiht);
} else {
$image->resize($width, $hegiht, true);
}
if ($watermark) {
if (!$watermark['sizes'] || in_array($sizeKey, $watermark['sizes'])) {
$image->insert($watermark['image'], $watermark['offset'][0], $watermark['offset'][1], $watermark['position']);
}
}
$tmpFile = public_path($model->{$field}) . '.tmp_' . uniqid();
$newFile = public_path(Config::get('devhook.imageRoute') . '/' . implode('/', $args));
$newPath = dirname($newFile);
if (!File::exists($newPath)) {
File::makeDirectory($newPath, 0777, true);
}
$image->save($newFile, $quality);
$img = $image->encode($ext, $quality);
$response = Response::make($img, 200);
$response->header('Content-Type', 'image/jpeg');
return $response;
}
示例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());
});
//.........这里部分代码省略.........