2017 © Pedro Peláez
 

symfony-bundle image-bundle

Allow to crop local and remote image before uploading them through a classic form.

image

presta/image-bundle

Allow to crop local and remote image before uploading them through a classic form.

  • Sunday, April 29, 2018
  • by nicolas-bastien
  • Repository
  • 5 Watchers
  • 6 Stars
  • 15,724 Installations
  • PHP
  • 1 Dependents
  • 1 Suggesters
  • 12 Forks
  • 3 Open issues
  • 21 Versions
  • 42 % Grown

The README.md

PrestaImageBundle

tests quality codecov Latest Stable Version Total Downloads, (*1)

Overview

PrestaImageBundle is a Symfony bundle providing tools to resize uploaded and remote images before sending them through a classic form. It uses the Cropper.js library., (*2)

Installation

Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation., (*3)

Applications that use Symfony Flex

Open a command console, enter your project directory and execute:, (*4)

$ composer require presta/image-bundle

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:, (*5)

$ composer require presta/image-bundle

Step 2: Enable the Bundle

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

// config/bundles.php

return [
    // ...
    Presta\ImageBundle\PrestaImageBundle::class => ['all' => true],
];

Configuration

You must configure the form_layout.html.twig form theme into config/packages/twig.yaml., (*7)

twig:
    form_themes:
        - "@PrestaImage/form/form_layout.html.twig"

Note: you can also create your own form theme instead., (*8)

You must include the routing into config/routes.yaml:, (*9)

presta_image:
    resource: "@PrestaImageBundle/config/routing.yaml"

See VichUploader documentation to configure the bundle., (*10)

Assets

See Cropper.js documentation to install assets., (*11)

Don't forget to include the following assets in your page:, (*12)

  • @PrestaImageBundle/public/css/cropper.css
  • @PrestaImageBundle/public/js/cropper.js

How to: implementation examples

Usage

Initialize cropper

document.querySelectorAll('.presta-image').forEach(element => {
    new Cropper(element)
})

Use the form type

<?php

use Presta\ImageBundle\Form\Type\ImageType;

public function buildForm(FormBuilderInterface $builder, array $options): void
{
    $builder
        ->add('image', ImageType::class)
    ;
}

Available options for the ImageType:, (*13)

  • aspect_ratios (array): a list of aspect ratio to apply when resizing an image
  • cropper_options (array): a list of options supported by cropper (default: ['autoCropArea' => 1])
  • max_width (int): the max width of the cropped image send to server (default: 320)
  • max_height (int): the max height of the cropped image send to server (default: 180)
  • preview_width (string): the max width to use when displaying the image preview - can be in px, % or other css value (default: '320px')
  • preview_height (string): the max height to use when displaying the image preview - can be in px, % or other css value (default: '180px')
  • upload_button_class (string): CSS class of the "upload" button (default: '')
  • cancel_button_class (string): CSS class of the "cancel" button (default: '')
  • save_button_class (string): CSS class of the "save" button (default: '')
  • download_uri (string): the path where the image is located (default: null, automatically set)
  • show_image (bool): whether the image should be rendered in the form or not (default: true)
  • file_upload_enabled (bool): whether to enable the file upload widget or not (default: true)
  • remote_url_enabled (bool): whether to enable the remote url widget or not (default: true)
  • rotation_enabled (bool): whether to enable the rotation or not (default: false)
  • upload_mimetype (string): format of the image to be uploaded (default: image/png)
    (Note: If the chosen mimetype is not supported by the browser, it will silently fall back to image/png)
  • upload_quality (float): quality (0..1) of uploaded image for lossy imageformats (eg. image/jpeg) (default: 0.92)

Notes

You can find Cropper.js options [here][5]., (*14)

The max_width and max_height options are used to define maximum size the cropped uploaded image will be. Bigger images (after cropping) are scaled down., (*15)

Security Note: NEVER rely on this size constraints and the format settings as they can easily be manipulated client side. ALWAYS validate the image-data, image-size, image-format server side!, (*16)

Contributing

Pull requests are welcome., (*17)

Thanks to everyone who has contributed already., (*18)


This project is supported by PrestaConcept, (*19)

Lead Developer : @J-Ben87, (*20)

Released under the MIT License, (*21)

The Versions

29/04 2018

dev-master

9999999-dev https://github.com/prestaconcept/PrestaImageBundle

Allow to crop local and remote image before uploading them through a classic form.

  Sources   Download

MIT

The Requires

 

form symfony2 bundle symfony image remote local picture

29/04 2018

v1.8.1

1.8.1.0 https://github.com/prestaconcept/PrestaImageBundle

Allow to crop local and remote image before uploading them through a classic form.

  Sources   Download

MIT

The Requires

 

form bundle symfony image remote local picture

26/03 2018

v1.8

1.8.0.0 https://github.com/prestaconcept/PrestaImageBundle

Allow to crop local and remote image before uploading them through a classic form.

  Sources   Download

MIT

The Requires

 

form bundle symfony image remote local picture

26/03 2018

dev-symfony4-support

dev-symfony4-support https://github.com/prestaconcept/PrestaImageBundle

Allow to crop local and remote image before uploading them through a classic form.

  Sources   Download

MIT

The Requires

 

form bundle symfony image remote local picture

03/12 2017

v1.7.5

1.7.5.0 https://github.com/prestaconcept/PrestaImageBundle

Allow to crop local and remote image before uploading them through a classic form.

  Sources   Download

MIT

The Requires

 

form symfony2 bundle image remote local picture

24/11 2017

v1.7.4

1.7.4.0 https://github.com/prestaconcept/PrestaImageBundle

Allow to crop local and remote image before uploading them through a classic form.

  Sources   Download

MIT

The Requires

 

form symfony2 bundle image remote local picture

12/10 2017

v1.7.3

1.7.3.0 https://github.com/prestaconcept/PrestaImageBundle

Allow to crop local and remote image before uploading them through a classic form.

  Sources   Download

MIT

The Requires

 

form symfony2 bundle image remote local picture

09/10 2017

v1.7.2

1.7.2.0 https://github.com/prestaconcept/PrestaImageBundle

Allow to crop local and remote image before uploading them through a classic form.

  Sources   Download

MIT

The Requires

 

form symfony2 bundle image remote local picture

29/09 2017

v1.7.1

1.7.1.0 https://github.com/prestaconcept/PrestaImageBundle

Allow to crop local and remote image before uploading them through a classic form.

  Sources   Download

MIT

The Requires

 

form symfony2 bundle image remote local picture

28/06 2017

v1.7

1.7.0.0 https://github.com/prestaconcept/PrestaImageBundle

Allow to crop local and remote image before uploading them through a classic form.

  Sources   Download

MIT

The Requires

 

form symfony2 bundle image remote local picture

26/06 2017

1.6

1.6.0.0 https://github.com/prestaconcept/PrestaImageBundle

Allow to crop local and remote image before uploading them through a classic form.

  Sources   Download

MIT

The Requires

 

form symfony2 bundle image remote local picture

22/06 2017

v1.5

1.5.0.0 https://github.com/prestaconcept/PrestaImageBundle

Allow to crop local and remote image before uploading them through a classic form.

  Sources   Download

MIT

The Requires

 

form symfony2 bundle image remote local picture

22/06 2017

dev-Fix-vichuploader-storage-injection

dev-Fix-vichuploader-storage-injection https://github.com/prestaconcept/PrestaImageBundle

Allow to crop local and remote image before uploading them through a classic form.

  Sources   Download

MIT

The Requires

 

form symfony2 bundle image remote local picture

20/06 2017

v1.4

1.4.0.0 https://github.com/prestaconcept/PrestaImageBundle

Allow to crop local and remote image before uploading them through a classic form.

  Sources   Download

MIT

The Requires

 

form symfony2 bundle image remote local picture

20/06 2017

dev-27-cropper-options

dev-27-cropper-options https://github.com/prestaconcept/PrestaImageBundle

Allow to crop local and remote image before uploading them through a classic form.

  Sources   Download

MIT

The Requires

 

form symfony2 bundle image remote local picture

06/06 2017

v1.3

1.3.0.0 https://github.com/prestaconcept/PrestaImageBundle

Allow to crop local and remote image before uploading them through a classic form.

  Sources   Download

MIT

The Requires

 

form symfony2 bundle image remote local picture

28/05 2017

v1.2

1.2.0.0 https://github.com/prestaconcept/PrestaImageBundle

Allow to crop local and remote image before uploading them through a classic form.

  Sources   Download

MIT

The Requires

 

form symfony2 bundle image remote local picture

12/05 2017

v1.1

1.1.0.0 https://github.com/prestaconcept/PrestaImageBundle

Allow to crop local and remote image before uploading them through a classic form.

  Sources   Download

MIT

The Requires

 

form symfony2 bundle image remote local picture

02/11 2016

dev-14_fix_image_size

dev-14_fix_image_size https://github.com/prestaconcept/PrestaImageBundle

Allow to crop local and remote image before uploading them through a classic form.

  Sources   Download

MIT

The Requires

 

form symfony2 bundle image remote local picture

11/10 2016

v1.0

1.0.0.0 https://github.com/prestaconcept/PrestaImageBundle

Allow to crop local and remote image before uploading them through a classic form.

  Sources   Download

MIT

The Requires

 

form symfony2 bundle image remote local picture

07/06 2016

dev-2_fix_file_upload

dev-2_fix_file_upload https://github.com/prestaconcept/PrestaImageBundle

Allow to crop local and remote image before uploading them through a classic form.

  Sources   Download

MIT

The Requires

 

form symfony2 bundle image remote local picture