【问题标题】:Display PHP as an Image将 PHP 显示为图像
【发布时间】:2018-02-08 22:27:34
【问题描述】:

基本上,它的作用是为我的墙上的固定帖子制作一张图片,上面写着“这面墙已被查看(次数)次。”。这曾经在我的 freewha.com 免费网站上为我工作,但现在我已经切换到运行 apache(ubuntu)的 DigitalOcean 的 VPS,它不起作用。它说页面无法处理请求。我能够发现这是 $text 之后的底部错误,但是我找不到发生这种情况的原因。

<?php

if(!defined('MyConst')) {
   die('Direct access not permitted');
}

$viewsOld = file_get_contents("path/views.conf");

$views = $viewsOld + 1;

file_put_contents("path/views.conf", $views);

if ($views < 10) {
$width = 305;
}
elseif ($views < 100) {
$width = 314;
}
elseif ($views < 1000) {
$width = 323;
}
elseif ($views < 10000) {
$width = 332;
}
elseif ($views < 100000) {
$width = 341;
}
elseif ($views < 1000000) {
$width = 350;
}
elseif ($views < 10000000) {
$width = 359;
}
elseif ($views < 100000000) {
$width = 368;
}
elseif ($views < 1000000000) {
$width = 377;
}
else {
}

$text = "This wall has been viewed $views times.";

$my_img = imagecreate( $width, 18 ); //width & height
$background  = imagecolorallocate( $my_img, 20,   20,   20 );
$text_colour = imagecolorallocate( $my_img, 0, 255, 0 );
imagestring( $my_img, 10, 0, 0, $text, $text_colour );
imagesetthickness ( $my_img, 5 );

header( "Content-type: image/png" );
imagepng( $my_img );
imagecolordeallocate( $text_color );
imagecolordeallocate( $background );
imagedestroy( $my_img );
?>

我已经安装了 php 和 php-common,但是它仍然这样做。关于为什么会发生这种情况的任何解释?

【问题讨论】:

标签: php apache ubuntu


【解决方案1】:

此脚本依赖于 GD PHP 扩展。如果它不起作用,您可能需要安装扩展程序——在 Ubuntu 上,这将是 php-gd(如果您运行的是旧版本,则可能是 php5-gd)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-23
    • 1970-01-01
    • 1970-01-01
    • 2018-04-19
    • 2017-11-29
    • 2016-01-13
    • 1970-01-01
    相关资源
    最近更新 更多