前一篇,我们讲了一些GD库的创建相关函数,这篇讲一下图像转换相关的函数。图像转换函数主要有以下几个:
png2wbmp
png图片转换wbmp格式
jpeg2wbmp
jpg图片转换wbmp格式
image2wbmp
图像转换wbmp格式
下面具体说一下
png2wbmp
将 PNG 图像文件转换为 WBMP 图像文件
int png2wbmp ( string pngname, string wbmpname, int d_height, int d_width, int threshold )
将名为 pngname 的 PNG 文件转换为 WBMP 格式,并存为 wbmpname。用 d_height 和 d_width 指定目标图像的高度和宽度。
jpeg2wbmp
将 JPEG 图像文件转换为 WBMP 图像文件
int jpeg2wbmp ( string jpegname, string wbmpname, int d_height, int d_width, int threshold )
将名为 jpegname 的 JPEG 文件转换为 WBMP 格式,并存为 wbmpname。用 d_height 和 d_width 指定目标图像的高度和宽度。
上面两个函数都是直接将一个图片文件转换成另一个格式的 图片文件,下面这个稍微特别一点了。
image2wbmp
以 WBMP 格式将图像输出到浏览器或文件
int image2wbmp ( resource image [, string filename [, int threshold]] )
从 image 图像创建一个名为 filename 的 WBMP 文件。image 参数是某个图像创建函数的返回值,例如 imagecreatetruecolor()。
filename 参数是可选项,如果省略,则直接将原图像流输出。通过用 header() 发送 image/vnd.wap.wbmp 的 Content-type,可以创建直接输出 WBMP 图像的 PHP 脚本。
如:
<?php
$file = 'php.jpg';
$image = imagecreatefrompng($file);
header('Content-type: ' . image_type_to_mime(IMAGETYPE_WBMP));
image2wbmp($file); // output the stream directly
?>