source($source); $this->sizer($sizer); $this->driver = clone $driver; } public function source(string $source) { // set source $this->source = realpath($source); if (!$this->source) { throw new \Exception("Source image not found: " . htmlentities($source)); } // validate file if (!is_file($this->source)) { throw new \Exception("Image file doesn't exist: " . htmlentities($this->source)); } if (!exif_imagetype($this->source)) { throw new \Exception("Invalid image file: " . htmlentities($this->source)); } // get height/width list($this->originalWidth, $this->originalHeight) = getimagesize($this->source); } public function sizer(AbstractSizer $sizer = null): AbstractSizer { if ($sizer) { $this->sizer = clone $sizer; $this->sizer->image($this); } return $this->sizer; } public function rotate(int $steps = 1) { $this->rotation = ($this->rotation + $steps) % 4; } public function rotation(): int { return $this->rotation; } public function flipH() { $this->flipH = !$this->flipH; if ($this->flipH && $this->flipV) { $this->flipH = $this->flipV = false; } } public function flipV() { $this->flipV = !$this->flipV; if ($this->flipH && $this->flipV) { $this->flipH = $this->flipV = false; } } public function width(): int { return $this->sizer->width(); } public function height(): int { return $this->sizer->height(); } public function ratio(): float { return $this->width() / $this->height(); } public function originalRatio(): float { return $this->originalWidth() / $this->originalHeight(); } public function originalWidth(): int { return $this->originalWidth; } public function originalHeight(): int { return $this->originalHeight; } }