尝试透明图像 php


Trying to transparent an image 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);
imagecolortransparent($im, $black);
imagepng($im, '$img');
imagedestroy($im);
?>

错误日志:

    [11-Feb-2016 22:00:17 America/New_York] PHP Warning:  imagecolorallocate() expects parameter 1 to be resource, string given in /home/iedgmnuq/public_html/fthw.cf/event/index.php on line 4
[11-Feb-2016 22:00:17 America/New_York] PHP Warning:  imagecolortransparent() expects parameter 1 to be resource, string given in /home/iedgmnuq/public_html/fthw.cf/event/index.php on line 5
[11-Feb-2016 22:00:17 America/New_York] PHP Warning:  imagepng() expects parameter 1 to be resource, string given in /home/iedgmnuq/public_html/fthw.cf/event/index.php on line 6
[11-Feb-2016 22:00:17 America/New_York] PHP Warning:  imagedestroy() expects parameter 1 to be resource, string given in /home/iedgmnuq/public_html/fthw.cf/event/index.php on line 7

问候!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");
?>

这是一个可用于使图像透明的函数