[英]GD library, text on image not working and errors
我试图在图像上输出文本,并且页面设置为空白,在设置错误报告时出现以下错误。 知道为什么要这样做以及如何解决吗?
PHP message: PHP Warning: imagecolorallocate() expects parameter 1 to be resource, boolean given in /var/www/gd-text/index.php on line 13
PHP message: PHP Warning: imagettftext() expects parameter 1 to be resource, boolean given in /var/www/gd-text/index.php on line 22
PHP message: PHP Warning: imagejpeg() expects parameter 1 to be resource, boolean given in /var/www/gd-text/index.php on line 25
PHP message: PHP Warning: imagedestroy() expects parameter 1 to be resource, boolean given in /var/www/gd-text/index.php on line 28" while reading response header from upstream, client: 203.176.102.98, server: myserver.com, request: "GET /gd-text/index.php HTTP/1.1", upstream: "fastcgi://unix:/dev/shm/php-fpm-www.sock:", host: "myserver.com"
我的PHP:
<?php
//error_reporting(E_ALL);
//ini_set("display_errors", 1);
//Set the Content Type
header('Content-type: image/jpeg');
// Create Image From Existing File
$jpg_image = imagecreatefromjpeg('image.jpg');
// Allocate A Color For The Text
$black = imagecolorallocate($jpg_image, 0, 0, 0);
// Set Path to Font File
$font_path = 'myfont.ttf';
// Set Text to Be Printed On Image
$text = "Text on image test";
// Print Text On Image
imagettftext($jpg_image, 25, 0, 75, 300, $black, $font_path, $text);
// Send Image to Browser
imagejpeg($jpg_image);
// Clear Memory
imagedestroy($jpg_image);
?>
..我以为图像的给定路径不起作用,因为imagecreatefrom ...如果无法创建图像,则返回布尔值FALSE。
无论如何,在将它们移交给您的过程之前先检查一下是很省力的,这样您就可以与exceptionion进行交互/简化调试工作...
看看你从代码中得到了什么
<? ... var_dump(is_file($jpg)); ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.