/** * 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; }
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; }
/** * 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); } }
/** * 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); } } }
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; }
/** * 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; }
/** * 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(); }
/** * 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; }
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; }
/** * 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]; }
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()]; }
/** * 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; }
/** * Get image width * @return int */ public function getWidth() { return $this->image->width(); }
/** * 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]; }
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); }
/** * @return int */ public function getWidth() { return $this->intervention->width(); }
/** * Указанная рамка должна помещаться внутрь конечного изображения * Т.е. если заказываем 100 на 400 а картинка 2000 на 1000 * То картинка будет уменьшаться до тех пор пока ее высота меньше указанного * или ширина меньше указанного * * @param \Intervention\Image\Image $img * @param $w * @param $h * * @return \Intervention\Image\Image */ static function resizeBoxInImg(\Intervention\Image\Image $img, $w, $h) { $ratio_image = $img->width() / $img->height(); $ratio_box = $w / $h; if ($ratio_box < $ratio_image) { $_h = $h; $_w = null; } else { $_w = $w; $_h = null; } return $img->resize($_w, $_h, function ($constraint) { $constraint->aspectRatio(); }); }