/** * Erzeugt Thumbnail einer Datei * Bisher implementiert: * - PNG * - JPG * - GIF * - PDF * - OpenOffice Doc odt * @param \AppBundle\Entity\File $file [description] * @return [type] [description] */ public function createThumbnail(\AppBundle\Entity\File $file) { #print __METHOD__; #print $file->getMimeType(); #die; switch ($file->getMimeType()) { case 'application/pdf': // sudo apt-get install imagemagick ghostscript $filename = sha1(uniqid(mt_rand(), true)) . '.png'; $cmd = sprintf('convert -thumbnail 200x -background white -alpha remove "%s[0]" "%s"', $this->storage . $file->getPath() . '/' . $file->getFilename(), $this->thumbnailsPath . $filename); exec($cmd, $output, $return_var); if ($return_var != 0) { print "FEHLER BEIM ERZEUGEN DES THUMBNAILS " . __METHOD__; } else { $file->setThumbnail($filename); } break; case 'application/vnd.oasis.opendocument.text': // https://wiki.ubuntuusers.de/OpenDocument_Thumbnails/ $filename = sha1(uniqid(mt_rand(), true)) . '.png'; $cmd = sprintf('/usr/bin/gsf-office-thumbnailer -i "%s" -o "%s" -s 800', $this->storage . $file->getPath() . '/' . $file->getFilename(), $this->thumbnailsPath . $filename); exec($cmd, $output, $return_var); if ($return_var != 0) { print "FEHLER BEIM ERZEUGEN DES THUMBNAILS " . __METHOD__; } else { $source_image = imagecreatefrompng($this->thumbnailsPath . $filename); $this->_makeThumbnail($file, $source_image, 200); unlink($this->thumbnailsPath . $filename); } break; case 'image/png': $src = $this->storage . $file->getPath() . '/' . $file->getFilename(); $source_image = imagecreatefrompng($src); $this->_makeThumbnail($file, $source_image, 200); break; case 'image/jpeg': $src = $this->storage . $file->getPath() . '/' . $file->getFilename(); $source_image = imagecreatefromjpeg($src); $this->_makeThumbnail($file, $source_image, 200); break; case 'image/gif': $src = $this->storage . $file->getPath() . '/' . $file->getFilename(); $source_image = imagecreatefromgif($src); $this->_makeThumbnail($file, $source_image, 200); break; } }