/** * Get a cropped thumbnail from the given image * @param Image image source image for the thumbnail * @param int width width to calculate the thumbnail's width * @param int height height to calculate the thumbnail's height * @return Image Image instance of the thumbnail */ protected function createThumbnail(Image $image, $thumbnailWidth, $thumbnailHeight) { $x = 0; $y = 0; $width = $thumbnailWidth; $height = $thumbnailHeight; if ($image->getWidth() > $image->getHeight()) { $this->calculateNewSize($image->getWidth(), $image->getHeight(), $width, $height, $x, $y); } else { $this->calculateNewSize($image->getHeight(), $image->getWidth(), $height, $width, $y, $x); } $thumbnail = $image->resize($width, $height); $thumbnail = $thumbnail->crop($x, $y, $thumbnailWidth, $thumbnailHeight); return $thumbnail; }
/** * Get a resized thumbnail from the given image * @param Image image source image for the thumbnail * @param int width width to calculate the thumbnail's width * @param int height height to calculate the thumbnail's height * @return Image Image instance of the thumbnail */ protected function createThumbnail(Image $image, $width, $height) { $imageWidth = $image->getWidth(); $imageHeight = $image->getHeight(); if ($imageWidth > $imageHeight) { $this->calculateNewSize($imageWidth, $imageHeight, $width, $height); } else { $this->calculateNewSize($imageHeight, $imageWidth, $height, $width); } return $image->resize($width, $height); }
/** * Get a thumbnail from the given image * @param Image image source image for the thumbnail * @param int width width to calculate the thumbnail's width * @param int height height to calculate the thumbnail's height * @return Image Image instance of the thumbnail */ public function getThumbnail(Image $image, $thumbnailWidth, $thumbnailHeight) { if (Number::isNegative($thumbnailWidth)) { throw new ThumbnailException($thumbnailWidth . ' is an invalid width'); } if (Number::isNegative($thumbnailHeight)) { throw new ThumbnailException($thumbnailHeight . ' is an invalid height'); } if ($image->getWidth() <= $thumbnailWidth && $image->getHeight() <= $thumbnailHeight) { return $image; } return $this->createThumbnail($image, $thumbnailWidth, $thumbnailHeight); }
/** * Draws the layers content on the image * @param zibo\library\image\Image $image The image to draw upon * @param zibo\library\diagram\Diagram $diagram The diagram we're drawing * @return null */ public function draw(Image $image, Diagram $diagram) { $grid = $diagram->getGrid(); $width = $image->getWidth(); $height = $image->getHeight(); $cellDimension = $grid->getCellDimension(); $margin = $diagram->getMargin(); $cellWidth = $cellDimension->getWidth(); $cellHeight = $cellDimension->getHeight(); // take margin into account and go out of the image to start the grid $loopX = $loopY = $this->helperLocation - 1; $x = $margin; while ($x > 0) { $x -= $cellWidth; $loopX--; } $y = $margin; while ($y > 0) { $y -= $cellHeight; $loopY--; } // draw the X-axis for (; $x < $width; $x += $cellWidth) { $loopX++; if ($loopX == $this->helperLocation) { $color = $this->helperColor; $loopX = 0; } else { $color = $this->gridColor; } $image->drawLine(new Point($x, 0), new Point($x, $height), $color); } // draw the Y-axis for (; $y < $height; $y += $cellHeight) { $loopY++; if ($loopY == $this->helperLocation) { $color = $this->helperColor; $loopY = 0; } else { $color = $this->gridColor; } $image->drawLine(new Point(0, $y), new Point($width, $y), $color); } }
public function testGetWidth() { $image = new Image($this->testImage); $width = $image->getWidth(); $this->assertEquals($this->testImageWidth, $width); }
/** * Checks whether a value is a valid image * @param string $value Path to the image * @return boolean true if the value is a valid image, false otherwise */ public function isValid($value) { $this->resetErrors(); if (!$this->isRequired && empty($value)) { return true; } $parameters = array('value' => $value); try { $file = new File($value); $image = new Image($file); } catch (Exception $exception) { $parameters['message'] = $exception->getMessage(); $error = new ValidationError(self::CODE, self::MESSAGE, $parameters); $this->addError($error); return false; } if ($this->minWidth && $image->getWidth() < $this->minWidth) { $parameters['width'] = $this->minWidth; $error = new ValidationError(self::CODE_WIDTH_MIN, self::MESSAGE_WIDTH_MIN, $parameters); $this->addError($error); } if ($this->minHeight && $image->getHeight() < $this->minHeight) { $parameters['height'] = $this->minHeight; $error = new ValidationError(self::CODE_HEIGHT_MIN, self::MESSAGE_HEIGHT_MIN, $parameters); $this->addError($error); } if ($this->maxWidth && $image->getWidth() > $this->maxWidth) { $parameters['width'] = $this->maxWidth; $error = new ValidationError(self::CODE_WIDTH_MAX, self::MESSAGE_WIDTH_MAX, $parameters); $this->addError($error); } if ($this->maxHeight && $image->getHeight() > $this->maxHeight) { $parameters['height'] = $this->maxHeight; $error = new ValidationError(self::CODE_HEIGHT_MAX, self::MESSAGE_HEIGHT_MAX, $parameters); $this->addError($error); } if ($this->errors) { return false; } return true; }