如何使用PHP将水印应用于上传的图片 [英] How to apply a watermark to an uploaded picture using PHP
本文介绍了如何使用PHP将水印应用于上传的图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用PHP为上传的图片应用水印?
How can I apply a watermark to an uploaded picture using PHP?
示例链接: http://www.kitebeaches.com/kitesurf/uploadPicture/NIRVANA_Club_Village.html
推荐答案
试试这个(改编自 sitepoint ):
<?php
header('content-type: image/jpeg');
$yourimagefile = 'something.jpg' // the image you're wanting to watermark
$watermark = imagecreatefrompng('watermark.png'); // the watermark
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$image = imagecreatetruecolor($watermark_width, $watermark_height);
$image = imagecreatefromjpeg($yourimagefile);
$size = getimagesize($yourimagefile);
$dest_x = $size[0] - $watermark_width - 5;
$dest_y = $size[1] - $watermark_height - 5;
imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);
imagejpeg($image);
imagedestroy($image);
imagedestroy($watermark);
这篇关于如何使用PHP将水印应用于上传的图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文