PHP动态生成指定大小随机图片的方法


Posted in PHP onMarch 25, 2016

本文实例讲述了PHP动态生成指定大小随机图片的方法。分享给大家供大家参考,具体如下:

<?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);

希望本文所述对大家PHP程序设计有所帮助。

PHP 相关文章推荐
PHP 和 MySQL 基础教程(四)
Oct 09 PHP
PHP 柱状图实现代码
Dec 04 PHP
php处理斐波那契数列非递归方法
Feb 04 PHP
安装apache2.2.22配置php5.4(具体操作步骤)
Jun 26 PHP
PHP5.5在windows安装使用memcached服务端的方法
Apr 16 PHP
PHP中实现获取IP和地理位置类分享
Feb 10 PHP
php实现简单的语法高亮函数实例分析
Apr 27 PHP
详解 PHP加密解密字符串函数附源码下载
Dec 18 PHP
深入剖析浏览器退出之后php还会继续执行么
May 17 PHP
Laravel如何友好的修改.env配置文件详解
Jun 07 PHP
php脚本守护进程原理与实现方法详解
Jul 20 PHP
PHP实现的折半查找算法示例
Dec 19 PHP
PHP5.2中PDO的简单使用方法
Mar 25 #PHP
PHP简单判断字符串是否包含另一个字符串的方法
Mar 25 #PHP
PHP错误机制知识汇总
Mar 24 #PHP
ThinkPHP的常用配置选项汇总
Mar 24 #PHP
ThinkPHP静态缓存简单配置和使用方法详解
Mar 23 #PHP
thinkPHP实现MemCache分布式缓存功能
Mar 23 #PHP
ThinkPHP项目分组配置方法分析
Mar 23 #PHP
You might like
Zend的AutoLoad机制介绍
2012/09/27 PHP
php过滤敏感词的示例
2014/03/31 PHP
thinkPHP5框架中widget的功能与用法详解
2018/06/11 PHP
javascript中的继承实例代码
2011/04/27 Javascript
JQuery扩展插件Validate 1 基本使用方法并打包下载
2011/09/05 Javascript
浅谈bootstrap源码分析之tab(选项卡)
2016/06/06 Javascript
使用do...while的方法输入一个月中所有的周日(实例代码)
2016/07/22 Javascript
用AngularJS来实现监察表单按钮的禁用效果
2016/11/02 Javascript
让微信小程序支持ES6中Promise特性的方法详解
2017/06/13 Javascript
微信小程序实现页面跳转传值以及获取值的方法分析
2017/12/18 Javascript
vue-router history模式下的微信分享小结
2018/07/05 Javascript
微信小程序实现动态显示和隐藏某个控件功能示例
2018/12/14 Javascript
JS使用队列对数组排列,基数排序算法示例
2019/03/02 Javascript
vue2.x数组劫持原理的实现
2020/04/19 Javascript
Vue.js获取手机系统型号、版本、浏览器类型的示例代码
2020/05/10 Javascript
jQuery冲突问题解决方法
2021/01/19 jQuery
[30:51]DOTA2上海特级锦标赛主赛事日 - 3 胜者组第二轮#1Liquid VS MVP.Phx第一局
2016/03/04 DOTA
使用Python的web.py框架实现类似Django的ORM查询的教程
2015/05/02 Python
Python文件与文件夹常见基本操作总结
2016/09/19 Python
Python 读取指定文件夹下的所有图像方法
2018/04/27 Python
浅析Python数据处理
2018/05/02 Python
python实现对任意大小图片均匀切割的示例
2018/12/05 Python
基于Python的图像数据增强Data Augmentation解析
2019/08/13 Python
pyinstaller打包单文件时--uac-admin选项不起作用怎么办
2020/04/15 Python
Python错误的处理方法
2020/06/23 Python
pycharm + django跨域无提示的解决方法
2020/12/06 Python
python 模块导入问题汇总
2021/02/01 Python
Android本地应用打开方法——通过html5写连接
2016/03/11 HTML / CSS
EM Cosmetics官网:由彩妆大神Michelle Phan创办的独立品牌
2020/04/27 全球购物
租房合同协议书
2014/04/09 职场文书
中秋寄语大全
2014/04/11 职场文书
中学生操行评语大全
2014/04/24 职场文书
2016暑期政治学习心得体会
2016/01/23 职场文书
2016中秋节月饼促销广告语
2016/01/28 职场文书
GO语言异常处理分析 err接口及defer延迟
2022/04/14 Golang
Golang 入门 之url 包
2022/05/04 Golang