Jump to content

imagerotate() removing transparency


patawic

Recommended Posts

Im trying to make a script that previews the level for a game, but im having issues with transparency and the rotation of each image.

 

you can see the problem here: http://beta.trackmill.com/DUI/preview/

 

here is the php file

<?php
header('Content-Type: image/png');
$image = imagecreatefrompng('images/Background.png');

function radiansToDegrees($radians)
{
    return $radians * 180 / pi();
}
$map = file_get_contents('map.txt');
$blocks = split("<obj", $map);
for($i=2; $i<count($blocks); $i++)
{
$arg = split(" ", $blocks[$i]);
$n = str_replace("n", "", str_replace("=", "", str_replace('"', "", $arg[1])));
$x = str_replace("x", "", str_replace("=", "", str_replace('"', "", $arg[2])));
$x = $x * 20 - 13;
$y = str_replace("y", "", str_replace("=", "", str_replace('"', "", $arg[3])));
$y = $y * 22 + 15;
$a = str_replace("a", "", str_replace("=", "", str_replace('"', "", $arg[4])));
$a = radiansToDegrees($a);
$t = str_replace("t", "", str_replace("=", "", str_replace('"', "", $arg[5])));
$e = str_replace("e", "", str_replace("=", "", str_replace('"', "", $arg[6])));
$f = str_replace("f", "", str_replace("=", "", str_replace('"', "", str_replace('/>', "", $arg[7]))));
$blockimage = imagecreatefrompng("images/$n.png");

$blockimage = imagerotate($blockimage, -$a, 0, 0) ;
imagealphablending($blockimage, false);
imagesavealpha($blockimage, true);

imagecopy($image, $blockimage, $x, $y, 0, 0, imagesx($blockimage), imagesy($blockimage));
//echo "$i | $n - $x - $y - $a - $t - $e - $f <br>";
}

imagepng($image);
imagedestroy($image);
?>

 

if you require the .zip containing the images etc, just reply and i will upload it as soon as possible

 

Link to comment
https://forums.phpfreaks.com/topic/220096-imagerotate-removing-transparency/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.