PHP動態(tài)生成指定大小隨機圖片的方法
本文實例講述了PHP動態(tài)生成指定大小隨機圖片的方法。分享給大家供大家參考,具體如下:
<?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è)計入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家PHP程序設(shè)計有所幫助。
相關(guān)文章
解析PHP函數(shù)array_flip()在重復(fù)數(shù)組元素刪除中的作用
本篇文章是對PHP函數(shù)array_flip()在重復(fù)數(shù)組元素刪除中的作用進行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06
原生JS實現(xiàn)Ajax通過POST方式與PHP進行交互的方法示例
這篇文章主要介紹了原生JS實現(xiàn)Ajax通過POST方式與PHP進行交互的方法,涉及ajax使用post方式與后臺交互及php數(shù)據(jù)接收、處理、查詢數(shù)據(jù)庫等相關(guān)操作技巧,需要的朋友可以參考下2018-05-05

