/** * @param FileUploadEvent $event */ public function beforeUpload(FileUploadEvent $event) { if (!$this->belongsToProfile($event->getProfile()->getIdentifier())) { return; } $upload = $event->getFileUpload(); if (!preg_match("/^image/", $upload->getMimeType())) { return; } $helper = new ImageMagickHelper($upload->getRealPath(), $this->tempFiles, $this->commandDefinitions); $tempnam = $helper->execute(); $pinfo = pathinfo($upload->getUploadFilename()); $nupload = new FileUpload($tempnam); $mimeTypes = new MimeTypes(); $extension = $mimeTypes->mimeTypeToExtension($nupload->getMimeType()); $nupload->setOverrideFilename($pinfo['filename'] . '.' . $extension); $event->setFileUpload($nupload); }
/** * @param File $file * @param Version $version * @return array */ protected function doCreateTemporaryVersion(File $file, Version $version) { $version = $this->ensureValidVersion($version); $retrieved = $this->storage->retrieve($file->getResource()); $commandDefinitions = call_user_func_array($this->commandDefinitionsGetter, array($file, $version, $this)); $helper = new ImageMagickHelper($retrieved, $this->tempFiles, $commandDefinitions); return array($version->toString(), $helper->execute()); }
/** * @test */ public function throwsUpWithInvalidSource() { $helper = new ImageMagickHelper(ROOT_TESTS . '/data/illusive-manatee.jpg', new TemporaryFileManager(ROOT_TESTS . '/data/temp')); $this->setExpectedException('Xi\\Filelib\\RuntimeException'); $helper->execute(); }