我尝试了很多方法将水印图像的坐标更改为左上角,但我无法理解哪些变量定义了顶部,左侧,右侧和底部。
我希望你能帮忙
//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);
?>
答案 0 :(得分:0)
好吧,你的代码!
//Margin of watermark from right and bottom of the main image
$margin_right=10;
$margin_bottom=10;
我不确定您的脚本是如何工作的,但您可以添加:
$margin_left=10;
$margin_top=10;
并删除:
$margin_right=10;
$margin_bottom=10;
它与PHP无关!它看起来像CSS配置!