wernerdweight / image-manager-bundle
Support for image resizing, cropping and encrypting for Symfony.
Installs: 122
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 2
Type:symfony-bundle
Requires
- php: ^7.2
- symfony/framework-bundle: ~2.8|~3.4|^4.0
- thecodingmachine/safe: ^0.1.14
- wernerdweight/image-manager: ^3.0.2
Requires (Dev)
- thecodingmachine/phpstan-safe-rule: ^0.1.3
- wernerdweight/cs: ^1.3
This package is auto-updated.
Last update: 2024-11-29 05:03:12 UTC
README
This bundle adds support for image resizing and cropping.
Installation
- Download using composer
{ "require": { "wernerdweight/image-manager-bundle": "~3.0" } }
- Enable the bundle
Enable the bundle in your kernel:
<?php // config/bundles.php return [ // ... WernerDweight\ImageManagerBundle\WDImageManagerBundle::class => ['all' => true], ];
- Setup config
# config/packages/wd_image_manager.yaml wd_image_manager: upload_root: absolute/path/to/web/directory # typically %kernel.root_dir%/../web upload_path: relative/path/for/storing/images # e.g. uploads/images secret: thisIsNotSecret # you can use app secret (%secret%) or any other custom secret (needed for encryption) autorotate: true # default false (if true, an attempt will be made to automatically rotate images based on exif data) versions: version_name_x: # this key will be used as name of directory to where this version of images will be saved width: 200 # desired image width in pixels (if you ommit width or height image will keep its original dimensions) height: 200 # desired image height in pixels (if you ommit width or height image will keep its original dimensions) crop: true # set this to true if you want the resulting image to have EXACTLY the dimensions specified (default false) watermark: # if you don't want your images to be watermarked, do not set this key at all file: absolute/path/to/watermark/file # e.g. %kernel.root_dir%/../web/watermark.png size: 50 # css-like watermark size; possible values: cover/contain/percentage (integer 0 - 100) position: top: 50 # css-like position from top in percent (integer 0 - 100; default 100 - align to bottom) left: 50 # css-like position from left in percent (integer 0- 100; default 100 - align to right) encrypted_version_name: encrypted: true # if encrypted is set to true original image will be saved encrypted (intended for image download restrictions) ...
Usage
How to use:
// this example expects you to pass image manager via DI into $imageManager // upload your image file(s), create database records etc. ... // process image (one by one) // 1st parameter ($file) is instance of Symfony\Component\HttpFoundation\File\UploadedFile (mandatory) // 2nd parameter is the filename of newly created file (mandatory) // 3rd parameter is a path under upload_path from config (optional) $processedImageInfo = $imageManager->processImage($file, 'destination-filename', '/optional/subpath');
License
This bundle is under the MIT license. See the complete license in the root directiory of the bundle.