0
我尝试了很多方法来将水印图像的坐标改变到左上角,但我无法理解哪些变量定义了顶部,左侧,右侧和底部角落。对齐水印与PHP左上角而不是右下角
我希望你能帮助
//Source folder where all images are placed
$source="source";
//Destination folder where all images with watermark will be copied
$destination="destination";
//Creating an image object of watermark image
$watermark=imagecreatefrompng("watermark.png");
//Margin of watermark from right and bottom of the main image
$margin_right=10;
$margin_bottom=10;
//Height ($sy) and Width ($sx) of watermark image
$sx=imagesx($watermark);
$sy=imagesy($watermark);
//Get list of images in source folder
$images=array_diff(scandir($source), array('..', '.'));
foreach($images as $image){
//Create image object of main image
$img=imagecreatefromjpeg($source.'/'.$image);
//Copying watermark image into the main image
imagecopy($img, $watermark, imagesx($img) - $sx - $margin_right, imagesy($img) - $sy - $margin_bottom, 0, 0, $sx, $sy);
//Saving the merged image into the destination folder
imagejpeg($img, $destination.'/'.$image,100);
//Destroying the main image object
imagedestroy($img);
}
//Destroying watermark image object
imagedestroy($watermark);
?>
不是。看看代码更好一点,你会看到 –
我没有看到任何关于! – Soheyl
您没有看到$ margin-right = 10; $边距= 10;只是变量?如果我将它改为margin-leftand margin-top,它会抛出一个错误,因为imagecopy需要名称为$ margin-right和$ margin-bottom的变量? –