PrestaImageBundle is a Symfony bundle providing tools to resize local/remote images before uploading them through a classic form. It uses Cropper jQuery plugin.
php composer.phar require presta/image-bundle
You must add the following bundles into app/AppKernel.php
:
<?php
public function registerBundles()
{
$bundles = [
// ...
new Vich\UploaderBundle\VichUploaderBundle(),
new FOS\JsRoutingBundle\FOSJsRoutingBundle(),
new Presta\ImageBundle\ImageBundle(),
];
}
You must use the image_widget.html.twig
form theme into app/config.yml
.
twig:
form_themes:
- "PrestaImageBundle:form:image_widget.html.twig"
You must include the routing into app/config/routing.yml
:
presta_image:
resource: "@PrestaImageBundle/Resources/config/routing.yml"
fos_js_routing:
resource: "@FOSJsRoutingBundle/Resources/config/routing/routing.xml"
See VichUploader documentation to configure the bundle.
See Cropper quick start section to install assets.
Note that jQuery and Bootstrap are required.
Don't forget to include the following assets in your page:
/path/to/cropper/dist/cropper.min.css
/path/to/cropper/dist/cropper.min.js
@PrestaImageBundle/Resources/public/css/cropper.css
@PrestaImageBundle/Resources/public/js/cropper.js
And the following scripts:
<script src="{{ asset('bundles/fosjsrouting/js/router.js') }}"></script>
<script src="{{ path('fos_js_routing_js', { callback: 'fos.Router.setData' }) }}"></script>
(function(w, $) {
'use strict';
$(function() {
$('.cropper').each(function() {
new Cropper($(this));
});
});
})(window, jQuery);
Pull requests are welcome.
Thanks to everyone who has contributed already.
This project is supported by PrestaConcept
Lead Developer : @J-Ben87
Released under the MIT License