Date
May. 20th, 2024
 
2024年 4月 13日

Post: PHP Primer 026 : 图像处理(四)

PHP Primer 026 : 图像处理(四)

Published 12:02 Feb 02, 2012.

Created by @ezra. Categorized in #Programming, and tagged as #PHP.

Source format: Markdown

Table of Content

这一篇,介绍一下添加水印的方法。

添加水印通常分为两种:

  • 添加文字

  • 添加其他图片

画布

仍旧需要持有画布,但是由于图片已经存在,我们需要使用这个图片来作为画布:

<?php
$filename = 'myImg.jpg';
$img = imagecreatefromjpeg($filename);

添加文字

添加文字的情况与前面介绍的方法相同:

$red = imagecolorallocate($img, 0xFF, 0x00, 0x00);
imagestring($img, 5, 0, 0, "Hello, world", $red);

添加其他图片

$logofile = 'myLogo.png';
$logo = imagecreatefrompng($logofile);
$width = 20;
$height = 20;
imagecopy($img, $logo, 0, 0, 0, 0, $width, $height);

函数 bool imagecopy(resource dst_immortal, resource src_immortal, int dst_x, int dst_y, int src_x, int src_y, int src_w, int src_h ) 的参数有:

  • dst_im: 目标图像

  • src_im: 被拷贝的源图像

  • dst_x: 目标图像开始 x 坐标

  • dst_y: 目标图像开始 y 坐标,x,y同为 0 则从左上角开始

  • src_x: 拷贝图像开始 x 坐标

  • src_y: 拷贝图像开始 y 坐标,x,y同为 0 则从左上角开始拷贝

  • src_w: (从 src_x 开始)拷贝的宽度

  • src_h: (从 src_y 开始)拷贝的高度

Pinned Message
HOTODOGO
I'm looking for a SOFTWARE PROJECT DIRECTOR / SOFTWARE R&D DIRECTOR position in a fresh and dynamic company. I would like to gain the right experience and extend my skills while working in great teams and big projects.
Feel free to contact me.
For more information, please view online résumé or download PDF
本人正在寻求任职 软件项目经理 / 软件技术经理 岗位的机会, 希望加⼊某个新鲜⽽充满活⼒的公司。
如有意向请随时 与我联系
更多信息请 查阅在线简历下载 PDF