Page 1 of 1

semi-transparent grid

Posted: Mon Nov 08, 2004 12:15 pm
by jtc970
I have a predrawn PNG map with a transparent background
I am trying to overlay a semi-transparent grid (size set will be variable)

I have it drawing the grid but cant get it to be semi-transparent

here is what I have so far

Code: Select all

<?
Header( "Content-type: image/png"); 
$grid_alpha=75;


$grid_x	=	10;
$grid_y	=	10;


############
# Make Map #
############
$mapname=$_GET['map'];

//open map
$map=$loc.'/sources/map_images/'.$mapname.'.png';
$image = imagecreatefrompng($map); 

$image_x	=	imagesx($image); 
$image_y	=	imagesy($image); 


//make grid
$grid_color				= imagecolorallocatealpha($image, 0,0,255,$grid_alpha );



// draw the | lines

$x1=0;$x2=$grid_x;
$y1=0;$y2=$image_y;
while ($x1 < $image_x){
		imageline( $image, $x1 , $y1 , $x2 , $y2 , $grid_color ); 
		


		$x1=$x1+$grid_x;
		$x2=$x2+$grid_x;
} 
// draw the - lines

$x1=0;$x2=$image_x;
$y1=0;$y2=0;
while ($y1 < $image_y){
		imageline ( $image , $x1 , $y1 , $x2 , $y2 , $grid_color ); 
		$y1=$y1+$grid_y;
		$y2=$y2+$grid_y;
} 


ImagePNG($image);
/* cleanup memory */
ImageDestroy($image);

exit;
?>

Posted: Mon Nov 08, 2004 1:32 pm
by rehfeld
i tried and was able to draw alpha elipses on top of the image, but the lines wont do it, and i used the same grid_color

odd...

Posted: Mon Nov 08, 2004 7:16 pm
by jtc970
Thanks, I somewhat got it to work by adding in

Code: Select all

$map=$loc.'/sources/map_images/'.$mapname.'.png';

$image2 = imagecreatefrompng($map); /* Attempt to open */

$image_x	=	imagesx($image2); 
$image_y	=	imagesy($image2); 

$image=imagecreatetruecolor($image_x,$image_y);
$black = ImageColorAllocate ($image, 0, 0, 0);
ImageColorTransparent($image, $black);

imagecopy ($image, $image2, 0, 0, 0, 0, $image_x, $image_y);
but it IE shows a black background where firefox shows it with a transparent background and semi transparent grid.

any other suggestions?

Posted: Tue Nov 09, 2004 1:18 am
by rehfeld
ie doesnt support png transparency.


but you can fudge it by using ie's filters

look into alphaimageloader

Posted: Tue Nov 09, 2004 8:46 am
by jtc970
Thanks, I wil check it out.