如何在干预包的laravel 5.2中添加水印图片?
How to add watermark image in laravel 5.2 in intervention package?
我正在使用 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'));
请帮我看看我做错了什么。提前致谢:)
如果我理解正确你的问题,这里是解决方案(未测试)
$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'));
我正在使用 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'));
请帮我看看我做错了什么。提前致谢:)
如果我理解正确你的问题,这里是解决方案(未测试)
$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'));