tent-type: image/png");
$newImg = ImageCreate(250,250);
$skyblue = ImageColorAllocate($newImg,136,193,255);
ImageFill($newImg,0,0,$skyblue);
ImagePNG($newImg);
ImageDestroy($newImg);
?>
如果你调用这个脚本skyblue.php 并用自己的浏览器访问它,你就会看到一个250-X-250像素大的蓝色PNG图像。
你还可以用图像创建函数处理图像,比如创建大型图像的缩微图等。
假设你打算为某个图片制作一个35-X-35像素大小的缩微图。你要做到就是创建一个新的35 X 35 像素大小的图像;制造出一个包含其原始图像内容的图像流;然后改变原始图像的大小,并把它放到新的空白图像中去。
用来达到以上目的的关键函数就是ImageCopyResized(),,该函数的格式如下所示:ImageCopyResized([new image handle],[original image handle],[new image X], [new Image Y], [original image X], [original image Y], [new image X], [new image Y], [original image X], [original image Y]);
以下是代码注释。
<? /* send a header so that the browser knows the content-type of the file */
header("Content-type: image/png");
/* set up variables to hold the height and width of your new image */
$newWidth = 35;
$newHeight = 35;
/* create a blank, new image of the given new height and width */
$newImg = ImageCreate($newWidth,$newHeight);
/* get the data from the original, large image */
$origImg = ImageCreateFromPNG("test.png");
/* copy the resized image. Use the ImageSX() and ImageSY functions to get the x and y sizes of the orginal image. */
ImageCopyResized($newImg,$origImg,0,0,0,0,$newWidth,$newHeight,ImageSX($origImg),ImageSY($origImg));
/* create final image and free up the memory */
ImagePNG($newImg);
ImageDestroy($newImg); ?>
如果你调用了以上脚本resized.php 并用自己的浏览器访问它,你应该能看到一个35-X-35像素大小的缩微PNG图。
$newImg = ImageCreate(250,250);
$skyblue = ImageColorAllocate($newImg,136,193,255);
ImageFill($newImg,0,0,$skyblue);
ImagePNG($newImg);
ImageDestroy($newImg);
?>
如果你调用这个脚本skyblue.php 并用自己的浏览器访问它,你就会看到一个250-X-250像素大的蓝色PNG图像。
你还可以用图像创建函数处理图像,比如创建大型图像的缩微图等。
假设你打算为某个图片制作一个35-X-35像素大小的缩微图。你要做到就是创建一个新的35 X 35 像素大小的图像;制造出一个包含其原始图像内容的图像流;然后改变原始图像的大小,并把它放到新的空白图像中去。
用来达到以上目的的关键函数就是ImageCopyResized(),,该函数的格式如下所示:ImageCopyResized([new image handle],[original image handle],[new image X], [new Image Y], [original image X], [original image Y], [new image X], [new image Y], [original image X], [original image Y]);
以下是代码注释。
<? /* send a header so that the browser knows the content-type of the file */
header("Content-type: image/png");
/* set up variables to hold the height and width of your new image */
$newWidth = 35;
$newHeight = 35;
/* create a blank, new image of the given new height and width */
$newImg = ImageCreate($newWidth,$newHeight);
/* get the data from the original, large image */
$origImg = ImageCreateFromPNG("test.png");
/* copy the resized image. Use the ImageSX() and ImageSY functions to get the x and y sizes of the orginal image. */
ImageCopyResized($newImg,$origImg,0,0,0,0,$newWidth,$newHeight,ImageSX($origImg),ImageSY($origImg));
/* create final image and free up the memory */
ImagePNG($newImg);
ImageDestroy($newImg); ?>
如果你调用了以上脚本resized.php 并用自己的浏览器访问它,你应该能看到一个35-X-35像素大小的缩微PNG图。
| 对此文章发表了评论 |
