/** * @param string $filename * @return Logo */ protected function createLogo($filename) { $logo = new Logo(); $logo->setImage($this->createResource($filename)); $logo->setCreatedAt(new DateTime()); return $logo; }
/** * @param resource $logo * @param string $id * @param int $width * @param int $height * @param Request $request * @param Response $response */ public function resize(Logo $logo, $width, $height, Request $request, Response $response) { $path = $this->getPath('logo_' . $logo->getId(), $width, $height); $response->setPublic(); $response->setContentType($logo->getMimeType()); $response->setLastModified($logo->getCreatedAt()); if ($response->isNotModified($request)) { return; } if (file_exists($path)) { return file_get_contents($path); } $image = $this->factory->createFromResource($logo->getImage()); return $this->getImageContent($image, $path, $width, $height, array($this->resizer, 'scale')); }
<?php require __DIR__ . '/../boot.php'; use PHPSC\Conference\Domain\Entity\Logo; if (!isset($argv[1]) || !file_exists($argv[1])) { echo 'Valid image path must be informed' . PHP_EOL; exit(1); } $logo = new Logo(); $logo->setImage(fopen($argv[1], 'rb')); $logo->setCreatedAt(new \DateTime()); $container = (require __DIR__ . '/../config/di-container.php'); $em = $container->get('entityManager'); $em->persist($logo); $em->flush();