日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php 动态显示数字,php – 如何动态创建具有指定数字的图像?

發布時間:2024/9/15 php 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php 动态显示数字,php – 如何动态创建具有指定数字的图像? 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這是一個如何做到這一點的例子 – 使用

gd function調用來制作你的圖像,但是玩得很好并緩存圖像.這個示例通過確保如果瀏覽器已經具有所需圖像,則返回304 …

#here's where we'll store the cached images

$cachedir=$_SERVER['DOCUMENT_ROOT'].'/imgcache/'

#get the score and sanitize it

$score=$_GET['score'];

if (preg_match('/^[0-9]\.[0-9]{1,2}$/', $score)

{

#figure out filename of cached file

$file=$cachedir.'score'.$score.'gif';

#regenerate cached image

if (!file_exists($file))

{

#generate image - this is lifted straight from the php

#manual, you'll need to work out how to make your

#image, but this will get you started

#load a background image

$im = imagecreatefrompng("images/button1.png");

#allocate color for the text

$orange = imagecolorallocate($im, 220, 210, 60);

#attempt to centralise the text

$px = (imagesx($im) - 7.5 * strlen($score)) / 2;

imagestring($im, 3, $px, 9, $score, $orange);

#save to cache

imagegif($im, $file);

imagedestroy($im);

}

#return image to browser, but return a 304 if they already have it

$mtime=filemtime($file);

$headers = apache_request_headers();

if (isset($headers['If-Modified-Since']) &&

(strtotime($headers['If-Modified-Since']) >= $mtime))

{

// Client's cache IS current, so we just respond '304 Not Modified'.

header('Last-Modified: '.gmdate('D, d M Y H:i:s', $mtime).' GMT', true, 304);

exit;

}

header('Content-Type:image/gif');

header('Content-Length: '.filesize($file));

header('Last-Modified: '.gmdate('D, d M Y H:i:s', $mtime).' GMT');

readfile($file);

}

else

{

header("HTTP/1.0 401 Invalid score requested");

}

如果你將它放在image.php中,你將在圖像標記中使用如下

總結

以上是生活随笔為你收集整理的php 动态显示数字,php – 如何动态创建具有指定数字的图像?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。