s0l1dsnak3123 Posted February 21, 2009 Share Posted February 21, 2009 Hi there, I have almost successfully overlayed an image from a string onto an image dynamically retrieved from a database, and making white in the overlay image transparent. One problem though: the resulting image has a little white halo as seen below. No matter what I've tried, I have not been able to get rid of those damn white halos... Here is the code I am using: function WatermarkImage( $CanvasImage, $WatermarkImageLink /* MUST BE PNG */, $SaveFilePath, $Opacity = 10, $Quality = 75 ) { // create true color canvas image: $canvas_src = @imagecreatefromjpeg( $CanvasImage ) or $canvas_src = @imagecreatefrompng( $CanvasImage ) or // or PNG Image // or GIF Image $canvas_src = @imagecreatefromgif( $CanvasImage ); $canvas_w = imagesx( $canvas_src ); $canvas_h = imagesy( $canvas_src ); $canvas_img = imagecreatetruecolor( $canvas_w, $canvas_h ); imagecopy( $canvas_img, $canvas_src, 0, 0, 0, 0, $canvas_w, $canvas_h ); // no longer needed imagedestroy( $canvas_src ); // create true color overlay image: $overlay_src = imagecreatefromstring( $WatermarkImageLink ); $overlay_w = imagesx( $overlay_src ); $overlay_h = imagesy( $overlay_src ); $overlay_img = imagecreatetruecolor( $overlay_w, $overlay_h ); imagecopy( $overlay_img, $overlay_src, 0, 0, 0, 0, $overlay_w, $overlay_h ); // no longer needed imagedestroy( $overlay_src ); //imagealphablending( $overlay_img, false ); // setup transparent color (pick one): $black = imagecolorallocate( $overlay_img, 0x00, 0x00, 0x00 ); $white = imagecolorallocate( $overlay_img, 0xFF, 0xFF, 0xFF ); $white_close = imagecolorclosest( $overlay_img, 0xFF, 0xFF, 0xFF ); $magenta = imagecolorallocate( $overlay_img, 0xFF, 0x00, 0xFF ); // and use it here: imagecolortransparent( $overlay_img, $white ); // Attempt to get rid of near-whites imagecolortransparent( $overlay_img, $white_close ); imagesavealpha( $overlay_img, true ); imagealphablending( $overlay_img, false ); // copy and merge the overlay image and the canvas image: imagecopymerge( $canvas_img, $overlay_img, 0, 0, 0, 0, $overlay_w, $overlay_h, $Opacity ); // The text to draw $text = 'Copyright (c) ' . date(Y) . ' Space Web Design. All rights reserved.'; // Replace path by your own font path //$font = imageloadfont('./gdf_fonts/trisk.gdf'); $font = imageloadfont( './gdf_fonts/' . IMAGE_FONT ); //$font = imageloadfont('./gdf_fonts/courier8.gdf'); //$font = imageloadfont('./gdf_fonts/checkbook.gdf'); //$font = 2; imagestring($canvas_img, $font, 10, $canvas_h-18, 'Copyright (c) ' . date(Y) . ' ' . COMPANY_COPYRIGHT , $white); // output: imagejpeg( $canvas_img, $SaveFilePath, $Quality ); imagedestroy( $overlay_img ); imagedestroy( $canvas_img ); } The colour I am using here for transparency is White. The string image is being generated from a flex application and is dynamic (hence the string function - it hasn't been saved, only POSTed). Please help me... I've been trying to correct this for hours with no luck. :-\ Thanks in advance, John. Link to comment https://forums.phpfreaks.com/topic/146235-overlaying-image-from-string/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.