How to apply a watermark to an uploaded picture us

2020-05-07 10:38发布

问题:

How can I apply a watermark to an uploaded picture using PHP?

Example LINK: http://www.kitebeaches.com/kitesurf/uploadPicture/NIRVANA_Club_Village.html

回答1:

Try this (adapted from 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);  


回答2:

Previously on SO:

  • How can I add an image onto an image in PHP like a watermark?
  • Can this watermark function be improve (PHP)?
  • How to watermark GIF image with 24-bit PNG with transparency in PHP?
  • How to edit and watermark animated gifs, preferably through php?