diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Upload.php b/lib/Alchemy/Phrasea/Controller/Prod/Upload.php index 8e96e4b69c..4fa1653265 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Upload.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Upload.php @@ -13,6 +13,8 @@ namespace Alchemy\Phrasea\Controller\Prod; use Alchemy\Phrasea\Border\File; use Alchemy\Phrasea\Border\Attribute\Status; +use DataURI; +use DataURI\Exception\Exception as DataUriException; use Entities\LazaretSession; use Silex\Application; use Silex\ControllerProviderInterface; @@ -243,6 +245,30 @@ class Upload implements ControllerProviderInterface $element = 'record'; $message = _('The record was successfully created'); $app['phraseanet.SE']->addRecord($elementCreated); + + // try to create thumbnail from data URI + if ('' !== $b64Image = $request->request->get('b64_image', '')) { + try { + $dataUri = DataURI\Parser::parse($b64Image); + + $fileName = sprintf('%s/tmp/%s.png', $app['root.path'], sprintf('base_64_thumb_%s', $id)); + file_put_contents($fileName, $dataUri->getData()); + + $media = $app['mediavorus']->guess($fileName); + $elementCreated->substitute_subdef('thumbnail', $media, $app); + $app['phraseanet.logger']($elementCreated->get_databox())->log( + $elementCreated, + \Session_Logger::EVENT_SUBSTITUTE, + 'thumbnail', + '' + ); + + unset($media); + $app['filesystem']->remove($fileName); + } catch (DataUriException $e) { + + } + } } else { $params = array('lazaret_file' => $elementCreated); diff --git a/templates/web/prod/upload/upload.html.twig b/templates/web/prod/upload/upload.html.twig index f9cc5145fc..94c331a368 100644 --- a/templates/web/prod/upload/upload.html.twig +++ b/templates/web/prod/upload/upload.html.twig @@ -336,6 +336,7 @@ $(document).ready(function () { UploaderManager.Preview.render(file, function(img){ context.find('.thumbnail .canva-wrapper').prepend(img); UploaderManager.addAttributeToData(uploadIndex, 'image', img); + UploaderManager.addAttributeToData(uploadIndex, 'b64_image', img.toDataURL("image/png") || ''); }); } }); @@ -390,6 +391,11 @@ $(document).ready(function () { $("select", UploaderManager.getSettingsBox()).serializeArray() ); + data.formData.push({ + "name": "b64_image", + "value": data["b64_image"] + }); + //remove current context data.context.remove();