/** * Get the cache hash of an image * * @param Image $image * * @return string */ public function getHashOf(Image $image) { $imagePath = $image->getOriginalImagePath(); // Build the salt array $salts = $image->getSalts(); $salts[] = $image->getQuality(); $salts[] = md5($imagePath); $salts = serialize($salts); // Get image extension $extension = pathinfo($imagePath, PATHINFO_EXTENSION); return md5($salts) . '.' . $extension; }
/** * Process an Image * * @param Image $image * * @return ImagineInterface */ public function process(Image $image) { $processors = $image->getSalts(); $image = $this->imagine->open($image->getOriginalImagePath()); // Apply each method one after the other foreach ($processors as $method => $arguments) { if (empty($arguments) or isset($arguments[0])) { $image = $this->executeMethod($image, $method, $arguments); } else { foreach ($arguments as $submethod => $arguments) { $this->executeSubmethod($image, $method, $submethod, $arguments); } } } return $image; }
/** * Create a new Image * * @param string $image Path to the image * * @return Image */ public function image($image) { try { $image = new Image($this, $image); if (!is_null($image->getImage())) { return $image; } } catch (\RuntimeException $e) { } return false; }