PHP動(dòng)態(tài)生成指定大小隨機(jī)圖片的方法
本文實(shí)例講述了PHP動(dòng)態(tài)生成指定大小隨機(jī)圖片的方法。分享給大家供大家參考,具體如下:
<?php
$image_width = 100;
$image_height = 100;
$image_str = '';
if (isset($_GET['w']))
{
$image_width = intval($_GET['w']);
}
if (isset($_GET['h']))
{
$image_height = intval($_GET['h']);
}
if (isset($_GET['s']))
{
$image_str = $_GET['s'];
}
$img = imagecreate($image_width, $image_height);
$color = imagecolorallocate($img, mt_rand(157,255), mt_rand(157,255), mt_rand(157,255));
imagefilledrectangle($img, 0, $image_height, $image_width, 0, $color);
$step = mt_rand(15, 30);
$start = mt_rand(0, $step);
$color = imagecolorallocate($img, mt_rand(200,255), mt_rand(200,255), mt_rand(200,255));
imagesetthickness($img, mt_rand(3, 10));
if ($image_height > $image_width)
{
for ($i=$start; $i<$image_height * 2; $i+=$step)
{
imageline($img, 0, $i, $i, 0, $color);
}
}
else
{
for ($i=$start; $i<$image_width * 2; $i+=$step)
{
imageline($img, $i, 0, 0, $i, $color);
}
}
if ($image_str != '')
{
$black = imagecolorallocate($img, 0, 0, 0);
imagestring($img, 12, 5, 5, $image_str, $black);
}
header('Content-type:image/png');
imagepng($img);
imagedestroy($img);
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP圖形與圖片操作技巧匯總》、《php操作office文檔技巧總結(jié)(包括word,excel,access,ppt)》、《php日期與時(shí)間用法總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門(mén)教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫(kù)操作入門(mén)教程》及《php常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總》
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。
- php生成圖片驗(yàn)證碼-附五種驗(yàn)證碼
- 使用PHP生成圖片的縮略圖的方法
- php生成圖片驗(yàn)證碼的實(shí)例講解
- php使用Imagick生成圖片的方法
- php實(shí)現(xiàn)QQ空間獲取當(dāng)前用戶的用戶名并生成圖片
- 用PHP代碼在網(wǎng)頁(yè)上生成圖片
- PHP批量生成圖片縮略圖的方法
- php生成圖片驗(yàn)證碼
- php生成圖片縮略圖的方法
- 基于GD2圖形庫(kù)的PHP生成圖片縮略圖類代碼分享
- phplot生成圖片類用法詳解
- PHP生成圖片驗(yàn)證碼、點(diǎn)擊切換實(shí)例
- php將數(shù)據(jù)庫(kù)中的電話號(hào)碼讀取出來(lái)并生成圖片
相關(guān)文章
php使用socket post數(shù)據(jù)到其它web服務(wù)器的方法
這篇文章主要介紹了php使用socket post數(shù)據(jù)到其它web服務(wù)器的方法,涉及php使用socket傳輸數(shù)據(jù)的相關(guān)技巧,需要的朋友可以參考下2015-06-06
php通過(guò)exif_read_data函數(shù)獲取圖片的exif信息
這篇文章主要介紹了php通過(guò)exif_read_data函數(shù)獲取圖片的exif信息,默認(rèn)情況下,PHP讀取圖片Exif信息模塊是不開(kāi)啟的,我們需要先開(kāi)啟這個(gè)模塊。開(kāi)啟Exif模塊需要mbstring支持,這里就不詳細(xì)說(shuō)明了,我們來(lái)先看下函數(shù)的用法2015-05-05
探討PHP中OO之靜態(tài)關(guān)鍵字以及類常量的詳解
本篇文章是對(duì)php中的靜態(tài)關(guān)鍵字以及類常量進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06
php導(dǎo)入excel文件到mysql數(shù)據(jù)庫(kù)的方法
這篇文章主要介紹了php導(dǎo)入excel文件到mysql數(shù)據(jù)庫(kù)的方法,分析了phpexcel類操作excel文件的技巧及導(dǎo)入數(shù)據(jù)庫(kù)的方法,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-01-01
PHP英文字母大小寫(xiě)轉(zhuǎn)換函數(shù)小結(jié)
這篇文章主要介紹了幾個(gè)PHP英文字母大小寫(xiě)轉(zhuǎn)換函數(shù),分為首字母大小寫(xiě)轉(zhuǎn)換和所有字母大小寫(xiě)轉(zhuǎn)換,需要的朋友可以參考下2014-05-05
php5.5新數(shù)組函數(shù)array_column使用
array_column 用于獲取二維數(shù)組中的元素(PHP 5 >= 5.5.0),但我們有時(shí)候需要在低版本中使用,那么就可以使用下面的代碼即可2013-07-07

