search
HomeBackend DevelopmentPHP TutorialGenerate artistic font image watermark code_PHP tutorial
Generate artistic font image watermark code_PHP tutorialJul 13, 2016 am 10:45 AM
andcodefunctionpicturefontFormatwatermarkNoticegenerateBackground pictureArt

//adv0.jpg is the background image, please note that the function corresponds to the image format
$im = imagecreatefromjpeg('/www/law/images/demo/adv0.jpg');
$font_color = imagecolorallocate ($im, 0, 250, 10); //This is the text color, green

$text = "Zhang San's blog"; 
$font_file = "/www/font/hyi_xkj.ttf"; //The linux absolute path of the font

//26: font, 0 is the angle, 10, 36 are the coordinates, $font_color is the text color, font is the font, and the text is the filled in text
imagettftext($im, 26,0, 10, 36, $font_color ,$font_file, $text); Insert text into the picture

// output image
header ('content-type: image/png');                                                // Even pictures copied from jpg can be output as png,                                   imagepng ($im);
// clean up
imagedestroy($im);

Method 2 of generating watermark


public final class imageutils {
public imageutils() {


}

public final static string getpressimgpath(){

return applicationcontext.getrealpath("/template/data/util/shuiyin.gif");

}

/**

* Print pictures onto pictures

* @param pressimg -- watermark file
* @param targetimg -- target file
* @param x
* @param y
*/
public final static void pressimage(string pressimg, string targetimg, int x, int y) {
try {
file _file = new file(targetimg);
image src = imageio.read(_file);
int wideth = src.getwidth(null);
int height = src.getheight(null);
bufferedimage image = new bufferedimage(wideth, height,
bufferedimage.type_int_rgb);
graphics g = image.creategraphics();
g.drawimage(src, 0, 0, width, height, null);

// Watermark file

file _filebiao = new file(pressimg);

image src_biao = imageio.read(_filebiao);
int wideth_biao = src_biao.getwidth(null);
int height_biao = src_biao.getheight(null);
g.drawimage(src_biao, wideth - wideth_biao - x, height - height_biao -y, wideth_biao,
height_biao, null);
// /
g.dispose();
fileoutputstream out = new fileoutputstream(targetimg);
jpegimageencoder encoder = jpegcodec.createjpegencoder(out);
encoder.encode(image);
out.close();
} catch (exception e) {
e.printstacktrace();
}
}

/**

* Print text watermark image

* @param presstext --Text
* @param targetimg -- target image
* @param fontname -- font name
* @param fontstyle -- font style
* @param color -- font color
* @param fontsize -- font size
* @param x -- offset
* @param y
*/

public static void presstext(string presstext, string targetimg, string fontname,int fontstyle, int color, int fontsize, int x, int y) {

try {

file _file = new file(targetimg);
image src = imageio.read(_file);
int wideth = src.getwidth(null);
int height = src.getheight(null);
bufferedimage image = new bufferedimage(wideth, height,
bufferedimage.type_int_rgb);
graphics g = image.creategraphics();
g.drawimage(src, 0, 0, width, height, null);
// string s=www.bKjia.c0m;
g.setcolor(color.red);
g.setfont(new font(fontname, fontstyle, fontsize));

g.drawstring(presstext, width - fontsize - x, height - fontsize/2 - y);

g.dispose();
fileoutputstream out = new fileoutputstream(targetimg);
jpegimageencoder encoder = jpegcodec.createjpegencoder(out);
encoder.encode(image);
out.close();
} catch (exception e) {
system.out.println(e);
}
}

public static void main(string[] args) {

pressimage("c:/shuiyin/shuiyin.gif", "c:/shuiyin/dsc02342.jpg", 20 ,20);

}
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/633027.htmlTechArticle//adv0.jpg is the background image. Note that the function corresponds to the image format $im = imagecreatefromjpeg('/www/ law/images/demo/adv0.jpg'); $font_color = imagecolorallocate ($im, 0, 250, 10); //This is...
Statement
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
如何在 Microsoft Word 中添加艺术页面边框如何在 Microsoft Word 中添加艺术页面边框Apr 27, 2023 pm 08:25 PM

您是否厌倦了一直在Word文档上看到传统的黑色边框?您是否正在寻找如何为您的文档添加一些彩色和艺术边框以使其更具吸引力和乐趣的方法?在Word文档的不同页面中添加不同的艺术边框怎么样?或者一次将单个艺术边框应用于文档中的所有页面?我知道你和我们一样对这整个艺术边界的事情感到兴奋!直接阅读本文,了解如何成功地将艺术边框应用于Word文档。第1部分:如何将相同的艺术页面边框应用于Word文档中的所有页面第1步:打开Word文档,然后单击顶部功能区中的“设计”选项卡。在DESIGN选

不再担心下班前被领导叫住开小会,AI助手帮你自动生成会议纪要不再担心下班前被领导叫住开小会,AI助手帮你自动生成会议纪要Sep 04, 2023 pm 11:21 PM

讯飞听见升级会议纪要功能,可以将口语表述直接转化为书面稿,AI能够根据录音总结会议纪要。AI能够帮助您完成会议纪要的撰写工作8月31日,讯飞听见网页端进行了版本升级,新增了PC端实时录音功能,能够利用人工智能智能生成会议纪要。这一功能的推出将大大提高用户在会议后整理内容、跟进重点工作事项的效率。对于经常参加会议的人来说,这个功能无疑是一个非常实用的工具,能够节省大量时间和精力该功能的应用场景主要是PC电脑端录音转文字自动生成会议纪要,旨在为用户提供最优质的服务和最先进的技术,快速提升办公效率的产

如何使用PHP生成可刷新的图片验证码如何使用PHP生成可刷新的图片验证码Sep 13, 2023 am 11:54 AM

如何使用PHP生成可刷新的图片验证码随着互联网的发展,为了防止恶意攻击和机器自动操作现象,很多网站都使用了验证码来进行用户验证。其中一种常见的验证码类型就是图片验证码,通过生成一张包含随机字符的图片,要求用户输入正确的字符才能进行后续操作。本文将介绍如何使用PHP生成可刷新的图片验证码,并提供具体的代码示例。步骤一:创建验证码图片首先,我们需要创建一个用于生

如何使用PHP进行基本的自然语言生成如何使用PHP进行基本的自然语言生成Jun 22, 2023 am 11:05 AM

自然语言生成是一种人工智能技术,它能够将数据转换为自然语言文本。在当今的大数据时代,越来越多的业务需要将数据可视化或呈现给用户,而自然语言生成正是一种非常有效的方法。PHP是一种非常流行的服务器端脚本语言,它可以用于开发Web应用程序。本文将简要介绍如何使用PHP进行基本的自然语言生成。引入自然语言生成库PHP自带的函数库并不包括自然语言生成所需的功能,因此

使用Python中的pyWaffle生成一个华夫饼图使用Python中的pyWaffle生成一个华夫饼图Aug 17, 2023 am 11:49 AM

数据可视化对于高效的信息理解和展示至关重要。在众多可用的图表类型中,华夫饼图以方形瓦片在网格状结构中显示数据的新颖方式。强大的Python模块PyWaffle方便了华夫饼图的开发,类似于许多计算和数据分析方法。在本文中,我们将看看如何使用复杂的Python模块PyWaffle创建华夫饼图。让我们安装PyWafle并看看如何使用它来可视化分类数据。在您的cmd中运行以下命令来安装该库,然后将其导入到您的代码中pipinstallpywaffleExample1的中文翻译为:示例1在这个例子中,我们

女王登基70周年,世上首个超逼真人形机器艺术家献上肖像画作,被锐评“缺少信念”女王登基70周年,世上首个超逼真人形机器艺术家献上肖像画作,被锐评“缺少信念”Apr 08, 2023 pm 08:11 PM

大数据文摘出品作者:Caleb为庆祝英国女王伊丽莎白二世登基70周年,英国也是早早就洋溢出了庆典的味道。据了解,英国将于6月2日至5日连放4天公众假期,并在期间举行多项庆祝活动。英国皇家铸币厂也在精心打造有史以来最大的硬币,直径220毫米,重15公斤,面值15000英镑,耗时近400小时打造,是该厂1100年来生产的最大硬币。这枚金币一面雕刻着代表英国女王伊丽莎白二世的符号EⅡR,周围环绕着代表英国的玫瑰、水仙、蓟和三叶草。另一面有女王骑在马背上的图案。在这么热闹的日子里,AI当然也必须来凑一凑

如何使用PHP生成带有时间限制的二维码?如何使用PHP生成带有时间限制的二维码?Aug 26, 2023 pm 04:34 PM

如何使用PHP生成带有时间限制的二维码?随着移动支付和电子门票的普及,二维码成为了一种常见的技术。在很多场景中,我们可能需要生成一种带有时间限制的二维码,即使在一定时间后,该二维码也将失效。本文将介绍如何使用PHP生成带有时间限制的二维码,并提供代码示例供参考。安装PHPQRCode库要使用PHP生成二维码,我们需要先安装PHPQRCode库。这个库

word目录生成错乱怎么办word目录生成错乱怎么办Feb 20, 2024 am 08:08 AM

word目录生成错乱怎么办随着科技的发展,电子文档已经成为我们日常工作和学习中不可或缺的一部分。而在编辑电子文档时,尤其是长篇文章或论文中,目录的生成是一个非常重要的步骤。目录能够方便读者查找到文章的内容和结构,提高阅读效率。然而,有时候我们在生成目录的过程中会遇到一些问题,比如目录生成出错,顺序混乱等。那么,如果word目录生成错乱,我们应该如何解决呢?首

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment