/** * Resizes image. * @access public * @param integer $width New width * @param integer $height New height * @param boolean $interpolate Flag: use interpolation * @return object Processor object for chaining * @throws InvalidArgumentException if width is not an integer value * @throws InvalidArgumentException if height is not an integer value * @throws OutOfRangeException if width is lower than 1 * @throws OutOfRangeException if height is lower than 1 * @throws OutOfRangeException if resulting image has more mega pixels than allowed */ public function resize($width, $height, $interpolate = TRUE) { if (!is_int($width)) { throw new \InvalidArgumentException('Width must be integer'); } if (!is_int($height)) { throw new \InvalidArgumentException('Height must be integer'); } if ($width < 1) { throw new \OutOfRangeException('Width must be atleast 1'); } if ($height < 1) { throw new \OutOfRangeException('Height must be atleast 1'); } if ($this->image->getWidth() == $width && $this->image->getHeight() == $height) { return $this; } if ($this->maxMegaPixels && $width * $height > $this->maxMegaPixels * 1024 * 1024) { throw new \OutOfRangeException('Larger than ' . $this->maxMegaPixels . 'MP (' . $width . 'x' . $height . ')'); } $image = new \CeusMedia\Image\Image(); $image->create($width, $height); $image->setType($this->image->getType()); $parameters = array_merge(array($image->getResource(), $this->image->getResource()), array(0, 0, 0, 0), array($width, $height), array($this->image->getWidth(), $this->image->getHeight())); $function = $interpolate ? 'imagecopyresampled' : 'imagecopyresized'; // function to use depending on interpolation $reflection = new \ReflectionFunction($function); // reflect function $reflection->invokeArgs($parameters); // call function with parameters $this->image->setResource($image->getResource()); // replace held image resource object by result return $this; }
<?php @(include '../vendor/autoload.php') or die('Please use composer to install required packages.' . PHP_EOL); $pathCDN = "//cdn.int1a.net/"; $pathImages = "images/"; $fileName = "IMG_6661.JPG"; $fileName = "IMG_2422.JPG"; $fileName = "IMG_2466.JPG"; $fileName = "IMG_2454.JPG"; $image = new \CeusMedia\Image\Image($pathImages . $fileName); // load image $processor = new \CeusMedia\Image\Processor($image); // start processor on image $processor->scaleDownToLimit(1960, 800); // scale down very large image $offsetX = (int) floor(($image->getWidth() - 980) / 2); // calculate left crop offset $offsetY = (int) floor(($image->getHeight() - 450) / 2); // calculate top crop offset $processor->crop($offsetX, $offsetY, 980, 450); // crop middle image part $copy = clone $image; // close image for results $processor = new \CeusMedia\Image\Processor($copy); // start processor on result image //$processor->enhance( -10, 10, 0.8, 50 ); // enhance image: preset "old film" //$processor->enhance( 10, -10, 1.25, 10 ); // enhance image: preset "person", $processor->enhance(10, -10, 1.25, 20); // enhance image: preset "nature", $body = ' <div class="container">