PHP動態(tài)生成指定大小隨機(jī)圖片的方法
本文實(shí)例講述了PHP動態(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日期與時間用法總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家PHP程序設(shè)計(jì)有所幫助。
相關(guān)文章
php使用socket post數(shù)據(jù)到其它web服務(wù)器的方法
這篇文章主要介紹了php使用socket post數(shù)據(jù)到其它web服務(wù)器的方法,涉及php使用socket傳輸數(shù)據(jù)的相關(guān)技巧,需要的朋友可以參考下2015-06-06php通過exif_read_data函數(shù)獲取圖片的exif信息
這篇文章主要介紹了php通過exif_read_data函數(shù)獲取圖片的exif信息,默認(rèn)情況下,PHP讀取圖片Exif信息模塊是不開啟的,我們需要先開啟這個模塊。開啟Exif模塊需要mbstring支持,這里就不詳細(xì)說明了,我們來先看下函數(shù)的用法2015-05-05探討PHP中OO之靜態(tài)關(guān)鍵字以及類常量的詳解
本篇文章是對php中的靜態(tài)關(guān)鍵字以及類常量進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06php導(dǎo)入excel文件到mysql數(shù)據(jù)庫的方法
這篇文章主要介紹了php導(dǎo)入excel文件到mysql數(shù)據(jù)庫的方法,分析了phpexcel類操作excel文件的技巧及導(dǎo)入數(shù)據(jù)庫的方法,具有一定參考借鑒價值,需要的朋友可以參考下2015-01-01PHP英文字母大小寫轉(zhuǎn)換函數(shù)小結(jié)
這篇文章主要介紹了幾個PHP英文字母大小寫轉(zhuǎn)換函數(shù),分為首字母大小寫轉(zhuǎn)換和所有字母大小寫轉(zhuǎn)換,需要的朋友可以參考下2014-05-05php5.5新數(shù)組函數(shù)array_column使用
array_column 用于獲取二維數(shù)組中的元素(PHP 5 >= 5.5.0),但我們有時候需要在低版本中使用,那么就可以使用下面的代碼即可2013-07-07