请问,怎么使用gd操作直接生成图片文件?

时间:2022-02-11 12:27:51
比如这样的代码(file1.php):

<?php
$img = imagecreatetruecolor(300,200);
$color = imageColorAllocate($img, 200,0,0);
//输出英文字:
ImageString($img, 5, 100, 50, "abc123@#¥a", $color);
//header("content-type: image/png");  
imagePng( $img );
imagedestroy($img);
?>

我只能在另一个文件中,通过这样的html代码  <img  src='./file1.php' />  来显示该图片。

我想实现的效果是,在一个php文件(网页)中,刷新一下,就在该网页的本身目录(文件夹)下,生成一张图片文件。网页界面上能不能看到无所谓。图片文件名可以采用某种不重复的随机字符来表示,图片上的文字内容当然也可以随机。这都不是重点。重点就是,刷新一下网页,就得到一个图片文件。

2 个解决方案

#1


imagePng( $img, "图片文件名" );

#2


在imagepng(image,路径加上名字)

#1


imagePng( $img, "图片文件名" );

#2


在imagepng(image,路径加上名字)