From 109d59b1864cfaf37d8f96df605deb6b424ed947 Mon Sep 17 00:00:00 2001 From: Can OMUR Date: Sun, 2 Jun 2019 21:53:15 +0200 Subject: [PATCH 1/3] fixes #48 and started to work on #56 --- Form/Type/CroppableImageType.php | 3 ++- Handler/UploadHandler.php | 3 ++- README.md | 13 +++++++++++++ Resources/public/js/comur.imagelibrary.js | 16 +++++++++++++--- .../views/Form/croppable_image_modal.html.twig | 2 +- composer.json | 2 +- 6 files changed, 32 insertions(+), 7 deletions(-) diff --git a/Form/Type/CroppableImageType.php b/Form/Type/CroppableImageType.php index 02edefc7..5f06e8a1 100644 --- a/Form/Type/CroppableImageType.php +++ b/Form/Type/CroppableImageType.php @@ -41,7 +41,8 @@ class CroppableImageType extends AbstractType 'aspectRatio' => true, 'cropRoute' => 'comur_api_crop', 'forceResize' => false, - 'thumbs' => null + 'thumbs' => null, + 'disable' => false ); // public function getParent() diff --git a/Handler/UploadHandler.php b/Handler/UploadHandler.php index 4b6349ef..8019bb16 100755 --- a/Handler/UploadHandler.php +++ b/Handler/UploadHandler.php @@ -937,7 +937,8 @@ protected function imagemagick_create_scaled_image($file_name, $version, $option } protected function get_image_size($file_path) { - if ($this->options['image_library']) { + // Disabled cause not works with animated gifs ans getimagesize works well with everything + if (false && $this->options['image_library']) { if (extension_loaded('imagick')) { $image = new \Imagick(); try { diff --git a/README.md b/README.md index 82fb1232..516b78e3 100644 --- a/README.md +++ b/README.md @@ -279,6 +279,7 @@ Use widget in your forms (works with SonataAdmin too) to create a simple image f 'generateFilename' => true //optional ), 'cropConfig' => array( + 'disable' => false, //optional 'minWidth' => 588, 'minHeight' => 300, 'aspectRatio' => true, //optional @@ -412,6 +413,10 @@ Route called to send uploaded file. It's recommended to not change this paramete ### uploadDir (required) ### +**Since 2.0.3** + +**Replaces uploadUrl removed because a security issue (see #80)** + Public dir relative path to directory where put uploaded image. I recommend you to create a function in your entity and call it like it's shown in the example: ```PHP @@ -483,6 +488,14 @@ This parameter is used to generate an uniq file name. Setted to false, it will k ## cropConfig ## +### disable (optional) ### + +**Since 2.0.4** + +Disables cropping feature and saves directly original image + +**Default value:** false + ### minWidth (optional) ### Minimum with of desired image. diff --git a/Resources/public/js/comur.imagelibrary.js b/Resources/public/js/comur.imagelibrary.js index 56a96d94..920ca85b 100644 --- a/Resources/public/js/comur.imagelibrary.js +++ b/Resources/public/js/comur.imagelibrary.js @@ -88,16 +88,26 @@ function initializeImageManager(id, options, cb){ // console.log('uploaded'); if(data.result['image_upload_file'][0].error){ $('#image_upload_widget_error').text(data.result['image_upload_file'][0].error); - $('#image_upload_widget_error').parent().removeClass('hidden'); + $('#image_upload_widget_error').parent().show(); } else{ $('#image_upload_widget_error').text(''); - $('#image_upload_widget_error').parent().addClass('hidden'); + $('#image_upload_widget_error').parent().hide(); // console.log(data.result, data.result['image_upload_file']); // $('#image_preview img').remove(); // $('#image_preview').html(''); $('#selected_image').val(data.result['image_upload_file'][0].name); - initJCrop(id, options); + if (options.cropConfig.disable) { + $('#'+id).val(data.result['image_upload_file'][0].name); + $('#image_preview_image_'+id).html(''); + reinitModal(); + cb({ + previewSrc: '/' + options.uploadConfig.webDir + '/' + data.result['image_upload_file'][0].name +'?'+ new Date().getTime(), + filename: data.result['image_upload_file'][0].name + }); + } else { + initJCrop(id, options); + } } }, diff --git a/Resources/views/Form/croppable_image_modal.html.twig b/Resources/views/Form/croppable_image_modal.html.twig index a79fa3e7..f2cb5cf0 100644 --- a/Resources/views/Form/croppable_image_modal.html.twig +++ b/Resources/views/Form/croppable_image_modal.html.twig @@ -74,7 +74,7 @@
-