semi-transparent grid

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jtc970
Forum Commoner
Posts: 38
Joined: Sun Jan 18, 2004 11:49 pm

semi-transparent grid

Post 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;
?>
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post 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...
jtc970
Forum Commoner
Posts: 38
Joined: Sun Jan 18, 2004 11:49 pm

Post 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?
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

ie doesnt support png transparency.


but you can fudge it by using ie's filters

look into alphaimageloader
jtc970
Forum Commoner
Posts: 38
Joined: Sun Jan 18, 2004 11:49 pm

Post by jtc970 »

Thanks, I wil check it out.
Post Reply