/** * @param ImageInterface $image * @param PersisterOptionsInterface $persisterOptions * @return bool */ public function save(ImageInterface $image, PersisterOptionsInterface $persisterOptions) { /** @var EntityPersisterOptions $persisterOptions */ $this->guardAgainstInvalidOptionsType($persisterOptions); $entity = $persisterOptions->getEntity(); $setter = $persisterOptions->getSetter(); $this->guardAgainstUncallableSetter($entity, $setter); $entity->{$setter}($image->getData()); return true; }
/** * @param ImageInterface $image * @param PersisterOptionsInterface $persisterOptions * @return bool */ public function save(ImageInterface $image, PersisterOptionsInterface $persisterOptions) { /** @var FilePersisterOptions $persisterOptions */ $this->guardAgainstInvalidOptionsType($persisterOptions); $filePath = $persisterOptions->getFilePath(); $this->guardAgainstInvalidPath($filePath); if (file_put_contents($filePath, $image->getData()) === false) { $msg = sprintf("Error saving file %s", $filePath); throw new SaveFileErrorException($msg, SaveFileErrorException::CANT_SAVE_FILE); } return true; }
/** * @param ImageInterface $image * @return resource */ protected function getImageResourceHandle(ImageInterface $image) { try { $handle = imagecreatefromstring($image->getData()); $prevExc = null; } catch (\Exception $e) { $handle = false; $prevExc = $e; } if ($handle === false) { $msg = "Failed to create image from data string"; throw new SaveFileErrorException($msg, SaveFileErrorException::ERROR_CREATING_RESOURCE, $prevExc); } return $handle; }