发布于 2016-05-22 23:54:21 | 201 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的PHP教程,程序狗速度看过来!

PHP开源脚本语言

PHP(外文名: Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言。语法吸收了C语言、Java和Perl的特点,入门门槛较低,易于学习,使用广泛,主要适用于Web开发领域。PHP的文件后缀名为php。


这篇文章主要介绍了PHP动态生成指定大小随机图片的方法,涉及PHP根据传入参数动态生成图片的相关技巧,需要的朋友可以参考下

本文实例讲述了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);



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务