我正在尝试在图像上写文字。它在本地系统上运行正常,但是当我将它上传到实时服务器时它无法正常工作。 我的代码是
$imgPath = base_url() . "public/images/mix/theatre.jpg";
$jpg_image = imagecreatefromjpeg($imgPath);
// Allocate A Color For The Text
$color = imagecolorallocate($jpg_image, 102, 20, 99);
// Set Path to Font File
$font_path = FCPATH . "public/fonts/Myriad Pro.TTF";
//echo $font_path = base_url()."/public/fonts/Myriad Pro.TTF";
// Set Text to Be Printed On Image
$text = "NOW SHOWING";
// Print Text On Image
$imagettf = imagettftext($jpg_image, 16, 0, 57, 140, $color, $font_path, $text);
$savedImage = imagejpeg($jpg_image, $saveToPath);
var_dump($savedImage);
它给了我从$imgPath
复制的相同图像,文字没有写在上面
答案 0 :(得分:0)
您确定您的字体在远程可用吗?你似乎也错过了斜线:
$font_path = FCPATH . "public/fonts/Myriad Pro.TTF";
^^^^
答案 1 :(得分:0)
您可以使用此代码
<?php
header('Content-type: image/png');
$im = imagecreatefromjpeg('includes/dir/something.jpg');
$black = imagecolorallocate($im, 0, 0, 0);
$text=strtolower("NOW SHOW");
$font = 'includes/dir/some.TTF';
imagettftext($im, 25, 0, 15, 33, $black, $font, $text);
imagepng($im);
imagedestroy($im);
?>
它为我工作