PHP
·
发表于 5年以前
·
阅读量:8305
ͼƬÌi¼ÓˮӡÎÒÏaП÷λÅoÓѶ¼ÖªµÀµÄ£¬½ñÌiÎÒÃÇÀ´¿´Ò»¶ÎphpµÄͼƬÌi¼ÓˮӡÀý×Ó£¬Ï£ÍuÎÄÕÂÄܹ»°iÖuµ½¸÷λÅoÓÑ¡£
<?php
/**
* ͼƬÌi¼Óˮӡ
* $target Ô´ÎļþÂ*¾¶
* $wtrmrk_file ˮӡͼƬÂ*¾¶
* $newcopy Ìi¼ÓˮӡºoµÄͼƬÂ*¾¶
*
*/
public function watermark_image($target, $wtrmrk_file, $newcopy) {
$watermark = imagecreatefrompng($wtrmrk_file);
imagealphablending($watermark, false);
imagesavealpha($watermark, true);
$img = imagecreatefromjpeg($target);
$img_w = imagesx($img);
$img_h = imagesy($img);
$wtrmrk_w = imagesx($watermark);
$wtrmrk_h = imagesy($watermark);
$dst_x = ($img_w ) ¨C ($wtrmrk_w); // For centering the watermark on any image //phpfensi.com
$dst_y = ($img_h) ¨C ($wtrmrk_h ); // For centering the watermark on any image
imagecopy($img, $watermark, $dst_x, $dst_y, 0, 0, $wtrmrk_w, $wtrmrk_h);
imagejpeg($img, $newcopy, 100);
imagedestroy($img);
imagedestroy($watermark);
//return $img;
}
?>
ÒÔÉϾÍÊDZ¾ÎĵÄÈ«²¿ÄÚÈÝ£¬Ï£Íu¶Ô´o¼ÒµÄѧϰÓÐËu°iÖu£¬Ò²Ï£Íu´o¼Ò¶a¶aÖ§³Ö½Å±¾Ö®¼Ò¡£