Home Backend Development PHP Tutorial php在图片上增加矩形框并加入水印

php在图片上增加矩形框并加入水印

Jun 13, 2016 pm 01:02 PM
font jpeg size start str

php在图片下增加矩形框并加入水印

 //统计混合汉字英文字符的实际字符数,只对gb2312码有效 
function str_len($str){ 
$length=0; 
for($i=0;$i<strlen if>0x80) 
$i++; 
$length++; 
} 
return $length; 
} 

//待添加水印图片 
$imagefile = "3.jpg"; 

//待添加文字 
$str = "照片由戈多上传于".date("Y年m月d日H时i分s秒"); 

//由于掺杂汉字,原生函数无法统计真实字符数,造成水印文字无法居中 
//所以自己写了个函数统计,如果有mbstring库支持,换用mb_strlen也可以 
$len = str_len($str); 

//如果源程序基于utf-8编码,不需要做字符转换,删除此行 
$str = iconv('gb2312','utf-8',$str); 

//获取原图大小 
$size = getimagesize($imagefile); 

//底边矩形高度 
$bottom_height = 20; 

//字体大小 
$font_size = 10; 

$im = imagecreatetruecolor($size[0], $size[1]+$bottom_height); 

//底边矩形背景色,修改最后三个RGB参数改变颜色 
$bgcolor = imagecolorallocate($im,100,120,100); 

//字体颜色 
$ftcolor = imagecolorallocate($im,255,255,255); 
imagefill($im,0,0,$bgcolor); 

//默认从jpeg创建,如从其他图片创建,可根据扩展名选择函数 
$jpeg = imagecreatefromjpeg($imagefile); 
imagecopy($im,$jpeg,0,0,0,0,$size[0],$size[1]); 

$start_x = ($size[0]-$len*$font_size)/2; 
$start_x = ($start_x>0?$start_x:0); 
$start_y = $size[1]+$font_size+($bottom_height-$font_size)/2; 

//C:/windows/fonts/SIMHEI.TTF为ttf字库文件,此处为黑体 
imagettftext($im,$font_size,0,$start_x,$start_y,$ftcolor,"C:/windows/fonts/SIMHEI.TTF",$str); 

header("Content-type: image/jpeg"); 
imagejpeg($im); 
imageclose($im); 
imageclose($jpeg); 
?> 

</strlen>
Copy after login

?

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 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 ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

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)

Use java's File.length() function to get the size of the file Use java's File.length() function to get the size of the file Jul 24, 2023 am 08:36 AM

Use Java's File.length() function to get the size of a file. File size is a very common requirement when dealing with file operations. Java provides a very convenient way to get the size of a file, that is, using the length() method of the File class. . This article will introduce how to use this method to get the size of a file and give corresponding code examples. First, we need to create a File object to represent the file we want to get the size of. Here is how to create a File object: Filef

What should I do if docker start cannot start? What should I do if docker start cannot start? Oct 21, 2022 pm 03:43 PM

Solution to docker start failure: 1. Check the running status, and then release the occupied memory through the "echo 3 &gt; /proc/sys/vm/drop_caches" command; 2. Use "$netstat -nltp|grep .. ." command to check whether the port has been occupied. If it is found to be occupied after going online, change it to an available port and restart.

Python's Pygame Font module - how to use text and fonts? Python's Pygame Font module - how to use text and fonts? Apr 23, 2023 pm 11:19 PM

Pygame's Font text and font Pygame uses the pygame.font module to create a font object to achieve the purpose of drawing text. Commonly used methods of this module are as follows: Name Description pygame.font.init() Initialize the font module pygame.font.quit() Uninitialize the font module pygame.font.get_init() Check whether the font module has been initialized and return a Boolean value . pygame.font.get_default_font() gets the file name of the default font. Returns the file name of the font in the system pygame.font.get_fonts() gets all

What image compression coding standard is jpeg? What image compression coding standard is jpeg? Dec 31, 2020 pm 02:32 PM

JPEG is a compression coding standard for continuous-tone still images; it mainly uses a joint coding method of predictive coding, discrete cosine transform and entropy coding to remove redundant images and color data. It is a lossy compression format, which can convert images Compression requires a small storage space and will cause damage to image data to a certain extent.

What format is jpeg What format is jpeg Nov 25, 2022 pm 02:46 PM

JPEG is an image format saved using a lossy compression method, and the file extension is ".jpg" or ".jpeg"; as a result of compression, the output image cannot take into account both quality and size. The JPEG format has long been the choice for storing and transmitting photographic images over the web, and almost all operating systems now have viewers that support the visualization of JPEG images, which are also often stored with the JPG extension.

Are the image quality of HEIF and JPEG formats the same? Are the image quality of HEIF and JPEG formats the same? Mar 17, 2023 pm 06:17 PM

No, the picture quality in HEIF format is better. HEIC is a high-fidelity compression format that will reduce the disk or memory space occupied by images while maintaining image quality; while JPEG is a lossy image format, so the same image taken with HEIC will be smaller, but the HEIC image quality is better. As an encapsulation format, HEIF can hold much more things than JPEG; it can not only store static images and EXIF ​​information metadata, but also animations, image sequences, and even videos, audios, etc. The types of data stored must be Much richer.

Convert JPEG image files to WBMP image files with PHP Convert JPEG image files to WBMP image files with PHP Mar 21, 2024 am 10:36 AM

This article will explain in detail about converting JPEG image files to WBMP image files with PHP. The editor thinks it is quite practical, so I share it with you as a reference. I hope you can gain something after reading this article. Introduction to converting JPEG image files to WBMP image files JPEG (Joint Photographic Experts Group) and WBMP (Wireless Bitmap) are two widely used image file formats. JPEG is used to store high-quality photos and images, while WBMP is used to store simple black-and-white images, commonly used on mobile devices and e-paper displays. This article will guide you to convert JPEG image files to WBMP image files using php. Steps to Install GD Library First, you need to install GD Library, which is a popular PHP

What to do if node start reports an error What to do if node start reports an error Dec 29, 2022 pm 01:55 PM

Solution to node start error: 1. Execute "node xx.js" directly in the terminal; 2. Add start startup item "scripts": {"test": "echo \"Error: no test specified\" && exit 1 ","start":"node service.js"}"; 3. Re-execute "npm start".

See all articles