Get the App
SLTechnology News&Howtos  ›  Network Security  › 

How to add text watermark to pictures by PHP

Shulou Source: shulou.com Published: 2022-06-01 01:13:46 10月03日 Update

This article mainly explains "how to add text watermark to pictures by PHP". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to add text watermarks to pictures by PHP".

PHP adds a text watermark instance to the picture, supports Chinese text watermark, whether to overwrite the original image, and customizes the background color, text color, font and so on.

Watermark water.class.php

Var $Path = ". /"; / / the directory where the picture resides relative to the relative path of the page calling this class var $FileName = ""; / / the name of the picture, such as "1.jpg" var $Text = ""; / / the watermark text to be added to the picture, which supports Chinese var $TextColor = "# ffffff"; / / the color of the text, the font color can only be black var $TextBgColor = "# 000000" for gif images. / / the color of the background bar of the text var $Font = "c://windows//fonts//simhei.ttf"; / / the directory where the font is stored, the relative path var $OverFlag = true; / / whether to overwrite the original image, default to overwrite, if not, automatically + "_ water_down" after the file name of the original image, such as "1.jpg" = > "1_water_down.jpg" var $BaseWidth = 200 / / the width of the image must be at least > = 200 before the watermark text will be added.

Call the watermark class

Include_once 'water.class.php'; $objImg = new sucaihuoWaterChinese (); $objImg- > Path = "images/"; $objImg- > FileName = "1.jpg"; $objImg- > Text = iconv (' UTF-8','GB2312',' material www.sucaihuo.com'); $objImg- > Font = ". / fonts/simhei.ttf"; / / font location $objImg- > TextBgColor = "# ffffff"; / / text background color $objImg- > TextColor = "# ffffff"; / / text color $objImg- > OverFlag = false / / whether to overwrite the original image $objImg- > Run (); at this point, I believe you have a better understanding of "how to add text watermarking to pictures by PHP". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Text watermark picture color original font background content directory path Chinese learning support practical deeper location interest name example practicality Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Huawei Shulou Information Xiaomi MySQL