Php 更改ImageString使用的字体
我有以下PHP代码:Php 更改ImageString使用的字体,php,Php,我有以下PHP代码: <?php //Other part of code Header("Content-type: image/png"); $im = imagecreatefromPng("./images/signatures/background.png"); $red = ImageColorAllocate($im, 255, 0, 0); $black = ImageColorAllocate($im, 0, 0, 0); ImageStrin
<?php
//Other part of code
Header("Content-type: image/png");
$im = imagecreatefromPng("./images/signatures/background.png");
$red = ImageColorAllocate($im, 255, 0, 0);
$black = ImageColorAllocate($im, 0, 0, 0);
ImageString($im, 5, 15, 5, "$callsign", $black);
ImageString($im, 5, 15, 20, "$name $surname", $black);
ImageString($im, 5, 15, 35, "Location: $location", $black);
ImageString($im, 5, 15, 50, "HUB: $hub", $black);
ImageString($im, 5, 15, 65, "Hours: $hours", $black);
$font_width = ImageFontWidth(5);
ImagePng($im);
?>
我想更改PHP用于在图像中写入的字体。我该怎么做??我试过了,但不行。您可以使用imageloadfont() 语法:
int imageloadfont ( string $file )
例如:
// Create a new image instance
$im = imagecreatetruecolor(50, 20);
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
// Make the background white
imagefilledrectangle($im, 0, 0, 49, 19, $white);
// Load the gd font and write 'Hello'
$font = imageloadfont('./04b.gdf');
imagestring($im, $font, 0, 0, 'Hello', $black);
// Output to browser
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
因此将代码更改为:
//Other part of code
Header("Content-type: image/png");
$im = imagecreatefromPng("./images/signatures/background.png");
$font = imageloadfont('./fonts/arial.gdf');//change the parameter based on your font file name
$red = ImageColorAllocate($im, 255, 0, 0);
$black = ImageColorAllocate($im, 0, 0, 0);
ImageString($im, $font, 15, 5, "$callsign", $black);
ImageString($im, $font, 15, 20, "$name $surname", $black);
ImageString($im, $font, 15, 35, "Location: $location", $black);
ImageString($im, $font, 15, 50, "HUB: $hub", $black);
ImageString($im, $font, 15, 65, "Hours: $hours", $black);
$font_width = ImageFontWidth(5);
ImagePng($im);
您可以使用imageloadfont() 语法:
int imageloadfont ( string $file )
例如:
// Create a new image instance
$im = imagecreatetruecolor(50, 20);
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
// Make the background white
imagefilledrectangle($im, 0, 0, 49, 19, $white);
// Load the gd font and write 'Hello'
$font = imageloadfont('./04b.gdf');
imagestring($im, $font, 0, 0, 'Hello', $black);
// Output to browser
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
因此将代码更改为:
//Other part of code
Header("Content-type: image/png");
$im = imagecreatefromPng("./images/signatures/background.png");
$font = imageloadfont('./fonts/arial.gdf');//change the parameter based on your font file name
$red = ImageColorAllocate($im, 255, 0, 0);
$black = ImageColorAllocate($im, 0, 0, 0);
ImageString($im, $font, 15, 5, "$callsign", $black);
ImageString($im, $font, 15, 20, "$name $surname", $black);
ImageString($im, $font, 15, 35, "Location: $location", $black);
ImageString($im, $font, 15, 50, "HUB: $hub", $black);
ImageString($im, $font, 15, 65, "Hours: $hours", $black);
$font_width = ImageFontWidth(5);
ImagePng($im);
假设您指的是字体:
如果您使用ttf字体,这可能会有所帮助,假设您的意思是字体:
如果您使用ttf字体,这可能会有所帮助您的意思是要更改字体?我要更改字母类型?字体?你能说得更具体些吗?你说的改变类型是什么意思?更改字体?类型意味着什么,字体还是其他什么?我想更改字体类型!!像Arial!你是说你想改变字体?我想改变字母的类型?字体?你能说得更具体些吗?你说的改变类型是什么意思?更改字体?类型意味着什么,字体还是其他什么?我想更改字体类型!!像Arial!好的,但如何将其应用到我的代码中??我的字体在./fonts/arial.ttf或./fonts/arial.gdf中。我现在还有其他问题。字体大小真的很大,我需要把imageloadfont(string$文件)放在哪里好,但如何将其应用到我的代码中??我的字体在./fonts/arial.ttf或./fonts/arial.gdf中。我现在还有其他问题。字体大小非常大,我需要把imageloadfont(string$文件)放在哪里