php - 如何修复水印位置php?
问题描述
我希望将水印应用于选定的图像,在 5 个不同的位置,我有 3 个函数用于这些位置中心、bottom_right、top_left,它们适用于所有图像,但我不知道如何做 bottom_left、top_right。我尝试过,但使用不同的图像,水印会消失或出现错误的地方,这是三个有效的功能。我需要将水印放置在每个图像中的相同位置,例如响应式。
中心:
$imgs = imagecreatefromjpeg("/var/www/$f$p/$n");
// Load the logo image
$logoImage = imagecreatefrompng("$waterpath/$watername");
imagealphablending($logoImage, true);
// Get dimensions
$imageWidth = imagesx($imgs);
$imageHeight = imagesy($imgs);
$logoWidth = imagesx($logoImage);
$logoHeight = imagesy($logoImage);
// Paste the logo
imagecopy(
// destination
$imgs,
// source
$logoImage,
// destination x and y
($imageWidth - $logoWidth) / 2, ($imageHeight - $logoHeight) / 2,
// source x and y
0, 0,
// width and height of the area of the source to copy
$logoWidth, $logoHeight);
$watermark->update(array('status' => 'done'));
imagejpeg($imgs, "/var/www/$f$p/$n");
左上方:
$imgs = imagecreatefromjpeg("/var/www/$f$p/$n");
// Load the logo image
$logoImage = imagecreatefrompng("$waterpath/$watername");
imagealphablending($logoImage, true);
// Get dimensions
$imageWidth = imagesx($imgs);
$imageHeight = imagesy($imgs);
$logoWidth = imagesx($logoImage);
$logoHeight = imagesy($logoImage);
// Paste the logo
imagecopy(
// destination
$imgs,
// source
$logoImage,
// destination x and y
($imageWidth - $logoWidth) / 100, ($imageHeight - $logoHeight) / 100,
// source x and y
0, 0,
// width and height of the area of the source to copy
$logoWidth, $logoHeight);
imagejpeg($imgs, "/var/www/$f$p/$n");
右下角:
$imgs = imagecreatefromjpeg("/var/www/$f$p/$n");
// Load the logo image
$stamps = imagecreatefrompng("$waterpath/$watername");
// Set the margins for the stamp and get the height/width of the stamp image
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamps);
$sy = imagesy($stamps);
$imageWidth = imagesx($imgs);
$imageHeight = imagesy($imgs);
// Copy the stamp image onto our photo using the margin offsets and the photo
// width to calculate positioning of the stamp.
imagecopy($imgs, $stamps, $imageWidth - $sx - $marge_right, $imageHeight - $sy - $marge_bottom, 0, 0, imagesx($stamps), imagesy($stamps));
imagejpeg($imgs, "/var/www/$f$p/$n");
我尝试了这些功能,但它们不适用于所有图像:
左下方:
$imgs = imagecreatefromjpeg("/var/www/$f$p/$n");
// Load the logo image
$stamps = imagecreatefrompng("$waterpath/$watername");
// Set the margins for the stamp and get the height/width of the stamp image
$marge_right = 670;
$marge_bottom = 10;
$sx = imagesx($stamps);
$sy = imagesy($stamps);
$imageWidth = imagesx($imgs);
$imageHeight = imagesy($imgs);
// Copy the stamp image onto our photo using the margin offsets and the photo
// width to calculate positioning of the stamp.
imagecopy($imgs, $stamps, $imageWidth - $sx - $marge_right, $imageHeight - $sy - $marge_bottom, 0, 0, imagesx($stamps), imagesy($stamps));
imagejpeg($imgs, "/var/www/$f$p/$n");
右上:
$imgs = imagecreatefromjpeg("/var/www/$f$p/$n");
// Load the logo image
$stamps = imagecreatefrompng("$waterpath/$watername");
// Set the margins for the stamp and get the height/width of the stamp image
$marge_right = 10;
$marge_bottom = 430;
$sx = imagesx($stamps);
$sy = imagesy($stamps);
$imageWidth = imagesx($imgs);
$imageHeight = imagesy($imgs);
// Copy the stamp image onto our photo using the margin offsets and the photo
// width to calculate positioning of the stamp.
imagecopy($imgs, $stamps, $imageWidth - $sx - $marge_right, $imageHeight - $sy - $marge_bottom, 0, 0, imagesx($stamps), imagesy($stamps));
imagejpeg($imgs, "/var/www/$f$p/$n");
解决方案
推荐阅读
- visual-studio - The function "REVERSE" does not support the data type "DT_I4" for parameter number 1
- unity3d - 用户使用全息透镜扫描海报。3D 内容将覆盖在海报上
- c# - Using AWS SDK on .net with localstack (TransferUtility/S3 - setting endpoint)
- json - 我应该使用 JSend 来包装 json ajax 响应,还是有更标准的标准?
- java - 带有公司代理的测试容器
- php - How to find the domain is whether HTTP or HTTPS (with or without WWW) using PHP?
- css - Css我如何从inspector中找到一个css文件
- laravel - 我如何验证 Laravel 5.4 中的电子邮件列表
- opc-ua - Livetime / uniqueness of NodeId (How to manage NodeIds for dynamic nodes)
- php - Using functions.php or something instead of content-single-product.php and content-product.php