gpt4 book ai didi

php - laravel 5.2 干预包中如何添加水印图片?

转载 作者:行者123 更新时间:2023-12-02 17:19:03 24 4
gpt4 key购买 nike

我正在使用 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'));

关于php - laravel 5.2 干预包中如何添加水印图片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44451310/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com