Home php教程 php手册 php 给图片加上文字水印代码

php 给图片加上文字水印代码

Jun 13, 2016 am 09:48 AM
php under code add picture support letter watermark of website

给图片加水印是很多网站会做的事情,下面这段代码只支持给图片加上文字水印哦,现在暂时只支持英文的,如果要让此程序能支持中文汉字就把$font=\'verdana.ttf\';调用一个中文字体就OK了。

php教程 给图片加上文字水印代码
/*
给图片加水印是很多网站会做的事情,下面这段代码只支持给图片加上文字水印哦,现在暂时只支持英文的,如果要让此程序能支持中文汉字就把$font='verdana.ttf';调用一个中文字体就ok了。
*/

$image=$_get[id];
$im=getimagesize($image);
//print_r($im);
//以下是读取文字的宽高
$font='verdana.ttf';//字体
$font_size = $im[0]/20;//文字大小
$size=imagettfbbox($font_size,0,$font,'bKjia.c0m');//文字宽高
$textwidth = $size [4];//取出宽
$textheight = abs( $size [7] );//取出高

$pic_w=abs(($im[0]-$textwidth)/2);//文字存放宽的位置
$pic_h=abs(($im[1]-$textheight)/2);//文字存放高的位置

 switch($im[2])               
{
case 1:
$im=imagecreatefromgif($image);
break;

case 2:
$im=imagecreatefromjpeg($image);
break;

case 3:
$im=imagecreatefrompng($image);
break;
}
//$logo="2.png";//商标图片
//$ing=getimagesize($logo);
//
// switch($ing[2])               
//
//{
//case 1:
//$in=imagecreatefromgif($logo);
//break;
//
//case 2:
//$in=imagecreatefromjpeg($logo);
//break;
//
//case 3:
//$in=imagecreatefrompng($logo);
//break;
//}
//imagecopy($im,$in,200,3,0,0,'120','110');//图片合并
 $te = imagecolorclosestalpha($im,255,255,255,60);//最后一个数值是透明度越大越透明
$str=iconv("gbk","utf-8","bKjia.c0m"); //设置文字的内容和编码,很简单吧

imagettftext($im,$font_size,0,$pic_w,$pic_h,$te,'verdana.ttf',$str);

header("content-type: image/jpeg");
imagejpeg($im);


?>

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

How To Set Up Visual Studio Code (VS Code) for PHP Development

See all articles