Nis*_*dke 16 php truetype imagettftext
<?php
session_start();
require_once 'facebook.php';
$app_id = "418907881455014";
$app_secret = "36389d2c4caaf6de86982cb87686a494";
$redirect_uri = 'http://gooogle12.comuf.com';
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$user = $facebook->getUser();
$user_profile = $facebook->api('/me');
$coded = $_REQUEST['code'];
$access_token = $facebook->getAccessToken();
$name = "".$user_profile['name']."";
$fbid = "".$user_profile['id']."";
function RandomLine($filename) {
$lines = file($filename) ;
return $lines[array_rand($lines)] ;
}
$reason = RandomLine("reason.txt");
$canvas = imagecreatefromjpeg ("bg.jpg"); // background image file
$black = imagecolorallocate( $canvas, 0, 0, 0 ); // The second colour - to be used for the text
$font = "Arial.ttf"; // Path to the font you are going to use
$fontsize = 20; // font size
$birthday = "".$user_profile['birthday']."";
$death = "- ".date('d/m/Y', strtotime( '+'.rand(0, 10000).' days'))."";
imagettftext( $canvas, 22, -1, 110, 120, $black, $font, $name ); // name
imagettftext( $canvas, 22, -1, 110, 170, $black, $font, $birthday ); // birthday
imagettftext( $canvas, 22, -1, 255, 172, $black, $font, $death ); // death
imagettftext( $canvas, 20, -1, 110, 220, $black, $font, $reason ); // reason
$facebook->setFileUploadSupport(true);
//Create an album
$album_details = array(
'message'=> 'How will you die?',
'name'=> 'How will you die?'
);
$create_album = $facebook->api('/me/albums', 'post', $album_details);
//Get album ID of the album you've just created
$album_uid = $create_album['id'];
//Upload a photo to album of ID...
$file='img/'.$fbid.'.jpg'; //Example image file
$photo_details = array( 'message'=> 'Find...51', 'image' => '@'.realpath($file));
$upload_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);
enter code here
ImageDestroy( $canvas );
header("Location: http://facebook.com".$fbid."&photoid=".$upphoto."")
?>
Run Code Online (Sandbox Code Playgroud)
好吧,我正在使用这个PHP代码制作一个facebook应用程序Arial.ttf.我将字体上传到我的网站的根目录.但我仍然显示错误 - Warning: imagettftext() [function.imagettftext]: Could not find/open font in /home/a2424901/public_html/index.php on line 35.我尝试改变案例,但我没有为我工作.我在这段代码中出错的地方?
Mic*_*ski 34
根据PHP使用的GD库版本,当fontfile不以前导/开头时,然后.ttf将附加到文件名,库将尝试沿库定义的字体路径搜索该文件名.
这似乎意味着fontfile应该是一个绝对路径,如果不是,该函数会将另一个附加.ttf到它的末尾.
指定字体文件的完整路径.
$font = "/home/a2424901/public_html/Arial.ttf";
Run Code Online (Sandbox Code Playgroud)
或者省略.ttf并使用GDFONTPATH. 文档建议如下:
在许多情况下,字体与使用它的脚本位于同一目录中,以下技巧将缓解任何包含问题.
putenv('GDFONTPATH=' . realpath('.'));
$font = "Arial";
Run Code Online (Sandbox Code Playgroud)
添加到user2724960的答案; 更改FontName __DIR__ . '/graph/fonts/someFont.ttf'为我做了.
全线:
$myPicture->setFontProperties(array("FontName"=>__DIR__ . '/graph/fonts/someFont.ttf',"FontSize"=>14));
Run Code Online (Sandbox Code Playgroud)
不要忘记将" someFont " 替换为您的字体文件名称(默认值:"Forgotte")
我也在使用 XAMPP,显然 XAMPP 只支持字体的完整目录路径。此代码可以在 Windows (XAMPP) 和我们的提供商 Linux 服务器上运行:
$dir= dirname(realpath(__FILE__));
$sep=DIRECTORY_SEPARATOR;
$font =$dir.$sep.'arial.ttf';
imagettftext($thumb, $size, 0, $y_pos, $size, $textcolor, $font, $txt);
Run Code Online (Sandbox Code Playgroud)
(假设你的字体文件与你的php文件在同一目录中)
小智 5
我的解决方案(对我有用):
realpath('here/is/right/path/to/font.ttf');
Run Code Online (Sandbox Code Playgroud)