I have the following script that works great for .jpeg files, but once used for .gif the transparency is gone. What is it that I am missing.. I have searched everywhere and I'm going NUTS.

	 /// test watermark //
	 $font="$adminpath/register/include/MTCORSVA.TTF";
	 $text="testing";

 $white = imagecolorallocatealpha($source_id, 255, 255, 255, 90);
 $color = imagecolorallocatealpha($source_id, 0, 0, 0, 75);
 //check width of the text
 $bbox=imagettfbbox(20, 0, $font, $text);
 $xcorr=0-$bbox[6];
 $mase=$bbox[2]+$xcorr;
 //check height of the image
 $heightnew=imagesy($source_id);
 $height=(($heightnew/2)+10);
 $heightoffset=($height+1);
 //check width of the image
 $widthnew=imagesx($source_id);
 $width=($widthnew-$mase)/2;
 $widthoffset=($width+1);
 //calculate x coordinates for text
 //$new=($width-$mase)/2;
 // Add some shadow to the text
 ImageTTFText($source_id, 20, 0, $widthoffset, $heightoffset, $color, $font, $text);
 ImageTTFText($source_id, 20, 0, $width, $height, $white, $font, $text);
 if ($size[2] == '2'){ 
 ImageJPEG($source_id,"$adminpath/customerimages/" . $renameimage,100);  
 } else if ($size[2] == '1'){
 ImageGIF($source_id,"$adminpath/customerimages/" . $renameimage,100);
 }
 ImageDestroy($source_id); 
 ///

    GIF is only able to accommodate a maximum of 256 colours (adding a semitransparent overlay potentially doubles the number of colours required, and as soon as 256 colours are used, it will just keep reusing those colours for any alterations), and has no no support for an alpha channel.

    Unlike PNG. Consider using that instead. It's a much more advanced format.

    (Note that you are under no obligation to save a file in the same format that it was originally supplied in.)

      Write a Reply...