průhlednost u PNG

Ahoj všem používám svou funkci na předělání velikosti obrázku (viz níže), ale teď jsem zjistil, že když do ní pustím PNG obrázek, který je v originále průhledný (pozadí), tak po zmenšení se mi udělá černé pozadí. a průhlednost je pryč. Koukám do toho hodiny Google taky nic, už si nevím rady. Děkuji.
function obrazek($sirka, $vyska, $soubor, $kam, $id, $dopocitat = 'nic') {
//zjistime typ obrazku
$imgtype=getimagesize($soubor);
switch($imgtype[2]){
case 1:
$im=imagecreatefromgif($soubor);
$k = ".gif";
break;
case 2:
$im=imagecreatefromjpeg($soubor);
$k = ".jpg";
break;
case 3:
$im=imagecreatefrompng($soubor);
imagealphablending($im, true);
$k = ".png";
break;
}
$src_width=imagesx($im);
$src_height=imagesy($im);

//ulozi se v originalni velikosti
if($sirka == 0 and $vyska == 0) {
$height1=$src_height;
$width1=$src_width;
$thumb1=imagecreatetruecolor($width1,$height1);
imagealphablending($thumb1, true);
imagecopyresampled($thumb1,$im,0,0,0,0,$width1,$height1,$src_width, $src_height);
$tmp_cil1=$kam.$id.$k;
if (file_exists($tmp_cil1)) unlink($tmp_cil1);
switch($imgtype[2]){
case 1:
imagegif($thumb1,$tmp_cil1);
break;
case 2:
imagejpeg($thumb1,$tmp_cil1, 100);
break;
case 3:
imagesavealpha($thumb1, true);
imagepng($thumb1,$tmp_cil1);
break;
}
imagedestroy($thumb1);
}
else {
if($dopocitat == "sirku") {
$height2=$vyska;
$width2=$height2/$src_height*$src_width;
}
elseif($dopocitat == "vysku") {
$width2=$sirka;
$height2=$width2/$src_width*$src_height;
}
elseif($dopocitat == "nic") {
$width2=$sirka;
$height2=$vyska;
}
$thumb2=imagecreatetruecolor($width2,$height2);
imagealphablending($thumb2, true);
imagecopyresampled($thumb2,$im,0,0,0,0,$width2,$height2,$src_width, $src_height);
$tmp_cil2=$kam.$id.$k;
if (file_exists($tmp_cil2)) unlink($tmp_cil2);
switch($imgtype[2]){
case 1:
imagegif($thumb2,$tmp_cil2);
break;
case 2:
imagejpeg($thumb2,$tmp_cil2, 100);
break;
case 3:
imagesavealpha($thumb2, true);
imagepng($thumb2,$tmp_cil2);
break;
}
imagedestroy($thumb2);
}
}
Docela špatně se to tady čte.. takže jenom vložím kus kódu, u kterého (polo)průhlednost funguje. Je sice někdy z roku 2008, ale to snad vadit nebude.. :)

public function load($filename,$alpha,$x,$y)
{
if(!$img = @imagecreatefrompng($filename))
{
$img = imagecreatetruecolor($x,$y); //Blank image
imagestring($img,1,5,5,'Background loading failed.',imagecolorallocate($img,255,255,255));
}
elseif($alpha)
{
imagealphablending($img,true);
imagesavealpha($img,true);
}
return $img;
}

public function create($x,$y,$transparent)
{
$img = imagecreatetruecolor($x,$y);
if($transparent)
{
imagealphablending($img,true);
imagecolortransparent($img,imagecolorallocate($img,0,0,0));
imagesavealpha($img,true);
}else
{
imagealphablending($img,false);
imagesavealpha($img,true);
}
return $img;
}

public function copy($dest,$source,$dstx,$dsty,$srcx,$srcy,$dstw,$dsth,$srcw,$srch)
{
imagealphablending($source,false);
imagefill($source,0,0,imagecolortransparent($source,imagecolorallocatealpha($source,0,0,0,127)));
imagesavealpha($source,true);
imagecopyresampled($dest,$source,$dstx,$dsty,$srcx,$srcy,$dstw,$dsth,$srcw,$srch);
return true;
}

public function save($img)
{
$filename = $this->path.'example.png';
imagepng($img,$filename);
return true;
}

Přebrat si to ale budeš muset sám..