在PHP上使用GD不起作用-只有黑色方块
我试图在我的服务器(Debian 4.9.88-1+deb9u1)上用在PHP上使用GD不起作用-只有黑色方块,php,gd,php-7.2,Php,Gd,Php 7.2,我试图在我的服务器(Debian 4.9.88-1+deb9u1)上用PHP7.2.5上的GD绘制一个简单的图像 我的源代码看起来很简单: <?php error_reporting(E_ALL); header("Content-type: image/png"); $string = $_GET['text']; $im = imagecreatefromjpeg("test.jpg"); $orange = imagecolorall
PHP7.2.5
上的GD
绘制一个简单的图像
我的源代码看起来很简单:
<?php
error_reporting(E_ALL);
header("Content-type: image/png");
$string = $_GET['text'];
$im = imagecreatefromjpeg("test.jpg");
$orange = imagecolorallocate($im, 220, 210, 60);
$px = (imagesx($im) - 7.5 * strlen($string)) / 2;
imagestring($im, 3, $px, 9, $string, $orange);
imagepng($im);
imagedestroy($im);
?>
test.jpg位于同一文件夹中。
PHP版本:7.2.5我在日志文件中看不到任何相关内容 GD在服务器上被激活: 结果如下:
<?php
error_reporting(E_ALL);
header("Content-type: image/png");
$string = $_GET['text'];
$im = imagecreatefromjpeg("test.jpg");
$orange = imagecolorallocate($im, 220, 210, 60);
$px = (imagesx($im) - 7.5 * strlen($string)) / 2;
imagestring($im, 3, $px, 9, $string, $orange);
imagepng($im);
imagedestroy($im);
?>
按照以下答案解决问题:
问题是,我的.php文件不是ANSI格式的,而是UTF-8格式的,在将其转换为ANSI格式后,它就工作了。您的代码在PHP7.1.18上适用于我。用另一个JPG文件试试。@timclutton我现在用一张类似的图片试了一下,没有成功。这可能是一个与权利相关的问题吗?或者它必须是“JPEG”而不是“JPG”?这是我的第一个猜测。尝试一个简单的单行脚本,如:
var\u dump(file\u get\u contents('test.jpg')
并确认脚本从文件中读取数据。对于myimage.jpg
它显示bool(false)
,但对于另一个jpg,显示内容。但当我把777设定为正确的时候,没有任何变化。不管怎样。。。image.jpg
的输出如下所示: