PHP水印与缩略图
文字水印
作用:在图片上添加文字或图片,目的:宣传,防止盗图
分类:文字水印和图片水印
文字水印实现原理和中文验证码一样
$img = imagecreatefromjpeg('./clk.jpg');
$color = imagecolorallocate($img,255,0,0);
$size = 15;
$angle=-30;
$fontpath = 'D:\MVVC\simhei.ttf';
$code = '我爱我的祖国';
$info = imagettfbbox($size,$angle,$fontpath,$code);
$code_w = $info[4]-$info[6];
$code_h = $info[1]-$info[7];
$x = (imagesx($img)-$code_w)/2;
$y = (imagesy($img)-$code_h)/2;
imagettftext($img,$size,$angle,$x,$y,$color,$fontpath,$code);
header('content-type:image/jpeg');
imagejpeg($img);
图片水印
$src_img = imagecreatefromjpeg('./tu.jpg');
$dst_img = imagecreatefromjpeg('./clk.jpg');
$dst_x=0;
$dst_y=0;
$src_w = imagesx($src_img);
$src_h=imagesy($src_img);
imagecopy($dst_img,$src_img,$dst_x,$dst_y,0,0,$src_w,$src_h);
header('content-type:image/jpeg');
imagejpeg($dst_img);
缩略图
require './2225.php';
$dst_img = imagecreatetruecolor(50,50);
$color = imagecolorallocate($dst_img,rand(0,255),rand(20,45),rand(1,255));
imagefill($dst_img,0,0,$color);
$src_img = imagecreatefromjpeg('./clk.jpg');
$src_w = imagesx($src_img);
$src_h = imagesy($src_img);
imagecopyresampled($dst_img,$src_img,0,0,0,0,50,50,$src_w,$src_h);
header('content-type:image/jpeg');
imagejpeg($dst_img);