尝试在php中透明图像

尝试在php中透明图像,php,Php,我又来了。我需要rlly帮助,我需要一个img php 但是我不能得到它。我是PHP的新手,我想学习。我在PHP.net上阅读,只发现了一些问题 代码如下: <?php header('Content-type: image/jpeg'); $im = file_get_contents("http://fthw.cf/count/index.php?dt=2016-02-13/10:00:00"); $black = imagecolorallocate($im, 0, 0, 0);

我又来了。我需要rlly帮助,我需要一个img php 但是我不能得到它。我是PHP的新手,我想学习。我在PHP.net上阅读,只发现了一些问题

代码如下:

 <?php
header('Content-type: image/jpeg');
$im = file_get_contents("http://fthw.cf/count/index.php?dt=2016-02-13/10:00:00");
$black = imagecolorallocate($im, 0, 0, 0);
imagecolortransparent($im, $black);
imagepng($im, '$img');
imagedestroy($im);
?>
你好! PS:请帮帮我


<?php
function copyTransparent($src, $output)
{
    $dimensions = getimagesize($src);
    $x = $dimensions[0];
    $y = $dimensions[1];
    $im = imagecreatetruecolor($x,$y); 
    $src_ = imagecreatefrompng($src); 
    // Prepare alpha channel for transparent background
    $alpha_channel = imagecolorallocatealpha($im, 0, 0, 0, 127); 
    imagecolortransparent($im, $alpha_channel); 
    // Fill image
    imagefill($im, 0, 0, $alpha_channel); 
    // Copy from other
    imagecopy($im,$src_, 0, 0, 0, 0, $x, $y); 
    // Save transparency
    imagesavealpha($im,true); 
    // Save PNG
    imagepng($im,$output,9); 
    imagedestroy($im); 
}
$png = 'file.png';

copyTransparent($png,"png.png");
?>

下面是一个可以用来使图像透明的函数

$im是一个字符串,如错误所示
<?php
function copyTransparent($src, $output)
{
    $dimensions = getimagesize($src);
    $x = $dimensions[0];
    $y = $dimensions[1];
    $im = imagecreatetruecolor($x,$y); 
    $src_ = imagecreatefrompng($src); 
    // Prepare alpha channel for transparent background
    $alpha_channel = imagecolorallocatealpha($im, 0, 0, 0, 127); 
    imagecolortransparent($im, $alpha_channel); 
    // Fill image
    imagefill($im, 0, 0, $alpha_channel); 
    // Copy from other
    imagecopy($im,$src_, 0, 0, 0, 0, $x, $y); 
    // Save transparency
    imagesavealpha($im,true); 
    // Save PNG
    imagepng($im,$output,9); 
    imagedestroy($im); 
}
$png = 'file.png';

copyTransparent($png,"png.png");
?>