public function assignWatermark(Request $request)
    {
        $getWatermak = $this->getWatermak();

        if(!$getWatermak) {
            return $getWatermak;
        }

        // go through each select image
        foreach ($request->all() as $key => $file){
            $image = new Media($file);

            // check if user has permissions to access this link
            if(!User::hasAccess('Media', 'update', $image->mediaID, true)) {
                return $this->noPermission();
            }

            if ($image->type == "image") {

                // mark original image
                $url = strpos($image->url, '?');
                if($url == false) {
                    $url = base_path($image->url);
                }else{
                    $url = base_path(explode('?', $image->url)[0]);
                }

                // does file exist
                if(!File::exists($url)) {
                    throw new \Exception("Original images ".$url." doesn't exists.");
                }

                $originalImage = Image::make($url);

                // get width of the original image
                $originalWidth = (integer) $originalImage->width();

                // calculate a width for the watermark
                $width = round($originalWidth / 3);

                // get watermark
                $watermark = Image::make($getWatermak->url);

                // resize watermark
                $watermark->resize(
                    $width, null, function ($constraint) {
                        $constraint->aspectRatio();
                    }
                );
                $originalImage->insert($watermark, 'center');
                $originalImage->save($url, 100);

                $image->deleteThumbs();
                $image->createDefaultThumbs();

            }else{
                return "Some files could not be watermaked. Please select only image files.";
            }
        }
        return "OK";
    }
public function assignWatermark(Request $request)
    {
        $getWatermak = $this->getWatermak();

        if(!$getWatermak) {
            return $getWatermak;
        }

        // go through each select image
        foreach ($request->all() as $key => $file){
            $image = new Media($file);

            // check if user has permissions to access this link
            if(!User::hasAccess('Media', 'update', $image->mediaID, true)) {
                return $this->noPermission();
            }

            if ($image->type == "image") {

                // mark original image
                $url = strpos($image->url, '?');
                if($url == false) {
                    $url = base_path($image->url);
                }else{
                    $url = base_path(explode('?', $image->url)[0]);
                }

                // does file exist
                if(!File::exists($url)) {
                    throw new \Exception("Original images ".$url." doesn't exists.");
                }

                $originalImage = Image::make($url);

                // get width of the original image
                $originalWidth = (integer) $originalImage->width();

                // calculate a width for the watermark
                $width = round($originalWidth / 3);

                // get watermark
                $watermark = Image::make($getWatermak->url);

                // resize watermark
                $watermark->resize(
                    $width, null, function ($constraint) {
                        $constraint->aspectRatio();
                    }
                );
                $originalImage->insert($watermark, 'center');
                $originalImage->save($url, 100);

                $image->deleteThumbs();
                $image->createDefaultThumbs();

            }else{
                return "Some files could not be watermaked. Please select only image files.";
            }
        }
        return "OK";
    }
public function assignWatermark ( Request $ request ) { $ getWatermak = $ this -> getWatermak ( ) ; if ( ! $ getWatermak ) { return $ getWatermak ; } // go through each select image foreach ( $ request -> all ( ) as $ key => $ file ) { $ image = new Media ( $ file ) ; // check if user has permissions to access this link if ( ! User :: hasAccess ( 'Media' , 'update' , $ image -> mediaID , true ) ) { return $ this -> noPermission ( ) ; } if ( $ image -> type == "image" ) { // mark original image $ url = strpos ( $ image -> url , '?' ) ; if ( $ url == false ) { $ url = base_path ( $ image -> url ) ; } else { $ url = base_path ( explode ( '?' , $ image -> url ) [ 0 ] ) ; } // does file exist if ( ! File :: exists ( $ url ) ) { throw new \ Exception ( "Original images " . $ url . " doesn't exists." ) ; } $ originalImage = Image :: make ( $ url ) ; // get width of the original image $ originalWidth = ( integer ) $ originalImage -> width ( ) ; // calculate a width for the watermark $ width = round ( $ originalWidth / 3 ) ; // get watermark $ watermark = Image :: make ( $ getWatermak -> url ) ; // resize watermark $ watermark -> resize ( $ width , null , function ( $ constraint ) { $ constraint -> aspectRatio ( ) ; } ) ; $ originalImage -> insert ( $ watermark , 'center' ) ; $ originalImage -> save ( $ url , 100 ) ; $ image -> deleteThumbs ( ) ; $ image -> createDefaultThumbs ( ) ; } else { return "Some files could not be watermaked. Please select only image files." ; } } return "OK" ; }
Assign watermark to media images.

@param  Request $request
@return array|string
@throws \Exception
Assign watermark to media images .