Media Module Watermark Addons



  • I have an idea for media module.
    Thumbnail watermark into the config settings can be added to some modules.

    Simple Module Config file (MyModuleName/thumbnails.php)

    <?php
    [
    return [
        'coverImage' => [
            'fit' => [
                'width' => '200',
                'height' => null,
                'callback' => function ($constraint) {
                    $constraint->upsize();
                }
            ],
            'watermark' => [
                'source' => 'public/assets/watermark.png', // if changing required
                'position' => 'top-right' // if changing required
            ]
        ]
    ];
    ?>
    

    Changes required for this purpose below

    Adding New File : Modules\Media\Image\Intervention\Manipulation\Watermark.php

    <?php namespace Modules\Media\Image\Intervention\Manipulations;
    
    use Modules\Media\Image\ImageHandlerInterface;
    
    class Watermark implements ImageHandlerInterface
    {
        private $defaults = [
            'source' => 'public/assets/watermark.png',
            'position' => 'bottom-right',
            'x' => null,
            'y' => null,
        ];
    
        /**
         * Handle the image manipulation request
         * @param  \Intervention\Image\Image $image
         * @param  array                     $options
         * @return \Intervention\Image\Image
         */
        public function handle($image, $options)
        {
            $options = array_merge($this->defaults, $options);
    
            return $image->insert($options['source'],$options['position'], $options['x'], $options['y']);
        }
    

  • admin

    Very good idea, thank you! I'll see if I find to add it myself, or you can always send a pull request



  • @nWidart No problem, you can add. Thanks.



  • @nWidart You don't need to add, i did it pull request. Thanks.



  • thank you for this addons :+1:


Log in to reply