public function testCanGetMimeTypeByExtension() { $mime = 'image/png'; $ext = 'png'; $mime_out = MimeType::getMimeTypeByExtension($ext); $this->assertEquals($mime_out, $mime); }
/** * Set type of File. * * @param string $type * * @return \Dms\Document\Document */ public function setType($type) { $this->type = $type; if ($fmt = MimeType::getExtensionByMimeType($this->type)) { $this->format = $fmt; } return $this; }
/** * Record a document to the Dms. * * @param int $id * * @throws \Exception * * @return \Dms\Document\Manager */ public function writeFile($id = null) { if (null === $this->document) { throw new \Exception('Document does not exist'); } $obj_mime_type = new MimeType(); $is_video = strpos($obj_mime_type->getMimeTypeByExtension($this->document->getFormat()), 'video') === 0 || strpos($this->document->getType(), 'video') === 0; if ($is_video && (null !== $this->getFormat() || null !== $this->getSize() || null !== $this->getPage())) { $this->createPicture(); $this->document = $this->new_document; $this->new_document = null; } // si que resize // si format n'est pas une image ou IN non compatible // convertire d'abort avec uniconv en format compatible imagick puis par defaut mettre un numéro de page 1 si non existant // puis resize imagick avec format de sortie par default (jpeg) if (null !== $this->getSize() && null === $this->getFormat()) { // si format n'est pas une image ou IN non compatible $is_img = strpos($obj_mime_type->getMimeTypeByExtension($this->document->getFormat()), 'image') === 0; if ($is_img && Resize::isCompatible($this->document->getFormat())) { $this->resize(); } else { // convertire d'abort avec uniconv en format compatible imagick puis par defaut mettre un numéro de page 1 si non existant if (!$is_img && $this->page == null) { $this->setPage(1); } $this->setFormat('jpg'); $this->convert(); $this->resize(); } // si que format // vérifier que le format n'est pas le même. // sinonuniconv (voir imagmagick selon le suport est quelité) } elseif (null === $this->getSize() && null !== $this->getFormat()) { if ($this->getFormat() !== $this->getDocument()->getFormat()) { $obj_mime_type = new MimeType(); $is_img = strpos($obj_mime_type->getMimeTypeByExtension($this->document->getFormat()), 'image') === 0; if (!$is_img) { $this->setPage(1); } $this->convert(); } // si resize + format } elseif (null !== $this->getSize() && null !== $this->getFormat()) { // si format compatible IN et OUT avec imagik on utilise imagik pour les deux if (Resize::isCompatible($this->format) && Resize::isCompatible($this->getDocument()->getFormat())) { $this->resize(); $this->getNewDocument()->setId($id); $document_write = $this->getNewDocument(); // si format IN et OUT non compatible avec Imagick // Convertion avec uniconv en format compatible Imagick (jpg) // Resize avec imagick // Convertion OUT avec uniconv } elseif (!Resize::isCompatible($this->format) && !Resize::isCompatible($this->getDocument()->getFormat())) { $tmp_fmt = $this->getFormat(); $this->setFormat('jpg'); $obj_mime_type = new MimeType(); $is_img = strpos($obj_mime_type->getMimeTypeByExtension($this->document->getFormat()), 'image') === 0; if (!$is_img) { $this->setPage(1); } $this->convert(); $this->resize(); $this->setFormat($tmp_fmt); $this->convert(); // si que format IN compatible Imagick // resize avec imagick (jpg) // convertie uniconv } elseif (!Resize::isCompatible($this->format) && Resize::isCompatible($this->getDocument()->getFormat())) { $tmp_fmt = $this->getFormat(); $this->setFormat('jpg'); $this->resize(); $this->setFormat($tmp_fmt); $this->convert(); // si que OUT compatible // convertie uniconv en (jpeg) // resize et format avec imagick } elseif (Resize::isCompatible($this->format) && !Resize::isCompatible($this->getDocument()->getFormat())) { $tmp_fmt = $this->getFormat(); $this->setFormat('jpg'); $obj_mime_type = new MimeType(); $is_img = strpos($obj_mime_type->getMimeTypeByExtension($this->document->getFormat()), 'image') === 0; if (!$is_img) { $this->setPage(1); } $this->convert(); $this->setFormat($tmp_fmt); $this->resize(); } } if ($this->new_document !== null) { $this->document = $this->new_document; } if (null !== $id) { $this->document->setId($id); } $this->document->setStorage($this->getStorage()); $this->document->write(); return $this; }