GithubHelp home page GithubHelp logo

comur / comurimagebundle Goto Github PK

View Code? Open in Web Editor NEW
105.0 13.0 76.0 12.14 MB

Image upload / crop bundle for Symfony2

PHP 19.69% JavaScript 33.00% CSS 43.96% Twig 3.36%
crop-image gallery-widget gallery image-widget thumbs gallery-images resized-images php symfony image-admin

comurimagebundle's Introduction

ComurImageBundle

Introduction

Image upload / crop bundle for Symfony2

This bundle helps you easily create an image upload / crop field in your forms. You don't need to use any type of generator or there is no other requirements. It uses bootstrap to make it look well but you can use any other css to customize it.

It uses beautiful Jquery File Upload to upload files (original UploadHandler has been modified to add namespace and a new config parameter to generate random filenames) and JCrop to let you crop uploaded images.

Works perfectly with ComurContentAdminBundle. If you don't know what it is, take a look and you will be surprised ! This bundle helps you create beautiful admins with inline editing capabilities with ease !!

If this bundle helps you reduce time to develop, you can pay me a cup of coffee ;)

coffee

coffee

Which version use

v SF v Bundle
2.x 1.x
3.x 2.x
4.x 2.x

⚠️ Use 1.X releases for compatibility with bootstrap 2.x.

⚠️ Compatibility with bootstrap 2.X is no more maintained

⚠️ I won't maintain Symfony 2 anymore, I will only merge PR on 1.2 branch for compatibility with SF2. If you need something you can always create a PR and I will merge it.

⚠️ Animated gif cropping is only available with imagick

Changelog

Please see on CHANGELOG.md

Screen shots

Here are some screen shots since i didn't have time to put a demo yet:

Simple Image widget

alt tag

Gallery widget

alt tag

Upload image screen

alt tag

Select image from library screen

alt tag

Crop image screen

alt tag

Change gallery image order screen

alt tag

Dependencies

Bundle uses following packages in assets (see in bower.json) :

Package version optional
blueimp-file-upload ^9.31.0 false
Jcrop jcrop#0.9.15 false
jquery ^3.4.1 true
holderjs ^2.9.6 true
bootstrap ^4.3.1 true
Font-Awesome FortAwesome/Font-Awesome#^5.8.2 true

You can disable auto including of these assets by using modal template inclusion parameters (see step4)

Installation

Applications that use Symfony Flex

Step 1: Download the Bundle

Open a command console, enter your project directory and execute:

$ composer require comur/content-admin-bundle

Step 2: Enable other bundles

Then, enable the bundle by adding it to the list of registered bundles in the config/bundles.php file of your project:

// config/bundles.php

return [
            // ...
            Comur\ImageBundle\ComurImageBundle::class => ['all' => true],
            FOS\JsRoutingBundle\FOSJsRoutingBundle::class => ['all' => true],
            JMS\TranslationBundle\JMSTranslationBundle::class => ['all' => true],
        ];

Step 3: Create routing files

Two of the bundles provides routes, which must be enabled by creating these files:

# config/routes/fos_js_routing.yaml
fos_js_routing:
    resource: "@FOSJsRoutingBundle/Resources/config/routing/routing-sf4.xml"
# config/routes/comur_image.yaml
comur_image:
    resource: "@ComurImageBundle/Resources/config/routing.yml"
    prefix:   /

Applications that don't use Symfony Flex

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require comur/content-admin-bundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable the Bundle and dependency bundles

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:

// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = [
            // ...
            new Comur\ImageBundle\ComurImageBundle(),
            new FOS\JsRoutingBundle\FOSJsRoutingBundle(),
            new JMS\TranslationBundle\JMSTranslationBundle(),
        ];

        // ...
    }

    // ...
}

Step 3: Add this route to your routing.yml:

    # app/config/routing.yml
    fos_js_routing:
      resource: "@FOSJsRoutingBundle/Resources/config/routing/routing.xml"
      
    comur_image:
        resource: "@ComurImageBundle/Resources/config/routing.yml"
        prefix:   /

Step 4: Add Modal template after body tag of your layout:

  <body>
  {% include "ComurImage/Form/croppable_image_modal.html.twig"%}
  …
  </body>

Note: This template includes many script and styles including jquery and bootstrap. You can use following parameters to avoid jquery and/or bootstrap being included:

{% include "ComurImage/Form/croppable_image_modal.html.twig" with {'include_fontawesome': false, 'include_jquery': false, 'include_bootstrap': false, 'bootstrap_version': 4} %}

⚠️ bootstrap_version is used for bootstrap 4 compatibility issues. If you include bootstrap using bundle, it will use bootstrap 4 and set it to 4 automatically. If you need to use bootstrap 3, remove bootstrap_version parameter or put 3.

Step 5: Do not forget to put FOSJSRoutingBundle script in your :

  <script src="{{ asset('bundles/fosjsrouting/js/router.js') }}"></script>
  <script src="{{ path('fos_js_routing_js', {"callback": "fos.Router.setData"}) }}"></script>

💥 That's it !

Configuration

All parameters are optional:

  comur_image:
    config:
      cropped_image_dir: 'cropped'
      thumbs_dir: 'thumbnails'
      media_lib_thumb_size: 150
      public_dir: '%kernel.project_dir%/public'
      translation_domain: 'ComurImageBundle'
      gallery_thumb_size: 150
      gallery_dir: 'gallery'

cropped_image_dir

It's used to determine relative directory name to put cropped images (see above).

Default value: 'cropped'

thumbs_dir

It's used to determine relative directory name to put thumbnails (see above).

Default value: 'thumbnails'

media_lib_thumb_size

It's used to determine thumbnails size in pixels (squares) used in media library.

Default value: 150

public_dir

Path to your public directory. It's used to check thumb existence in thumb twig helper and your upload dir will be relative to this dir (since security fix #80)

Default value: '%kernel.project_dir%/public'

translation_domain

Domain name for translations. For instance two languages are provided (en & fr). To override the domain name, change this parameter to whatever you want.

Default value: 'ComurImageBundle'

gallery_thumb_size

That's the image size in pixels that you want to show in gallery widget. Gallery widget will automaticaly create square thums having this size and show them in the gallery widget.

Default value: 150

gallery_dir

That's the gallery directory name. The widget will store all gallery images in a specific directory inside the root directory that you will give when you will add the widget to your forms.

For eg. if you put 'uploads/images' as webDir when you add the widget, gallery images will be stored in 'uploads/images/[gallery_dir]'. This is added to make gallery use easier so you don't have to add new functions to your entities to get gallery dirs.

Usage

There are two widgets provided with this bundle. They both have exacly same config parameters.

Image widget

Use widget in your forms (works with SonataAdmin too) to create a simple image field :

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
      // get your entity related with your form type
      $myEntity = $builder->getForm()->getData();
      ...
      ->add('image', CroppableImageType::class, array(
          'uploadConfig' => array(
              'uploadRoute' => 'comur_api_upload',     //optional
              'uploadDir' => $myEntity->getUploadDir(), // required - see explanation below (you can also put just a dir name relative to your public dir)
              // 'uploadUrl' => $myEntity->getUploadRootDir(),       // DEPRECATED due to security issue !!! Please use uploadDir. required - see explanation below (you can also put just a dir path)
              'webDir' => $myEntity->getUploadDir(),        // required - see explanation below (you can also put just a dir path)
              'fileExt' => '*.jpg;*.gif;*.png;*.jpeg',   //optional
              'maxFileSize' => 50, //optional
              'libraryDir' => null,             //optional
              'libraryRoute' => 'comur_api_image_library', //optional
              'showLibrary' => true,             //optional
              'saveOriginal' => 'originalImage',      //optional
              'generateFilename' => true      //optional
          ),
          'cropConfig' => array(
              'disable' => false,      //optional
              'minWidth' => 588,
              'minHeight' => 300,
              'aspectRatio' => true,         //optional
              'cropRoute' => 'comur_api_crop',   //optional
              'forceResize' => false,       //optional
              'thumbs' => array(           //optional
                array(
                  'maxWidth' => 180,
                  'maxHeight' => 400,
                  'useAsFieldImage' => true  //optional
                )
              )
          )
      ))

You need to create a field (named image in this example but you can choose whatever you want):

  // YourBundle\Entity\YourEntity.php
  
  ...
  
    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    protected $image;
    
    ...

And create your functions in your entity to have directory paths, for ex :

  /* DEPRECATED, Use upload dir
  public function getUploadRootDir()
  {
      // absolute path to your directory where images must be saved
      return __DIR__.'/../../../../../web/'.$this->getUploadDir();
  }*/
  
  /* Directory relative to your public dir (see public_dir in configuration)
  public function getUploadDir()
  {
      return 'uploads/myentity';
  }
  
  public function getWebPath()
  {
      return null === $this->image ? null : '/'.$this->getUploadDir().'/'.$this->image;
  }

That's all ! This will add an image preview with an edit button in your form and will let you upload / select from library and crop images without reloading the page.

To save original image path, you have to create another field and name it same as saveOriginal parameter:

  // YourBundle\Entity\YourEntity.php/**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    protected $originalImage;
    
    …

I will put a demo soon…

Gallery widget

Use widget in your forms (works with SonataAdmin too) to create a sortable list of images (so a gallery :)) stored in an array typed field :

  ->add('gallery', CroppableGalleryType::class, array(
    //same parameters as comur_image
  ))

And create your array typed field for storing images in it. Doctrine (or other ORM) will serialize this field to store it as string in the DB.

  // YourBundle\Entity\YourEntity.php
  
  ...
  
    /**
     * @ORM\Column(type="array", nullable=true)
     */
    protected $gallery;
    
    ...
    

And create your functions in your entity to have directory paths, for ex :

    /* DEPRECATED, Use upload dir
    public function getUploadRootDir()
    {
        // absolute path to your directory where images must be saved
        return __DIR__.'/../../../../../web/'.$this->getUploadDir();
    }*/

    public function getUploadDir()
    {
        return 'uploads/myentity';
    }

    public function getWebPath()
    {
        return null === $this->image ? null : '/'.$this->getUploadDir().'/'.$this->image;
    }

That's all ! This will create a widget like on the following image when you will use it in your forms. You can also reorder them since php serialized arrays are ordered:

Gallery images will be stored in uploadDir / gallery_dir (default is gallery). Cropped images will be stored in uploadDir / gallery_dir / cropped_dir (same as image widget) and thumbs in uploadDir / gallery_dir / cropped_dir / thumb_dir with specified width. So if you pu

uploadConfig

uploadRoute (optional)

Route called to send uploaded file. It's recommended to not change this parameter except if you know exactly what you do.

Default value: comur_api_upload

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:

    /* DEPRECATED, Use upload dir
    public function getUploadRootDir()
    {
        // absolute path to your directory where images must be saved
        return __DIR__.'/../../../../../web/'.$this->getUploadDir();
    }*/

    public function getUploadDir()
    {
        return 'uploads/myentity';
    }

    public function getWebPath()
    {
        return null === $this->image ? null : '/'.$this->getUploadDir().'/'.$this->image;
    }

webDir (required)

Url used to show your image in templates, must be relative url. If you created related functions as explained in uploadDir section, then you can user getWebPath() function for webDir parameter.

fileExt (optional)

Permitted image extensions.

Default value: '.jpg;.gif;.png;.jpeg'

maxFileSize (optional)

Permitted maximum image weight in MB.

Default value: 50 (50Mb)

libraryDir (optional)

Directory to look into for images to show in image library.

Default value: uploadDir

libraryRoute (optional)

Route called to get images to show in library. I recommend you to not change this parameter if you don't know exactly what it does.

Default value: comur_api_image_library

showLibrary (optional)

Set this to false if you don't want the user see existing images in libraryDir.

Default value: true

saveOriginal (optional)

Use this parameter if you want to save original file's path (for eg. to show big image in a lightbox). You have to put property name of your entity and the bundle will use it to save original file path in it.

Attention: This parameter is disabled for gallery for instance. It will be implemented soon.

Default value: false

generateFilename (optional)

This parameter is used to generate an uniq file name. Setted to false, it will keep the original filename.

Default value: true

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.

Default value: 1

minHeight (optional)

Minimum height of desired image.

Default value: 1

aspectRatio (optional)

True to aspect ratio of crop screen.

Default value: true

cropRoute (optional)

Route to crop action. I recommend you to not change this parameter if you don't know exactly what it does.

Default value: comur_api_crop

forceResize (optional)

If true, system will resize image to fit minWidth and minHeight. Default value: false

thumbs (optional)

Array of thums to create automaticly. System will resize images to fit maxWidth and maxHeight. It will put them in "uploadDir/cropped_images_dir/thumbs_dir/widthxheight-originalfilename.extension" so you can use included Thumb Twig extension to get them, ex:

{# your_themplate.html.twig #}
<img src="{{ entity.imagePath|thumb(45, 56) }}"
      

New in 0.2.2: You can use 'useAsFieldImage' option to use this thumb as image field's preview (in your form you will see this thumb instead of original cropped image). Usefull when you have big cropped images.

SECURITY

Please read following documentation about upload best practices: https://github.com/blueimp/jQuery-File-Upload/blob/master/SECURITY.md

TODO LIST

  • Create tests
  • Add more comments in the code
  • Think about removed image deletion (for now images are not deleted, you have to care about it by yourself…)
  • Update existing images list dynamicly after an image upload
  • Add javascript events (in progress)

comurimagebundle's People

Contributors

anthonyherve avatar barthy-koeln avatar benjaminbonhouredc avatar bryant1410 avatar carlosequiz avatar carolinasolfernandez avatar comur avatar jarjak avatar jontorrado avatar lexxpavlov avatar metadan avatar thelem avatar zoupme avatar zozoh94 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

comurimagebundle's Issues

modal

after install with composer click add or edit not responding
and modal not open
plz help me.

Setting jpeg quality

Crop engine set jpeg quality to 100 (as mentioned in EXIF of result image). I found option 'jpeg_quality' in UploadHandler.php at 883 line, but setting this option to field definition doesn't do any changes.
I tried to set 'jpeg_quality' at these places:

->add('picture', 'comur_image', array(
                    'required' => false,
                    'uploadConfig' => array(
                        'uploadRoute' => 'comur_api_upload',
                        'uploadUrl' => $object->getPictureUploadRootDir(),
                        'webDir' => $object->getPictureUploadDir(),
                        'fileExt' => '*.jpg;*.gif;*.png;*.jpeg',
                        'libraryDir' => null,
                        'libraryRoute' => 'comur_api_image_library',
                        'showLibrary' => true,
                        'saveOriginal' => 'originalPicture'
                    ),
                    'cropConfig' => array(
                        'minWidth' => 640,
                        'minHeight' => 480,
                        'jpeg_quality' => 30, // jpeg_quality ?
                        'aspectRatio' => true,
                        'cropRoute' => 'comur_api_crop',
                        'forceResize' => false,
                        'thumbs' => array(
                             array(
                                'maxWidth' => 180,
                                'maxHeight' => 400,
                                'jpeg_quality' => 30, // jpeg_quality ?
                                'useAsFieldImage' => true  //optional
                             )
                        )
                    )
                ))

It will be logical to set jpeg_quality inside thumbs array, for separate option for all thumbs.

mkdir: permission denied

Having an issue when modal appear, i am not able to upload an img, Chrome gives me an error 500, mkdir: permission denied.
I work under mac os 10.7.5 (Lyon), I have been searching around and tried a couple of thing.
I gave apache the permission is needed:
sudo chown -R _www:_www web/uploads/
chmod -R g+rw web/uploads/
sudo chgrp -R _www web/uploads/

I tried to put my username in _www group:
sudo dseditgroup -o edit -a $USER -t user _www

And put _www in wheel:
sudo dseditgroup -o edit -a _www -t user wheel

But nothing work, do you have any idea on how to solve this?

INFO - Matched route "comur_api_image_library" (parameters: "_controller": "Comur\ImageBundle\Controller\UploadController::getLibraryImagesAction", "_route": "comur_api_image_library")
INFO - Populated SecurityContext with an anonymous Token
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::configure".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DumpListener::configure".
DEBUG - Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\FragmentListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\TranslatorListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "NewBlog\AdminBundle\Listener\DoctrineExtensionListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Bundle\AsseticBundle\EventListener\RequestListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "NewBlog\AdminBundle\Listener\DoctrineExtensionListener::onLateKernelRequest".
DEBUG - Notified event "kernel.controller" to listener "Symfony\Bundle\FrameworkBundle\DataCollector\RouterDataCollector::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Symfony\Component\HttpKernel\DataCollector\RequestDataCollector::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ControllerListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ParamConverterListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\HttpCacheListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\SecurityListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelController".
CRITICAL - Uncaught PHP Exception Symfony\Component\Debug\Exception\ContextErrorException: "Warning: mkdir(): Permission denied" at /Users/tamarabollinger/Sites/new_blog/vendor/comur/image-bundle/Comur/ImageBundle/Controller/UploadController.php line 277
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::configure".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DumpListener::configure".
DEBUG - Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\FragmentListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\TranslatorListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "NewBlog\AdminBundle\Listener\DoctrineExtensionListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Bundle\AsseticBundle\EventListener\RequestListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "NewBlog\AdminBundle\Listener\DoctrineExtensionListener::onLateKernelRequest".
DEBUG - Notified event "kernel.controller" to listener "Symfony\Bundle\FrameworkBundle\DataCollector\RouterDataCollector::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Symfony\Component\HttpKernel\DataCollector\RequestDataCollector::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ControllerListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ParamConverterListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\HttpCacheListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\SecurityListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelController".

Problems overriding fields template

Hi,

I'm facing some troubles overriding fields.html.twig

I've already copied ComurImageBundle/views/Form templates and place it into app/Resources folder.

In line 91 I want to override
i class="icon icon icon-remove" data-delete="image"
to:
i class="glyphicon glyphicon-remove-circle" data-delete="image"

But the template is always rendering class="icon icon icon-remove" instead class="glyphicon glyphicon-remove-circle" previously defined in app/Resources/ComurImageBundle/views/Form/fields.html.twig

Any thoughts?

Uncaught SyntaxError: Unexpected token i

Hello i having this problem: "Uncaught SyntaxError: Unexpected token i" when I click on the "Edit" button where I included the image widget in my view.

I use the branch : "comur/image-bundle": "1.0.*@dev"
and bootstrap 3.

In my layout I used {% include "ComurImageBundle:Form:croppable_image_modal.html.twig" with {'include_jquery': false, 'include_bootstrap': false} %} since i'm already including a jquery script and bootstrap 3. I made sure the include was after the jquery script.

When i click on the error msg in the navigator console. i don't get a specific line number, so i have no idea where the error is coming from.

edit image already saved

Hi
i want to edit image profile using ComurImageBundle but i don't know what should i write is any documentation or any code already used.thanks

Modal window not responsive

Hi.

the modal is not responsive, and in mobiles is not functional. There is a fixed width to 850px, but i don't know why. There is a reason for that? If you delete it, the modal works perfectly.

Cheers,
Sergio

Generates filename when i use 'generateFilename' => false

Here is my entityType.php code

->add('imgName', 'comur_image', array( 'uploadConfig' => array( 'generateFilename' => false, 'showLibrary' => false, 'uploadUrl' => $myEntity->getUploadRootDir(), 'webDir' => $myEntity->getUploadDir(), 'fileExt' => '*.jpg;*.gif;*.png;*.jpeg', ), 'cropConfig' => array( 'minWidth' => 200, 'minHeight' => 200, 'aspectRatio' => true, 'cropRoute' => 'comur_api_crop', 'forceResize' => true, ) ))

So with or with the 'generateFilename' => false set to true or false it always sets the filename to a super long ugly string like 271ed3895ece9653fb0c31a6793142b8e811d404.jpg

Uncaught TypeError: undefined is not a function

Hello,

i have all config write but with the type Single image or gallery i have the same error in console :

Uncaught TypeError: undefined is not a function comur.imagelibrary.js:60
initializeImageManager comur.imagelibrary.js:60
(anonymous function) (index):347
jQuery.event.dispatch 772ad89_part_5.js:1
elemData.handle 772ad89_part_5.js:1
POST http://127.0.0.1:8080/app_dev.php/image-library 500 (Internal Server Error) 772ad89_part_5.js:1
send 772ad89_part_5.js:1
jQuery.extend.ajax 772ad89_part_5.js:1
initializeImageManager comur.imagelibrary.js:27
(anonymous function) (index):347
jQuery.event.dispatch 772ad89_part_5.js:1
elemData.handle

I have allright config, and this bundle is seems to be really good 👍

Working with sonata media

Could this library potentially work with sonata media ?
May be as some extension as CoopTilleulsCKEditorSonataMediaBundle

Animated GIF support

I have an error with size of gif.
In UploaderHandler line 944 pingImage no return good value for width and height file
I test with this picture

test

Error 404 uplaod image

Hello,
I have a problem to upload the image to the server. I have installed the bundle, pop up displays correctly when I selected an image, it is uploaded to the server, but in return it does not appear in the pop up.
Looking at the console I noticed an error in routing. The URL I use to upload the files is as follows:

http: //localhost/congo-job/cj-symf/web/app_dev.php/demo/imageTest/new

but in the console I get this error:

Failed to load resource: the server responded with a status of 404 (Not Found)

http: //localhost/uploads/test/5bbfd314905a0b267d0b3f5c36ef0f8897415f42.jpg 1435321243541?

I already noticed that the path of the url are not correct.
Can anyone help me?

My entity :

Hello,
I have a problem to upload the image to the server. I have installed the bundle, pop up displays correctly when I selected an image, it is uploaded to the server, but in return it does not appear in the pop up.
Looking at the console I noticed an error in routing.
The URL I use to upload the files is as follows:

http: //localhost/congo-job/cj-symf/web/app_dev.php/demo/imageTest/new

but in the console I get this error:

Failed to load resource: the server responded with a status of 404 (Not Found)

http: //localhost/uploads/test/5bbfd314905a0b267d0b3f5c36ef0f8897415f42.jpg 1435321243541?

I already noticed that the path of the url are not correct.

Can anyone help me?

Hello,
I have a problem to upload the image to the server. I have installed the bundle, pop up displays correctly when I selected an image, it is uploaded to the server, but in return it does not appear in the pop up.
Looking at the console I noticed an error in routing.
The URL I use to upload the files is as follows:

http: //localhost/congo-job/cj-symf/web/app_dev.php/demo/imageTest/new

but in the console I get this error:

Failed to load resource: the server responded with a status of 404 (Not Found)

http: //localhost/uploads/test/5bbfd314905a0b267d0b3f5c36ef0f8897415f42.jpg 1435321243541?

I already noticed that the path of the url are not correct.

Can anyone help me?

id; } /** * Set photo * * @param string $photo * @return Image */ public function setPhoto($photo) { $this->photo = $photo; return $this; } /** * Get photo * * @return string */ public function getPhoto() { return $this->photo; } public function getUploadRootDir() { // absolute path to your directory where images must be saved return str_replace("\\", '\\\\', __DIR__.'/../../../../web/'.$this->getUploadDir()); } public function getUploadDir() { return 'uploads/test'; } public function getAbsolutePath() { return null === $this->photo ? null : $this->getUploadRootDir().'/'.$this->photo; } public function getWebPath() { return null === $this->photo ? null : '/'.$this->getUploadDir().'/'.$this->photo; } /** * Set originalImage * * @param string $originalImage * @return Image */ public function setOriginalImage($originalImage) { $this->originalImage = $originalImage; return $this; } /** * Get originalImage * * @return string */ public function getOriginalImage() { return $this->originalImage; } ``` } ImageType: getForm()->getData(); ``` $builder ->add('photo', 'comur_image', array( 'uploadConfig' => array( 'uploadRoute' => 'comur_api_upload', //optional 'uploadUrl' => $myEntity->getUploadRootDir(), // required - see explanation below (you can also put just a dir path) 'webDir' => $myEntity->getUploadDir(), // required - see explanation below (you can also put just a dir path) 'fileExt' => '*.jpg;*.gif;*.png;*.jpeg', //optional //'libraryDir' => null, //optional 'libraryRoute' => 'comur_api_image_library', //optional 'showLibrary' => true, //optional 'saveOriginal' => 'originalImage' //optional ), 'cropConfig' => array( 'minWidth' => 200, 'minHeight' => 200, 'aspectRatio' => true, //optional 'cropRoute' => 'comur_api_crop', //optional 'forceResize' => false, //optional 'thumbs' => array( //optional array( 'maxWidth' => 200, 'maxHeight' => 200, 'useAsFieldImage' => true //optional ) ) ) )) ; } /** * @param OptionsResolverInterface $resolver */ public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array( 'data_class' => 'Acme\DemoBundle\Entity\Image' )); } /** * @return string */ public function getName() { return 'acme_demobundle_image'; } ``` } Image\new.html.twig : {% extends '::base.html.twig' %} {% block javascripts %} ``` <script src="{{ asset('bundles/fosjsrouting/js/router.js') }}"></script> <script src="{{ path('fos_js_routing_js', {"callback": "fos.Router.setData"}) }}"></script> ``` {% endblock %} {% block body -%} ``` {% include "ComurImageBundle:Form:croppable_image_modal.html.twig"%}

Image creation

{{ form(form) }} {% endblock %}

Override uploadRoute Issue

How can I change uploadRoute to my custom controller?

I have changed uploadRoute to my custom controller but it doesn't work.

$myEntity = $builder->getForm()->getData();

$builder->add('photoName', 'comur_image', array(
'uploadConfig' => array(
'uploadRoute' => 'custom_route', //optional
'uploadUrl' => $myEntity->getUploadRootDir(), // required - see explanation below (you can also put just a dir path)
'webDir' => $myEntity->getUploadDir(), // required - see explanation below (you can also put just a dir path)
'fileExt' => '.jpg;.gif;.png;.jpeg', //optional
'libraryDir' => null, //optional
'libraryRoute' => 'comur_api_image_library', //optional
'showLibrary' => true, //optional
'saveOriginal' => 'photoName' //optional
),
'cropConfig' => array(
'minWidth' => 100,
'minHeight' => 100,
'aspectRatio' => false, //optional
'cropRoute' => 'comur_api_crop', //optional
'forceResize' => true, //optional
'thumbs' => array(//optional
array(
'maxWidth' => 500,
'maxHeight' => 300,
'useAsFieldImage' => true //optional
)
)
)
))
;

Problem with jCrop

Hello !

I hava a problem when I want to crop my uploaded image.
First, I don't see all my image.
Second, I can't move the jCrop zone and the jCrop zone have a very little height.
I hav also a list bullet at the left...

I use configuration from READMME.md.

What am I doing wrong ? Thank you for your help.

jcrop_problem

Is there way to store image based on last_insert_id ?

Hello,

I really want to know about image store based on last insert id,

For Ex:
-> Current images table have 3 records.
-> Now i am going to upload new one.
-> Newly uploaded image stored would be on uploads/{4}/2sdf3asdf4as.jpg
->{4} will be last insert id

Actually standard symfony provide lifecycle callback so we can do that, but i don't know how to do with this bundle.

I really love this bundle it is awesome 👍

comur + bootstrap when click edit

Hi a try use the bundle when i click on edit my navegator says:

Uncaught TypeError: undefined is not a function
on $('#image_upload_file').fileupload
i include {% include "ComurImageBundle:Form:croppable_image_modal.html.twig" with {'include_jquery': true, 'include_bootstrap': false} %} do you have any idea?

Uncaught TypeError: $(...).fileupload is not a function

Hello,

I have installed your bundle that is very great but I have a problem when I click on Edit button :
Uncaught TypeError: $(...).fileupload is not a function

Here is my versions :

  • bootstrap : 3.3.x-dev
  • jQuery : 2.1.4
  • ComuImageBundle : 1.0.*@dev

I include Twig like this :
{% include "ComurImageBundle:Form:croppable_image_modal.html.twig" with {'include_jquery': false, 'include_bootstrap': false} %}

I have installed assets and all JS are present in web/bundles folder.

If I comment .fileupload from comur.imagelibrary.js, I have another problem with function modal from bootstrap : Uncaught TypeError: $(...).modal is not a function. Very strange...

But if I copy this line ($('#image_upload_modal').modal('show');) from comur.imagelibrary.js to the end of my HTMl document, it works and modal appears.

I don't understand what it's happening...

If someone has an idea, thank you.

Make crop rectangle fill the entire image

Is there a way that the crop rectangle - by default, initially - simply fills the entire image? That way the crop action will be optional, whoever decides to do so.

Or, alternatively - is there a way to disable the cropping entirely?

png transparent background turned black

Hi again.

There is an issue with png files that has transparent background. I have resolved it.

  • In comur.image.library.js jcrop initialization must be bgColor: 'transparent' insteada of bgColor: 'black'.
  • In UploadController.php, line 337, the transparency is doing after other functions that breaks it. It must be moved to line 325, inmediately after imagecreatetruecolor call and before imagecopyresampled call.

Delete unused images

Have to find a way to delete images when they are not used anymore.

2 possibilities:

  1. Add a listener on preUpdate and remove old images
  2. Add a trigger on image change in the widget and call an ajax route to delete old images

Any way, we have to create a service to get all image types (cropped, thumbs) related to an image.

404 when uploading on production

While moving the project to production i noticed that the POST after uploading an image returns 404:

"Failed to load resource: the server responded with a status of 404 (Not Found) http://somedomain.com/upload/"

The not-found path is defined in routing.yml

comur_api_upload:
pattern: /upload

In debug_mode everything works just fine, at both local and external server, but in production mode the error is thrown.

Anyone knows what could be the problem? Just in case is relative to the issue, i also added a rewrite rule to get rid of the "app.php" part of the url.

Thanks,

black line when uploaded image has exact same size

If i upload an image which has exact same size as minWidht or minHeight, it adds a black line at left or top because jcrop sends:

x:-0.624996185302134
w:300.625

instead of

x: 0
w: 300

for an image width = 300 and minWidth = 300

mismatch in progress bar name

There's a mismatch in progress bar selector in "comur.imagelibrary.js" and "croppable_image_modal.html.twig".

"comur.imagelibrary.js" => $('#image_upload_file_progress .progress-bar').css('width',progress + '%');

"croppable_image_modal.html.twig" =>

Add multiple file upload support

Add options to support multiple file upload with a new field type like comur_gallery and store them in an array to keep it simple.

Delete images from gallery

Hi!
I've been playing around with this bundle (excellent work btw), and I'm kind of lost trying to find out the right direction to implement remove image from gallery.

Has anybody worked on this feature before? Can I ask for some directions on this?

Thanks in advance!

croppable_image_modal.html.twig don't work

Hello, when i add {% include "ComurImageBundle:Form:croppable_image_modal.html.twig"%} it shows me nothing and when i add {% include "ComurImageBundle:Form:croppable_image_modal.html.twig" with {'include_jquery': false, 'include_bootstrap': false} %} it works without style, how to fix that please ?

Error with *.png transparency

When I crop a file png with background transparent
I have a black background
I think you must add imagealphablending on each new layer.

JSON.parse syntax error

Hi all.

I've a syntax error in the options parsing in twig:

fields.html.twig line 54: {{ options | json_encode() | raw }}

I think that uploadConfig object isn't properly parse, because the slash in the routes are not escaped (they are '' instead of '').

Is this possible?

Jquery error : $(...).sortable is not a function

Hi,

When I want to use the image gallery widget I get this error in the browser console. I have to download jquery ui and add it to the croppable_image_modal.html.twig template to get it work. I use jquery v2.1.4, I get this error event if I set the "include_jquery" parameter to TRUE. Don't think it's normal or if I've miss something ?

Thx

Cropped Image name will be configurable.

Cropped image name will be configurable, it make big effort when some dynamics image directory generate after upload and cropped.

For Ex:
     if(isset($config['cropConfig']['useFileNameUnique']) && $config['cropConfig']['useFileNameUnique'] != ""){
        $ext = pathinfo($imageName, PATHINFO_EXTENSION);
        $imageName = sha1(uniqid(mt_rand(), true)).'.'.$ext;
     }

What you think about this one ?

I can't get it to work :(

Hey there,
I installed the lates dev-master as described in the documentation, but can't get it to work.
If I hover over the placeholder Image the Edit button appears, but pressing it doesn't work.
In the console I see this error when pressing the Edit button:
TypeError: $(...).fileupload is not a function
Empty string passed to getElementById().

Jquery and all necessary files are loaded and active. What could be the problem?

Thanks for help.. :)

Translation not working when destroy image

A function in comur.imagelibrary.js is adding a text that is not translated.

function destroyImageManager(){
$('#image_upload_file').fileupload('destroy');
destroyJCrop();
$('#image_crop_go_now').unbind('click');
$('#image_preview').html('

Please select or upload an image

');
}

Modal doesnt appear

I manage to get the holder displayed properly but when I click on Modify, the background become darker as it would be expected but no modal and no error / warning / anything to debug.

Jquery 2.1
Bootstrap 3.2.2
Query UI Widget 1.10.3+amd (provided by your bundle)

Thanks for your help!

upload doesn't work in IE10

Nothing happens when you select a file. I see where it calls _initIframeSettings in jquery.fileupload.js but that doesn't seem to do much. In other browsers it doesn't call that method, it uses XHR upload instead and that seems to work fine.

edit: this is actually IE9 issue, it works with XHR in IE10

placehold.io not working

I have problems with this service. My include code is:

{% include "ComurImageBundle:Form:croppable_image_modal.html.twig" with {'include_jquery': false, 'include_bootstrap': false, 'include_holder': true} %}

captura de pantalla 2015-04-29 a les 11 24 57

Images cropped twice

Hi!

I'm experimenting a weird behavior when uploading images, when I upload the first image upload one image, perfect; but when upload the second two images are uploaded, and so on; third image tree images uploaded.

What could possibly be happening?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.