【问题标题】:Outputting an image not working properly输出图像无法正常工作
【发布时间】:2015-09-24 17:51:52
【问题描述】:

我正在尝试使用PHP 输出图像,但是当我这样做时,它看起来不像原始图像。原始图像具有透明背景,输出图像具有一些奇怪的背景,“杀死”了图像。

这是我的代码:

<?php
$image = imagecreatefrompng('./logo2.png');
$imagesize = getimagesize('./logo2.png');
header('Content-type: ' . $imagesize['mime']);
imagepng($image);
imagedestroy($image);

如果您需要其他任何东西来确定问题,请告诉我。

【问题讨论】:

    标签: php image


    【解决方案1】:

    添加 alpha 混合:

    <?php
    $image = imagecreatefrompng('./logo2.png');
    $imagesize = getimagesize('./logo2.png');
    header('Content-type: ' . $imagesize['mime']);
    
    imagealphablending($image, true);
    imagesavealpha( $image, true );
    
    imagepng($image);
    imagedestroy($image);
    

    例如here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-11
      • 1970-01-01
      • 2013-04-17
      • 2015-07-25
      • 2019-01-11
      • 2012-07-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多