cesurapp / media-bundle
Symfony Media Bundle
Installs: 203
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=8.2
- ext-fileinfo: *
- ext-imagick: *
- cesurapp/storage-bundle: ^1.0
- doctrine/doctrine-bundle: ^2.10
- doctrine/orm: ^2.15
- symfony/console: ^7.0
- symfony/dependency-injection: ^7.0
- symfony/framework-bundle: ^7.0
- symfony/http-kernel: ^7.0
- symfony/mime: ^7.0
- symfony/uid: ^7.0
Requires (Dev)
- php-cs-fixer/shim: ^3.40
- phpstan/phpstan: ^1.10
- symfony/test-pack: ^1.1
- zenstruck/foundry: ^2.0
README
It is used to keep track of files. When media is deleted, it is also automatically removed from storage. You can use the same media with multiple tables. You must create a new trait for each column. Imagick compression, resizing, conversion support is available for image files.
Install
Required Symfony 7
composer req cesurapp/media-bundle
Commands
bin/console media:status # View Media Storage Details
Create Media Column
Note: Copy the "MediaTrait" for the new column.
use \Cesurapp\MediaBundle\Entity\MediaInterface; use \Cesurapp\MediaBundle\Entity\MediaTrait; class UserEntity implements MediaInterface { use MediaTrait; /** * For a single column, this is not necessary. */ //public function getMediaColumns(): array { // return ['media']; //} }
Upload Image
use \Cesurapp\MediaBundle\Manager\MediaManager; class ExampleController { public function index(Request $request, MediaManager $manager): void { $images = $manager ->setImageCompress(true) // Enable Image Compressor ->setImageConvertJPG(true) // PNG to JPG Convertor ->setImageQuality(75) // Default Image Quality ->setImageSize(1024,768) // Maximum Image Size //->uploadFile($request) // HTTP File Upload //->uploadBase64($request, ['base64DataKey'], ['base64DataKey' => ['image/png']]) // Json Base64 Image Upload ->uploadLink($request, ['imageLinkKey'], ['imageLinkKey' => ['image/png']]) // Image Link Upload } }
Imagick Helper
Compress JPG:
\Cesurapp\MediaBundle\Compressor\Image::create(file_get_contents('image.jpg'))->save('save_path.jpg', 'jpg', 75);
Convert & Compress to JPG:
\Cesurapp\MediaBundle\Compressor\Image::create(file_get_contents('image.png'))->save('save_path.jpg', 'jpg', 75);
Resize Aspect Ratio & Convert JPG:
\Cesurapp\MediaBundle\Compressor\Image::create(file_get_contents('image.png'))->resize(100, 100)->output('jpg', 75);