imageloadfont
Description
The imageloadfont of Image for PHP load a new font.
Syntax
imageloadfont( string $filename ): GdFont|false
Parameters
filename
The font file format is currently binary and architecture dependent. This means you should generate the font files on the same type of CPU as the machine you are running PHP on.
Byte Position | Type | Description |
---|---|---|
byte 0-3 | int | number of characters in the font |
byte 4-7 | int | value of first character in the font (often 32 for space) |
byte 8-11 | int | pixel width of each character |
byte 12-15 | int | pixel height of each character |
byte 16- | char | array with character data, one byte per pixel in each character, for a total of (nchars*width*height) bytes. |
Return
Returns an GdFont instance, or false on failure.
Examples
1 · return
<? $filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/gdf/1.gdf'; $return = imageloadfont($filename); var_dump($return);
object(GdFont)#1 (0) { }
2 · base64
<? $width = 100; $height = 100; $image = imagecreatetruecolor($width, $height); $red = 255; $green = 255; $blue = 255; $color = imagecolorallocate($image, $red, $green, $blue); $filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/gdf/1.gdf'; $font = imageloadfont($filename); $x = 0; $y = 0; $string = "string"; imagestring($image, $font, $x, $y, $string, $color); $filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/gdf/2.gdf'; $font = imageloadfont($filename); $x = 0; $y = 20; $string = "string"; imagestring($image, $font, $x, $y, $string, $color); $filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/gdf/3.gdf'; $font = imageloadfont($filename); $x = 0; $y = 40; $string = "string"; imagestring($image, $font, $x, $y, $string, $color); ob_start(); imagepng($image); $output = ob_get_clean(); echo '<!doctype html> <html> <body> <img src="data:image/png;base64,' . base64_encode($output) . '"> </body> </html>';
<!doctype html> <html> <body> <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAB0ElEQVR4nO3b27KDIAxAUXD8/1+mD14GAUNwVILd66kHqaPhcpBY53CjEELvS7Bikg9fiFQI4avxrQQLsfn2M3rvbz+nEd6Vxtpyw0l5XOi9j4/uAdoLk5K4fl45P49N09n8Is87rbNSXH/5POK8tg7DvEmTfpR/86zwLApCb83LbVqDVRxTgtbxYnx8KU3fuI13zO7Y7MsqiQgWzZrJIv9HVq2pjPgQU9WusCiNb/K5LkbnvW6Ih6T7V/B69qOTMPRsyMAEAACoGW61qVRflH71zh/xWrDst4q0UxrvtyTlxQREsbJcX7/5Y0XSpPKfLtshKFbQ1JdPYlBlP+vMn+7Buy0lc7ltvxEIjUMqTEh8PUGY+Gw6bP7tIXvz0ocI02JyvSfXsOl4DUprKkxIsu5Hm7I1mq8kXZgUnKS6RrGmc0u2vjYAAACAP3ThqW2UB70LDL1FYx+/sGhAz2pQfmdf84J/cetGTuE0HTKosptcPBRH5CxeZyWaz2YxDBtcn+CXXmC8L9xrTYW5ofbCe1mHod+4EbZ3e+k5Z8U9uuNl6PX80YAb8feGwmInzuy3psL+au5/XDwAhxiMpMIAAAAAAAAAAAAAAAAAAAAAAAB+sNlTHLs39T4AAAAASUVORK5CYII="> </body> </html>
Links
Related
Image
- gd_info
- getimagesize
- getimagesizefromstring
- image_type_to_extension
- image_type_to_mime_type
- imageaffine
- imageaffinematrixconcat
- imageaffinematrixget
- imagealphablending
- imageantialias
- imagearc
- imageavif
- imagebmp
- imagechar
- imagecharup
- imagecolorallocate
- imagecolorallocatealpha
- imagecolorat
- imagecolorclosest
- imagecolorclosestalpha
- imagecolorclosesthwb
- imagecolordeallocate
- imagecolorexact
- imagecolorexactalpha
- imagecolormatch
- imagecolorresolve
- imagecolorresolvealpha
- imagecolorset
- imagecolorsforindex
- imagecolorstotal
- imagecolortransparent
- imageconvolution
- imagecopy
- imagecopymerge
- imagecopymergegray
- imagecopyresampled
- imagecopyresized
- imagecreate
- imagecreatefromavif
- imagecreatefrombmp
- imagecreatefromgif
- imagecreatefromjpeg
- imagecreatefrompng
- imagecreatefromstring
- imagecreatefromtga
- imagecreatefromwbmp
- imagecreatefromwebp
- imagecreatefromxbm
- imagecreatefromxpm
- imagecreatetruecolor
- imagecrop
- imagecropauto
- imagedashedline
- imagedestroy
- imageellipse
- imagefill
- imagefilledarc
- imagefilledellipse
- imagefilledpolygon
- imagefilledrectangle
- imagefilltoborder
- imagefilter
- imageflip
- imagefontheight
- imagefontwidth
- imageftbbox
- imagefttext
- imagegammacorrect
- imagegetclip
- imagegetinterpolation
- imagegif
- imageinterlace
- imageistruecolor
- imagejpeg
- imagelayereffect
- imageline
- imageopenpolygon
- imagepalettecopy
- imagepalettetotruecolor
- imagepng
- imagepolygon
- imagerectangle
- imageresolution
- imagerotate
- imagesavealpha
- imagescale
- imagesetbrush
- imagesetclip
- imagesetinterpolation
- imagesetpixel
- imagesetstyle
- imagesetthickness
- imagesettile
- imagestring
- imagestringup
- imagesx
- imagesy
- imagetruecolortopalette
- imagettfbbox
- imagettftext
- imagetypes
- imagewbmp
- imagewebp
- imagexbm
- iptcembed
- iptcparse