#StackBounty: #php #laravel #watermark #aspect-ratio #intervention How to keep aspect ration of Image and Watermark in Laravel php

Bounty: 50

I am trying to add Watermark of 800x100px to Images which can have any resolution greater than 800×100, i.e. 801×110, 1200×1000, 1300×200, 1920×1080, 4000×2010, etc.

I want to keep the aspect ratio of Watermark and image to 2:50.
i.e., if image has 1000px width, then watarmark over image should occupy 20px(1000/50).

Here is my Function :

in helper.php

use Image;
//calling from Controller

public static function addwatermark ($name) {

  $thumbnail = Image::make($name);
  $imageWidth = $thumbnail->width();
  $watermarkWidth = '800px';

  $watermarkSource = 'public/img/watermark/watermark.png';
  $thumbnail->insert($watermarkSource, 'bottom-left', 0, 0);
  $thumbnail->save($name)->destroy();
}
 

in ImageController.php

 $folder = 'public/folder/';
 $large = 'myfile.jpeg';
 Helper::addwatermark($folder.$large);


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.