将心比心,方得人心~

php 图像水印的处理方法

周洲 2017-04-06 21:16:07

php 图像水印的处理方法

<?php

	define('__DIR__',dirname(__FILE__).'\\');

	//加载已有的图像
	header('Content-Type: image/png'); 
	//imagecreatefrompng -- 从 PNG 文件或 URL 新建一图像
	//用image载入图像,是可以编辑图像
	//在载入的图像中,加入一个小水印
	//通过魔法常量__FILE__
	$im = imagecreatefrompng(__DIR__.'1.png');
	$white = imagecolorallocate($im,255,255,255);
	imagestring($im,5,10,10,'http://www.baiduyo.com',$white);	
	imagepng($im);
	imagedestroy($im);

用系统字体添加水印

<?php

	define('__DIR__',dirname(__FILE__).'\\');
	//加载已有的图像
	header('Content-Type: image/png'); 
	//imagecreatefrompng -- 从 PNG 文件或 URL 新建一图像
	//用image载入图像,是可以编辑图像
	//在载入的图像中,加入一个小水印
	//通过魔法常量__FILE__
	$im = imagecreatefrompng(__DIR__.'1.png');
	$white = imagecolorallocate($im,255,255,255);
	//字体文件
	$text = iconv('gbk','utf-8','admin');
	//font字体还必须支持中文
	$font = 'C:\WINDOWS\Fonts\SIMHEI.TTF';
	//采用系统提供的字体
	//第二参数,是字体的大小,第三个参数是旋转角度,4,5参数是坐标
	imagettftext($im,40,30,45,110,$white,$font,$text);	
	imagepng($im);
	imagedestroy($im);


打赏

『微信打赏』

Tag标签php 

我是有底线的