/** * Constructor * * @param string $path Path to image * @param UnitConverter $unitConverter Converter that converts image's size from pixels to standard unit */ public function __construct($path, UnitConverter $unitConverter = null) { $this->path = $path; $this->unitConverter = $unitConverter; if (!$this->pathExists($path) || ($data = @getimagesize($path)) === false) { throw InvalidResourceException::invalidImageException($path); } $this->type = $data[2]; $this->width = $unitConverter ? $unitConverter->convertUnit($data[0], UnitConverter::UNIT_PIXEL) : $data[0]; $this->height = $unitConverter ? $unitConverter->convertUnit($data[1], UnitConverter::UNIT_PIXEL) : $data[1]; }
private function getPointsWithPositionCorrection(UnitConverter $converter, Boundary $boundary) { $points = array(); $xSignMatrix = array(-1, 1, 1, -1, -1); $ySignMatrix = array(1, 1, -1, -1, 1); $position = $converter->convertUnit($this->position); foreach ($boundary->getPoints() as $index => $point) { $xSign = isset($xSignMatrix[$index]) ? $xSignMatrix[$index] : 1; $ySign = isset($ySignMatrix[$index]) ? $ySignMatrix[$index] : 1; $points[$index] = array($point->getX() + $position * $xSign, $point->getY() + $position * $ySign); } return $points; }
private function convertPercentageDimension(UnitConverter $converter, Node $node, $width, $height) { $width = $converter->convertPercentageValue($width, $this->getWidth($node)); $height = $converter->convertPercentageValue($height, $this->getHeight($node)); return array($width, $height); }