/** * 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); }