FDS’s Blog

2009年1月21日

利用PHP生成图像

Filed under: PHP — FDS @ 13:58

 生成图像,PHP可以操作处理图像。如果你已经安装了GD库,你甚至可以利用PHP生成图像。
<?
Header(“Content-type: image/gif”);
$string=implode($argv,” “);
$im = imagecreatefromgif(“images/button1.gif”);
$orange = ImageColorAllocate($im, 220, 210, 60);
$px = (imagesx($im)-7.5*strlen($string))/2;
ImageString($im,3,$px,9,$string,$orange);
ImageGif($im);
ImageDestroy($im);
?>

(译者注:以上代码段缺少注释,请读者参考PHP Manual的图像处理函数部分)

  这段代码在其他页面中通过以下标记<img src=http://www.okzz.cn/button.php3?text”>调用,然后以上的那段button.php3代码取得text值并在另外取得的图像文件中加上该值–在以上的代码中该图像文件是images/button1.gif–最后输出到浏览器。假如你想在表单域中使用图像按钮,但是又不希望在每次按钮上的文字改变后不得不重新生成新的图像,就可以利用这样简单的方法动态生成图像文件。

1 条评论 »

  1. 学习了

    评论 by 华晨 — 2009年8月23日 @ 12:40

这篇文章上的评论的 RSS feed TrackBack URL

留下评论

Powered by WordPress