


PHP is not limited to creating HTML output, it can also create and process images in a variety of formats including GIF, PNG, JPEG, WBMP and XPM. Even more conveniently, PHP can directly output the image data stream to the browser. To use image processing functions in PHP, you need to GD library to compile PHP. The GD library and PHP may require other libraries, depending on the image format you want to process. You can use the image functions in PHP to get the size of images in the following formats: JPEG, GIF, PNG, SWF, TIFF and JPEG2000. if union exif Extensions used together, you can manipulate the information stored in the header of JPEG and TIFF image files, so that you can obtain the metadata generated by digital cameras. Exif related functions can be used without the GD library.
You can use phpinfo.php to obtain the installation configuration information of the GD library:
GD supported formats
Format | supports reading Get | support writing | notes |
---|---|---|---|
JPEG | TRUE |
TRUE |
GD 1.8+ |
PNG | TRUE |
TRUE |
|
GIF | TRUE |
TRUE |
Versions between GD 1.6 and GD 2.0.28 are not supported |
XBM | TRUE |
TRUE
|
PHP 4.0.1 Start Support reading, PHP 5.0.0 starts to support writing |
XPM | TRUE |
FALSE |
PHP 4.0.1 starts to support reading. Not available on Windows platforms. GD library that requires PHP binding |
WBMP | TRUE |
TRUE |
GD 1.8+ |
WebP | TRUE | TRUE |
GD 2.1+, PHP 5.5 + |
GD and image processing functions
?gd_info — Get information about the currently installed GD library
?getimagesize — Get the image size
?getimagesizefromstring — Get image size information from a string
?image_type_to_extension — Get the file suffix of the image type
?image_type_to_mime_type — Get getimagesize, exif_read_data , exif_thumbnail, exif_imagetype MIME type of the image type returned
?image2wbmp — Output the image to a browser or file in WBMP format
?imageaffine — Return the image after affine transformation, with optional clipping area
?imageaffinematrixconcat — Concat two matrices (as in doing many ops in one go)
?imageaffinematrixget — Return an image containing the affine tramsformed src image, using an optional clipping area
?imagealphablending — Set the blending mode of the image
?imageantialias — Whether to use anti-aliasing ( antialias) functions
?imagearc — Draw an elliptical arc
?imagechar — Draw a character horizontally
?imagecharup — Draw a character vertically
?imagecolorallocate — Assign a color to an image
?imagecolorallocatealpha — Assign a color + alpha to an image
?imagecolorat — Get the color index value of a certain pixel
?imagecolorclosest — Get the index value of the color closest to the specified color
?imagecolorclosestalpha — Get the color closest to the specified color plus transparency
?imagecolorclosesthwb — Get the given color The black and white index of the color closest to the color
?imagecolordeallocate — Cancel the allocation of image color
?imagecolorexact — Get the index value of the specified color
?imagecolorexactalpha — Get the index value of the specified color plus transparency
?imagecolormatch — Make an image The color of the medium palette version better matches the true color version
?imagecolorresolve — Get the index value of the specified color or the closest alternative value possible
?imagecolorresolvealpha — Get the index value of the specified color + alpha or possible value The closest replacement value
?imagecolorset — Set the color for the specified palette index
?imagecolorsforindex — Get the color of an index
?imagecolorstotal — Get the number of colors in the palette of an image
?imagecolortransparent — Convert a certain A color is defined as a transparent color
?imageconvolution — Apply a 3x3 convolution matrix with coefficients div and offset
?imagecopy — Copy a part of the image
?imagecopymerge — Copy and merge a part of the image
?imagecopymergegray — Copy and merge with grayscale Part of an image
?imagecopyresampled — Resample a portion of an image and resize it
?imagecopyresized — Copy a portion of an image and resize it
?imagecreate — Create a new palette-based image
?imagecreatefromgd2 — Create a new image from a GD2 file or URL
?imagecreatefromgd2part — Create a new image from a part of the given GD2 file or URL
?imagecreatefromgd — Create a new image from a GD file or URL
?imagecreatefromgif — Create a new image from a file or URL.
?imagecreatefromjpeg — Create a new image from a file or URL.
?imagecreatefrompng — Create a new image from a file or URL.
?imagecreatefromstring — Create a new image from an image stream in a string
?imagecreatefromwbmp — Create a new image from a file or URL.
?imagecreatefromwebp — Create a new image from a file or URL.
?imagecreatefromxbm — Create a new image from a file or URL.
?imagecreatefromxpm — Create a new image from a file or URL.
?imagecreatetruecolor — Create a new true color image
?imagecrop — Crop an image using the given coordinates and size, x, y, width and height
?imagecropauto — Crop an image automatically using one of the available modes
?imagedashedline — Draw one Dashed line
?imagedestroy — Destroy an image
?imageellipse — Draw an ellipse
?imagefill — Area fill
?imagefilledarc — Draw an elliptical arc and fill it
?imagefilledellipse — Draw an ellipse and fill it
?imagefilledpolygon — Draw a polygon and fill it
?imagefilledrectangle — draw a rectangle and fill it
?imagefilltoborder — fill the area to the border of the specified color
?imagefilter — apply a filter to the image
?imageflip — Flips an image using a given mode
?imagefontheight — get the font height
?imagefontwidth — Get the font width
?imageftbbox — Give a text box using a FreeType 2 font
?imagefttext — Write text to an image using a FreeType 2 font
?imagegammacorrect — Apply gamma correction to a GD image
?imagegd2 — Output a GD2 image to Browser or file
?imagegd — Export GD image to browser or file
?imagegif — Export image to browser or file.
?imagegrabscreen — Captures the whole screen
?imagegrabwindow — Captures a window
?imageinterlace — Activate or disable interlacing
?imageistruecolor — Check whether the image is a true color image
?imagejpeg — Output the image to a browser or file.
?imagelayereffect — Set the alpha blending flag to use the bundled libgd layering effect
?imageline — Draw a line segment
?imageloadfont — Load a new font
?imagepalettecopy — Copy a palette from one image to another
?imagepalettetotruecolor — Converts a palette based image to true color
?imagepng — Output an image in PNG format to a browser or file
?imagepolygon — Draw a polygon
?imagepsbbox — Give a text box using PostScript Type1 font
?imagepsencodefont — Change the character encoding vector in a font
?imagepsextendfont — Extend or condense a font
?imagepsfreefont — Free up the memory occupied by a PostScript Type 1 font
?imagepsloadfont — Load a PostScript Type 1 font from a file
?imagepsslantfont — Skew a font
?imagepstext — Draw a text string on an image using a PostScript Type1 font
?imagerectangle — Draw a rectangle
?imagerotate — Rotate an image by a given angle
?imagesavealpha — Set a flag to save a PNG image intact when saving it Alpha channel information (as opposed to a single transparent color)
?imagescale — Scale an image using the given new width and height
?imagesetbrush — Set the brush image used to draw lines
?imagesetinterpolation — Set the interpolation method
?imagesetpixel — Draw A single pixel
?imagesetstyle — Set the style of the line drawing
?imagesetthickness — Set the width of the line drawing
?imagesettile — Set the texture used for filling
?imagestring — Draw a line of string horizontally
?imagestringup — Vertically Draw a line of string
?imagesx — Get the image width
?imagesy — Get the image height
?imagetruecolortopalette — Convert a true color image to a palette image
?imagettfbbox — Get the range of text using TrueType fonts
?imagettftext — Use TrueType Font writes text to images
?imagetypes — Returns the image types supported by the current PHP version
?imagewbmp — Outputs images in WBMP format to a browser or file
?imagewebp — Outputs images in WebP format to a browser or file
?imagexbm — Output XBM images to a browser or file
?iptcembed — Embed binary IPTC data into a JPEG image
?iptcparse — Parse binary IPTC blocks into individual tags
?jpeg2wbmp — Convert JPEG image files to WBMP Image file
?png2wbmp - Convert PNG image file to WBMP image file
The GD library can be used under both Linux and Windows systems. The functions are exactly the same, but the graphics coordinates will be offset. If systems are migrated to each other, the interface must be reviewed again.
Draw Chinese on image
<?php // 定义输出为图像类型 header("content-type:image/gif"); // 创建画布 $im = imagecreate(400, 200); // 背景 imagecolorallocate($im, 225, 66, 255); // 文本颜色 $text_color = imagecolorallocate($im, 233, 14, 91); $motto = "Test String 长白山"; //imagestring 默认英文编码,只支持UTF-8 //imagestring($im, 2, 0, 0, $motto, $text_color); //当代码文件为: //ANSI编码,需要转换 //UTF-8编码,不需要转换 //$motto = iconv("gb2312", "utf-8", $motto); imageTTFText($im, 20, 0, 0, 100, $text_color, "c:/windows/fonts/simhei.ttf", $motto); imagegif($im); imagedestroy($im); ?>

Generate verification code
<?php session_start(); header("Content-type:image/png"); $imWidth = 70; $imHeight= 18; $im = imagecreate($imWidth, $imHeight); imagecolorallocate($im, 255, 255, 255); srand(microtime() * 100000); for($ix=0; $ix<4; $ix++) $number .= dechex(mt_rand(0, 15)); $_SESSION[check_check] = $number; for($ix=0; $ix<4; $ix++) { $x = $imWidth*$ix/ 4 + mt_rand(1, 8); $y = mt_rand(1, $imHeight / 4); $ft = mt_rand(3, 5); $cor = imagecolorallocate($im, mt_rand(0, 100), mt_rand(0, 150), mt_rand(0, 200)); imagestring($im, $ft, $x, $y, $_SESSION[check_check][$ix], $cor); } imagepng($im); imagedestroy($im); ?>

Copyright statement: This article is a blog Original article by Zhulangya Studio, not yet published No reproduction is allowed without the permission of the blogger.
The above introduces PHP's use of the GD library to generate verification codes and draw Chinese characters on images, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。

本文将介绍七种利用免费的BingImageCreator获得高质量输出的方法。BingImageCreator(现称为MicrosoftDesigner的ImageCreator)是一个出色的在线人工智能艺术生成器之一。它能根据用户的提示生成高度逼真的视觉效果。提示越具体、清晰和创意,生成的效果也会更出色。BingImageCreator在创建高质量图像方面取得了重大进展。它现在使用Dall-E3培训模式,显示出更高水平的细节和现实主义。然而,它能否始终如一地生成高清结果取决于几个因素,包括快速


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version
Chinese version, very easy to use

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Linux new version
SublimeText3 Linux latest version