我有一个JPG文件,我想合并另一个图像PNG文件就可以了。我不知道如何实现这个使用PHP?如何为图像加水印?
回答
您可以使用gd的imagecopy函数。
此功能用于图像的一部分从源复制到目标
imagecopy (
$dst_im , // destination image (resource), imagecreatefrom(gif|jpg|png)
$src_im , // destination image (resource), imagecreatefrom(gif|jpg|png)
$dst_x , // x cordinate in destination where u want the new obj placed
$dst_y , // y cordinate in destination where u want the new obj placed
$src_x , // x cordinate in source from wher u want the new obj placed
$src_y , // y cordinate in source from where u want the new obj placed
$src_w , // the width of the object to copy
$src_h // the height of the object to copy
);
如在上面的代码中的注释指出,你将不得不创建两个目的地和源的图像资源。
通常使用
$src = imagecreatefromjpg('image.jpg');
$dst = imagecreatefromjpg('watermark');
剩余部分只是简单的坐标来完成。
也别忘了自己造访imagecopy。
这里是在炎热的做水印使用GD一些例子:
const CORNER_TOP_LEFT = 1;
const CORNER_TOP_RIGHT = 2;
const CORNER_BOTTOM_LEFT = 3;
const CORNER_BOTTOM_RIGHT = 4;
$backgroundImagePath = "img/stamp.png";
$corner=CORNER_BOTTOM_RIGHT;
$alpha=60
[email protected]($filename);
$img_info=getimagesize($backgroundImagePath);
switch ($corner){
case CORNER_TOP_LEFT:
if(!imagecopymerge ($this->imageRes, $img_res, 0, 0, 0, 0, $img_info[0], $img_info[1], $alpha)){
throw new RuntimeException("Unable to make stamp!");
}
break;
case CORNER_TOP_RIGHT:
if(!imagecopymerge ($this->imageRes, $img_res, $this->info[0]-$img_info[0], 0, 0, 0, $img_info[0], $img_info[1], $alpha)){
throw new RuntimeException("Unable to make stamp!");
}
break;
case CORNER_BOTTOM_LEFT:
if(!imagecopymerge ($this->imageRes, $img_res, 0, $this->info[1]-$img_info[1], 0, 0, $img_info[0], $img_info[1], $alpha)){
throw new RuntimeException("Unable to make stamp!");
}
break;
case CORNER_BOTTOM_RIGHT:
if(!imagecopymerge ($this->imageRes, $img_res, $this->info[0]-$img_info[0], $this->info[1]-$img_info[1], 0, 0, $img_info[0], $img_info[1], $alpha)){
throw new RuntimeException("Unable to make stamp!");
}
break;
}
imagejpeg($img_res, "/path/to/save/image.jpg", 100);
我想合并从PHP创建的jpeg文件,就像这里$ filename =“pic。 PHP“我想使用PHP,因为pic.php生成随机图片,我想合并图片。 – 2012-03-31 07:01:19
不清楚你的随机图像是如何生成的。请详细解释。 – 2012-04-01 01:10:58
以captcha i generete为例,使用图像ttf函数,然后我想为它添加水印 – 2012-04-04 10:12:32
- 1. 如何为文本加水印图像?
- 2. 如何在图像上添加水印?
- 3. oracle ordim为图像添加水印
- 4. 在PHP中为图像添加水印
- 5. 用php为水印图片加水印
- 6. C#如何为jpeg图像添加水印?
- 7. 如何使用Imagemagick为图像加水印?
- 8. 如何根据图像调整水印?
- 9. ImageResizer水印应用基本图像,而不是水印图像
- 10. ASP.NET:添加“水印”到图像上飞
- 11. Carrierwave添加水印处理图像
- 12. 将水印添加到图像
- 13. 在图像上添加水印
- 14. 加水印后的图像大小
- 15. 试图用MagickWand方法使用python为图像加水印
- 16. 如何将图像添加到PHP中的图像上(如水印)
- 17. 如何在打印机上打印背景图像水印
- 18. 为图像添加水印并将其保存为图像不是php文件
- 19. 如何在图像上打印水平线并添加“厚度”?
- 20. 如何将文字水印添加到UWP中的图像?
- 21. 如何将水印添加到图像节点js
- 22. 如何为mp4视频添加水印?
- 23. 水印图像位置[asp.net]
- 24. carrierwave水印的图像
- 25. Imageresizer水印 - 改变图像
- 26. imagick图像水印透明
- 27. 水印2000+图像一次?
- 28. 放置图像水印
- 29. CListCtrl中的水印图像
- 30. 图像不可见水印
这是伟大的。谨慎向我们提供一些细节和一些现有的代码?你有什么尝试? – 2012-03-30 15:22:57
一些代码会很好 – 2012-03-30 15:23:02
你应该把这个问题的标题改为“使用gd和php的水印图像” – 2012-03-30 15:29:05