本文整理汇总了PHP中Intervention\Image\Image::width方法的典型用法代码示例。如果您正苦于以下问题:PHP Image::width方法的具体用法?PHP Image::width怎么用?PHP Image::width使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Intervention\Image\Image
的用法示例。
在下文中一共展示了Image::width方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkWidth
/**
* Check width first in resizing
*
* @param \Intervention\Image\Image $image
* @param integer $width
*
* @return integer
*/
private function checkWidth($image, $width)
{
if ($image->width() < $width) {
return $image->width();
}
return $width;
}
示例2: limitToImageBoundaries
public function limitToImageBoundaries(Image $image, array $coordinates)
{
if ($coordinates[0] > $image->width() - $coordinates[2]) {
$coordinates[0] = $image->width() - $coordinates[2];
}
if ($coordinates[1] > $image->height() - $coordinates[3]) {
$coordinates[1] = $image->height() - $coordinates[3];
}
return $coordinates;
}
示例3: get
/**
* Resolve the dimension.
* @param string $value The dimension value.
* @return double The resolved dimension.
*/
public function get($value)
{
if (is_numeric($value) and $value > 0) {
return (double) $value * $this->dpr;
}
if (preg_match('/^(\\d{1,2}(?!\\d)|100)(w|h)$/', $value, $matches)) {
if ($matches[2] === 'h') {
return (double) $this->image->height() * ($matches[1] / 100);
}
return (double) $this->image->width() * ($matches[1] / 100);
}
}
示例4: get
/**
* Resolve the dimension.
* @param string $value The dimension value.
* @return double The resolved dimension.
*/
public function get($value)
{
if (is_numeric($value) and $value > 0) {
return (double) $value * $this->dpr;
}
if (preg_match('/^(\\d{1,2}(?!\\d)|100)(w|h)$/', $value)) {
$type = substr($value, -1);
$value = substr($value, 0, -1);
if ($type === 'w') {
return (double) $this->image->width() * ($value / 100);
}
if ($type === 'h') {
return (double) $this->image->height() * ($value / 100);
}
}
}
示例5: run
public function run(Image $image)
{
$color = (new Color($this->bg))->formatted();
if ($color) {
$new = $image->getDriver()->newImage($image->width(), $image->height(), $color);
$new->mime = $image->mime;
$image = $new->insert($image, 'top-left', 0, 0);
}
return $image;
}
示例6: 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;
}
示例7: make
/**
* Save file to database and to our filesystem.
*/
public static function make(Picture $picture, Image $image, $identifier)
{
$file = new self();
$file->picture_id = $picture->id;
$file->identifier = $identifier;
$file->mime = $image->mime();
$file->extension = $image->extension;
$file->width = $image->width();
$file->height = $image->height();
self::checkDirPermission();
$image->save($file->getFilePath());
$file->save();
}
示例8: 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;
}
示例9: apply
public function apply(Image $image)
{
$iHeight = $image->height();
$iWidth = $image->width();
if ($iHeight == $height && $iWidth == $width) {
return $image;
}
$iRatio = $iWidth / $iHeight;
$Ratio = $width / $height;
if ($iRatio > $Ratio) {
$image->resize($width, null, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
} else {
$image->resize(null, $height, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
}
return $image;
}
示例10: resolveCropOffset
/**
* Resolve the crop offset.
* @param Image $image The source image.
* @param integer $width The width.
* @param integer $height The height.
* @return array The crop offset.
*/
public function resolveCropOffset(Image $image, $width, $height)
{
list($offset_percentage_x, $offset_percentage_y) = $this->getCrop();
$offset_x = (int) ($image->width() * $offset_percentage_x / 100 - $width / 2);
$offset_y = (int) ($image->height() * $offset_percentage_y / 100 - $height / 2);
$max_offset_x = $image->width() - $width;
$max_offset_y = $image->height() - $height;
if ($offset_x < 0) {
$offset_x = 0;
}
if ($offset_y < 0) {
$offset_y = 0;
}
if ($offset_x > $max_offset_x) {
$offset_x = $max_offset_x;
}
if ($offset_y > $max_offset_y) {
$offset_y = $max_offset_y;
}
return [$offset_x, $offset_y];
}
示例11: getInfo
public function getInfo()
{
return ['mime' => $this->image->mime(), 'width' => $this->image->width(), 'height' => $this->image->height(), 'extension' => $this->image->extension, 'filename' => $this->image->filename, 'filesize' => $this->image->filesize()];
}
示例12: execute
/**
* Fills image with color or pattern
*
* @param \Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$filling = $this->argument(0)->value();
$x = $this->argument(1)->type('digit')->value();
$y = $this->argument(2)->type('digit')->value();
$width = $image->width();
$height = $image->height();
$filling = $this->decodeFilling($filling);
// flood fill if coordinates are set
if (is_int($x) && is_int($y)) {
// flood fill with texture
if ($filling instanceof Image) {
foreach ($image as $frame) {
// create tile
$tile = clone $frame->getCore()->getImage();
$alpha = false;
if ($tile->getImageAlphaChannel() !== \Imagick::ALPHACHANNEL_UNDEFINED) {
// clone alpha channel
$alpha = clone $frame->getCore()->getImage();
}
// mask away color at position
$tile->transparentPaintImage($tile->getImagePixelColor($x, $y), 0, 0, false);
// fill canvas with texture
$canvas = $frame->getCore()->textureImage($filling->getCore());
// merge canvas and tile
$canvas->compositeImage($tile, \Imagick::COMPOSITE_DEFAULT, 0, 0);
if ($alpha) {
// restore alpha channel of original image
$canvas->compositeImage($alpha, \Imagick::COMPOSITE_COPYOPACITY, 0, 0);
}
// replace image core
$frame->getCore()->setImage($canvas);
$tile->clear();
$canvas->clear();
}
// flood fill with color
} elseif ($filling instanceof Color) {
// create filling
$fill = new \Imagick();
$fill->newImage($width, $height, 'none', 'png');
$draw = new \ImagickDraw();
$draw->setFillColor($filling->getPixel());
$draw->rectangle(0, 0, $width, $height);
$fill->drawImage($draw);
foreach ($image as $frame) {
// create tile
$tile = clone $frame->getCore()->getImage();
$alpha = false;
if ($tile->getImageAlphaChannel() !== \Imagick::ALPHACHANNEL_UNDEFINED) {
// clone alpha channel
$alpha = clone $frame->getCore()->getImage();
}
// mask away color at position
$tile->transparentPaintImage($tile->getImagePixelColor($x, $y), 0, 0, false);
// fill canvas with texture
$canvas = $frame->getCore()->textureImage($fill);
// merge canvas and tile
$canvas->compositeImage($tile, \Imagick::COMPOSITE_DEFAULT, 0, 0);
if ($alpha) {
// restore alpha channel of original image
$canvas->compositeImage($alpha, \Imagick::COMPOSITE_COPYOPACITY, 0, 0);
}
// replace image core
$frame->getCore()->setImage($canvas);
$tile->clear();
$canvas->clear();
}
}
} else {
if ($filling instanceof Image) {
// fill each frame with texture
foreach ($image as $frame) {
$filled = $frame->getCore()->textureImage($filling->getCore());
$frame->getCore()->setImage($filled);
}
} elseif ($filling instanceof Color) {
// setup draw object
$draw = new \ImagickDraw();
$draw->setFillColor($filling->getPixel());
$draw->rectangle(0, 0, $width, $height);
// fill each frame with color
foreach ($image as $frame) {
$frame->getCore()->drawImage($draw);
}
}
}
return true;
}
示例13: getWidth
/**
* Get image width
* @return int
*/
public function getWidth()
{
return $this->image->width();
}
示例14: resolveMissingDimensions
/**
* Resolve missing image dimensions.
* @param Image $image The source image.
* @param double|null $width The image width.
* @param double|null $height The image height.
* @return double[] The resolved width and height.
*/
public function resolveMissingDimensions(Image $image, $width, $height)
{
if (!$width and !$height) {
$width = $image->width();
$height = $image->height();
}
if (!$width) {
$width = $height * ($image->width() / $image->height());
}
if (!$height) {
$height = $width / ($image->width() / $image->height());
}
return [(double) $width, (double) $height];
}
示例15: runShrink
public function runShrink(Image $image, $width, $color)
{
return $image->resize($image->width() - $width * 2, $image->height() - $width * 2)->resizeCanvas($width * 2, $width * 2, 'center', true, $color);
}