cesurapp/media-bundle

Symfony Media Bundle

Installs: 206

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:symfony-bundle

1.0.16 2024-09-01 11:12 UTC

This package is auto-updated.

Last update: 2024-10-31 11:45:19 UTC


README

App Tester Software License

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);