Ejemplo n.º 1
0
 public static function rotate_image(Image $image, $degrees)
 {
     if (!$image->getAbsolutePath()) {
         return false;
     }
     $command = implode(" ", array(self::get_convert(), $image->getAbsolutePath(), sprintf('-rotate %d', $degrees), $image->getAbsolutePath()));
     exec($command);
 }
Ejemplo n.º 2
0
 /**
  * Adds image to Album
  * @param string $image_file
  * @param string $default_title
  * @param Entity\Album $album
  * @param array $options
  * @param UserInterface $user
  */
 private function addImageToAlbum($image_file, $default_title, Entities\Album $album, array $options = array(), UserInterface $user = null)
 {
     $image = new Entities\Image();
     $image->setAlbum($album);
     $image->setFilename(sprintf("%s.%s", md5(uniqid()), strtolower(pathinfo($default_title ?: $image_file, PATHINFO_EXTENSION))));
     $name = pathinfo($image_file, PATHINFO_FILENAME);
     if ($default_title) {
         $name = $default_title;
     }
     if (@$options['default_name']) {
         $name = $options['default_name'];
     }
     $image->setName($name);
     // create folder if not exists
     if (!file_exists($image->getUploadRootDir())) {
         mkdir($image->getUploadRootDir(), 0777, true);
         chmod($image->getUploadRootDir(), 0777);
     }
     copy($image_file, $image->getAbsolutePath());
     $image->setUser($user);
     $exif = new ExifParsers\ExifDataParser(@read_exif_data($image->getAbsolutePath()));
     $exif_parsed = $exif->getParsed();
     $datetime = null;
     try {
         $datetime = new \DateTime(@$exif_parsed['DateTimeOriginal']);
     } catch (\Exception $e) {
         $datetime = new \DateTime($exif_parsed['DateTime']);
     }
     $image->setTakenAt($datetime);
     Converter::exif_rotate($image->getAbsolutePath(), @$exif_parsed['IFD0']['Orientation']);
     $iptc = new ExifParsers\IptcDataParser($image->getAbsolutePath());
     $image->setExifData($exif_parsed);
     if (@$options['keywords']) {
         $keywords = array_filter(array_map('trim', explode(',', $options['keywords'])));
         foreach ($keywords as $keyword) {
             $tag = $this->tag($keyword);
             $image->addTag($tag);
         }
     }
     if (@$options['private']) {
         $image->setPrivate(true);
     }
     $this->em->persist($image);
 }
Ejemplo n.º 3
0
 /**
  * @param Image $image
  */
 protected function drop_thumbnails(Image $image)
 {
     $finder = new Finder();
     foreach ($finder->name($image->getFilename())->in($this->container->getParameter('web_root')) as $file) {
         /** @var \SplFileInfo $file */
         unlink($file->getPathname());
     }
 }
Ejemplo n.º 4
0
 /**
  * @Route("/{slug}/upload", name="album.upload")
  * @Template
  * @Secure(roles="ROLE_USER")
  *
  * @param Album $album
  *
  * @throws AccessDeniedException
  * @return array|\Symfony\Component\HttpFoundation\Response
  */
 public function uploadAction(Album $album)
 {
     if (!$album->getUser()->equals($this->getUser())) {
         throw new AccessDeniedException();
     }
     $image = new Image();
     $image->setAlbum($album);
     $image->setUser($this->getUser());
     $form = $this->createForm(new Forms\ImageType(), $image);
     if ($this->getRequest()->isMethod('POST')) {
         $form->submit($this->getRequest());
         if ($form->isValid()) {
             /** @var UploadManager $manager */
             $manager = $this->get('gallery.upload_manager');
             return $manager->save($image);
         }
         return new Response('', 500);
     }
     return array('form' => $form->createView(), 'album' => $album);
 }
Ejemplo n.º 5
0
 /**
  * @Route("/{album}/{id}", name="image.show")
  * @Template
  */
 public function showAction(Image $image)
 {
     return array('image' => $image, 'album' => $image->getAlbum());
 }