PHP development text watermark tutorial output picture
Output picture
<?php
/*打开图片*/
//1.配置图片路径(填入你的图片路径)
$src="https://img.php.cn/upload/course/000/000/004/581454f755fb1195.jpg";
//获取图片信息
$info = getimagesize($src);
//通过图像的编号来获取图像的类型
$type=image_type_to_extension($info[2],false);
//在内存中创建一个和我们图像类型一样的图像
$fun = "imagecreatefrom{$type}";
//把图片复制到我们的内存中
$image=$fun($src);
/*操作图片*/
//设置字体的路径
$font="/tpl/Index/Static/css/img/fonts/Christmas.ttf";
//添加内容
$content="欢迎来到php中文网";
//设置字体的颜色和透明度
$col=imagecolorallocatealpha($image,255,255,255,30);
//写入文字
imagettftext($image,20,0,20,30,$col,$font,$content);
/*输出图片*/
//浏览器输出
header("Content-type:".$info['mime']);
$func="image{$type}";
$func($image);
//保存图片
$func($image,'FFF.'.$type);
/*销毁图片*/
imagedestroy($image);
?>/*输出图片*/
//浏览器输出
header("Content-type:".$info['mime']);
$func="image{$type}";
$func($image);
//保存图片
$func($image,'FFF.'.$type);
/*销毁图片*/
imagedestroy($image);Define a variable $func.
Output directly from the browser.
Or save the image output with a customized name.
In this way, adding text watermark to the picture is completed.
new file
<?php
/*打开图片*/
//1.配置图片路径(填入你的图片路径)
$src="https://img.php.cn/upload/course/000/000/004/581454f755fb1195.jpg";
//获取图片信息
$info = getimagesize($src);
//通过图像的编号来获取图像的类型
$type=image_type_to_extension($info[2],false);
//在内存中创建一个和我们图像类型一样的图像
$fun = "imagecreatefrom{$type}";
//把图片复制到我们的内存中
$image=$fun($src);
/*操作图片*/
//设置字体的路径
$font="/tpl/Index/Static/css/img/fonts/Christmas.ttf";
//添加内容
$content="欢迎来到php中文网";
//设置字体的颜色和透明度
$col=imagecolorallocatealpha($image,255,255,255,30);
//写入文字
imagettftext($image,20,0,20,30,$col,$font,$content);
/*输出图片*/
//浏览器输出
header("Content-type:".$info['mime']);
$func="image{$type}";
$func($image);
//保存图片
$func($image,'FFF.'.$type);
/*销毁图片*/
imagedestroy($image);
?>
Preview
Clear
Students who have watched this course are also learning
Let's briefly talk about starting a business in PHP
Quick introduction to web front-end development
Large-scale practical Tianlongbabu development of Mini version MVC framework imitating the encyclopedia website of embarrassing things
Getting Started with PHP Practical Development: PHP Quick Creation [Small Business Forum]
Login verification and classic message board
Computer network knowledge collection
Quick Start Node.JS Full Version
The front-end course that understands you best: HTML5/CSS3/ES6/NPM/Vue/...[Original]
Write your own PHP MVC framework (40 chapters in depth/big details/must read for newbies to advance)
















The courseware is not available for download at the moment. The staff is currently organizing it. Please pay more attention to this course in the future~ 