Php 如何在干预包的laravel 5.2中添加水印图像?

Php 如何在干预包的laravel 5.2中添加水印图像?,php,laravel,laravel-5.2,watermark,intervention,Php,Laravel,Laravel 5.2,Watermark,Intervention,我使用的是laravel 5.2框架,我使用的是laravel的干预包,对我来说运行良好。现在我面临一个问题,我不知道我做错了什么。请帮助:- $myimage = Image::make(storage_path('app/images/test1.jpg')); //Suppose $imyimage width is 3024 and height is 2016 $actualwidth = 3024; $actualheight = 2016; 现在,当我尝试这些尺寸3024*201

我使用的是laravel 5.2框架,我使用的是laravel的干预包,对我来说运行良好。现在我面临一个问题,我不知道我做错了什么。请帮助:-

$myimage = Image::make(storage_path('app/images/test1.jpg'));
//Suppose $imyimage width is 3024 and height is 2016
$actualwidth = 3024;
$actualheight = 2016;
现在,当我尝试这些尺寸3024*2016像素时,水印不可见,而当我缩放图像时,水印可见 现在假设我有1600*1027像素的宽度和高度,它显示在中间,没有缩放 我想在3024*2016像素或任何缩放图像的像素中心水印

$watermarkHeight =  Image::make(storage_path('watermark.png'))->height();
$watermarkWidth =  Image::make(storage_path('watermark.png'))->width();
$x = ($actualwidth - $watermarkWidth) / 2;
$y = ($actualheight - $watermarkHeight) / 2;
$img = Image::make(storage_path('app/images/test1.jpg'));
$img->insert(storage_path('watermark.png'), 'center',round($x),round($y));
$img->resize($actualwidth,$actualheight)->save(storage_path('app/images/watermark-test.jpg'));

请帮帮我,我做错了什么。提前感谢:)

如果我正确理解了您的问题,以下是解决方案(未经测试)


你的问题对我来说不清楚,你试图在不同宽度/高度的图像上放置水印,你需要根据初始图像将水印居中并调整大小
,round($x),round($y)
您看不到它,因为此值太高。是的,确切地说@Froxz我想要在调整大小的图像上显示一个图像,该图像应该是可见的,并且在中间。解决方案是什么@Froxz我想要任何大小,,我希望图像居中,可见非常近,现在在每一幅图像水印是非常非常zoom@kunal检查更新的答案有3种调整水印大小的方法,请使用适合您需要的方法。我如何维护调整大小或上载图像的dpi请帮助我希望您也回答此问题
$watermark =  Image::make(storage_path('watermark.png'));
$img = Image::make(storage_path('app/images/test1.jpg'));
//#1
$watermarkSize = $img->width() - 20; //size of the image minus 20 margins
//#2
$watermarkSize = $img->width() / 2; //half of the image size
//#3
$resizePercentage = 70;//70% less then an actual image (play with this value)
$watermarkSize = round($img->width() * ((100 - $resizePercentage) / 100), 2); //watermark will be $resizePercentage less then the actual width of the image

// resize watermark width keep height auto
$watermark->resize($watermarkSize, null, function ($constraint) {
    $constraint->aspectRatio();
});
//insert resized watermark to image center aligned
$img->insert($watermark, 'center');
//save new image
$img->save(storage_path('app/images/watermark-test.jpg'));