Problem tłem przy zmniejszaniu obrazków

Witam serdecznie,

mam taki kod:

function createThumbnail($path, $imagename, $rozmiar) { /////// tworzymy miniaturkę

	$wynik = explode(".", $imagename);

	$type = $wynik[1];


	$site_max_thumbnails_size = $rozmiar; // max size

	if ($type== "jpg" || $type== "jpeg"){

	$img = imagecreatefromjpeg( "{$path}{$imagename}" );

	}

	if ($type== "png"){

	$img = imagecreatefrompng( "{$path}{$imagename}" );

	}

	if ($type== "gif"){

	$img = imagecreatefromgif( "{$path}{$imagename}" );

	}

	$width = imagesx( $img );

	$height = imagesy( $img );


	// calculate thumbnail size

	if ($height>=$width) {

		$smallerSize=$width;

		$croppingStartHeight=($height-$smallerSize)/2;

		$croppingStartWidth=0;

	}

	else {

		$smallerSize=$height;

		$croppingStartHeight=0;

		$croppingStartWidth=($width-$smallerSize)/2;	}

	$croppedImage=imagecreatetruecolor($smallerSize, $smallerSize); // create square image

	$resizedImage=imagecreatetruecolor($site_max_thumbnails_size, $site_max_thumbnails_size);

	imagecopy($croppedImage, $img, 0, 0, $croppingStartWidth, $croppingStartHeight, $smallerSize, $smallerSize); // build cropped, square image

	imagecopyresampled ($resizedImage, $croppedImage, 0, 0, 0, 0, $site_max_thumbnails_size, $site_max_thumbnails_size, $smallerSize, $smallerSize); // copy and resize old image into new image

	$pathToThumbs=$path."";

	if ($type== "jpg" || $type== "jpeg"){

	if (!imagejpeg($resizedImage, "{$pathToThumbs}mini_{$imagename}" )) // save thumbnail into a file

		$result='Nie można zapisać miniaturki w folderze docelowym!';

		ImageDestroy($croppedImage);  

	ImageDestroy($resizedImage);

	return $result;

	}

	if ($type== "png"){

	if (!imagepng($resizedImage, "{$pathToThumbs}mini_{$imagename}" )) // save thumbnail into a file

		$result='Nie można zapisać miniaturki w folderze docelowym!';

		ImageDestroy($croppedImage);  

	ImageDestroy($resizedImage);

	return $result;

	}

	if ($type== "gif"){

	if (!imagegif($resizedImage, "{$pathToThumbs}mini_{$imagename}" )) // save thumbnail into a file

		$result='Nie można zapisać miniaturki w folderze docelowym!';

		ImageDestroy($croppedImage);  

	ImageDestroy($resizedImage);

	return $result;

	}  

}

przy wgrywaniu i obróbce przeźroczystych PNG mam czarne tło :frowning: jak pozostawić przeźroczyste po zmniejszeniu?

Z góry dziękuje za pomoc,

Northwest

$croppedImage=imagecreatetruecolor($smallerSize, $smallerSize); // create square image

imagesavealpha($croppedImage, true);

$resizedImage=imagecreatetruecolor($site_max_thumbnails_size, $site_max_thumbnails_size);

imagesavealpha($resizedImage, true);

nie pomogło :frowning:

Dodane 11.03.2011 (Pt) 11:52

kurcze, nie wiem jak to zmienić :frowning: a jak ustawić np. domyslnie zielone tło zamiast czarnego?

$croppedImage=imagecreatetruecolor($smallerSize, $smallerSize); // create square image

imagealphablending($croppedImage, false);

imagesavealpha($croppedImage, true);

$resizedImage=imagecreatetruecolor($site_max_thumbnails_size, $site_max_thumbnails_size);

imagealphablending($resizedImage, false);

imagesavealpha($resizedImage, true);

działa, dzieki WIELKIE za pomoc :))