php怎么输出背景透明的图片?

是用image系列的函数直接画图:怎么输出一张全透明的图片?顺便问一下,如果对它使用了其他image函数,背景会变吗?... 是用image系列的函数直接画图:
怎么输出一张全透明的图片?
顺便问一下,如果对它使用了其他image函数,背景会变吗?
展开
 我来答
IT_小宋
推荐于2016-03-02 · TA获得超过125个赞
知道小有建树答主
回答量:342
采纳率:0%
帮助的人:79万
展开全部
php可以使用GD库或者ImageMagick工具生成png或者gif的背景透明图片.推荐使用ImageMagick.
这里有范例 http://php.net/manual/en/imagick.examples-1.php
准备一张png图片,放到php文件的目录,运行看看效果.
<?php
/* Read the image */
$im = new Imagick("test.png");
/* Thumbnail the image */
$im->thumbnailImage(200, null);

/* Create a border for the image */
$im->borderImage(new ImagickPixel("white"), 5, 5);

/* Clone the image and flip it */
$reflection = $im->clone();
$reflection->flipImage();

/* Create gradient. It will be overlayed on the reflection */
$gradient = new Imagick();

/* Gradient needs to be large enough for the image and the borders */
$gradient->newPseudoImage($reflection->getImageWidth() + 10, $reflection->getImageHeight() + 10, "gradient:transparent-black");

/* Composite the gradient on the reflection */
$reflection->compositeImage($gradient, imagick::COMPOSITE_OVER, 0, 0);

/* Add some opacity. Requires ImageMagick 6.2.9 or later */
$reflection->setImageOpacity( 0.3 );

/* Create an empty canvas */
$canvas = new Imagick();

/* Canvas needs to be large enough to hold the both images */
$width = $im->getImageWidth() + 40;
$height = ($im->getImageHeight() * 2) + 30;
$canvas->newImage($width, $height, new ImagickPixel("black"));
$canvas->setImageFormat("png");

/* Composite the original image and the reflection on the canvas */
$canvas->compositeImage($im, imagick::COMPOSITE_OVER, 20, 10);
$canvas->compositeImage($reflection, imagick::COMPOSITE_OVER, 20, $im->getImageHeight() + 10);

/* Output the image*/
header("Content-Type: image/png");
echo $canvas;
?>
钓侠
2016-01-07 · 知道合伙人互联网行家
钓侠
知道合伙人互联网行家
采纳数:90 获赞数:564
麦子学院讲师,WEB前端工程师,专注于WEB开发,精通Discuz、PHPCMS等开源程序!

向TA提问 私信TA
展开全部

php代码如下:

<?php
echo '<img src="images/test.png">';


案例中直接使用echo输出html源代码;

<img>标签是显示图片的

src 是图片的路径

images/表示图片所在的目录(当前表示,在当前网页文件同级目录中,的images文件夹中去找一张,名为test的格式为png的图片)

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式