簡體   English   中英

將PHP顯示為圖像

[英]Display PHP as an Image

基本上,此操作是在我的牆上制作一張固定的帖子的圖像,上面寫着“此牆已被瀏覽(次數)次”。 這曾經在我的免費網站freewha.com上對我有用,但是現在我已經切換到使用DigitalOcean運行apache(ubuntu)的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,但是仍然可以做到這一點。 為什么會發生這種情況的任何解釋?

該腳本取決於GD PHP擴展。 如果它不起作用,則可能需要安裝擴展程序-在Ubuntu上,它應該是php-gd (如果運行的是舊版本,則可能是php5-gd )。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM