moon 111 Posted March 25, 2008 Share Posted March 25, 2008 I have this function: [code] <?php function watermarkImage ($SourceFile, $WaterMarkText, $DestinationFile, $x, $y, $font_size) { if(stripos($SourceFile, ".png")) { $ext = ".png"; } elseif(stripos($SourceFile, ".jpg") OR stripos($SourceFile, ".jpeg")) { $ext = ".jpg"; } list($width, $height) = getimagesize($SourceFile); $image_p = imagecreatetruecolor($width, $height); if($ext == ".png") $image = imagecreatefrompng($SourceFile); elseif($ext == ".jpg") $image = imagecreatefromjpeg($SourceFile); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width, $height); $black = imagecolorallocate($image_p, 0, 0, 0); $font = 'arial.ttf'; imagettftext($image_p, $font_size, 0, $x, $y, $black, $font, $WaterMarkText); if ($DestinationFile<>'') { if($ext == ".png") imagepng ($image_p, $DestinationFile, 100); elseif($ext == ".jpg") imagejpeg ($image_p, $DestinationFile, 100); } else { if($ext == ".png") { header('Content-Type: image/png'); imagepng($image_p, null, 100); } elseif($ext == ".jpg") { header('Content-Type: image/jpeg'); imagejpeg($image_p, null, 100); } } imagedestroy($image); imagedestroy($image_p); } ?> But it only works on .jpegs. Want I want to do is make it work with pngs too. I tried this but it didn't work: <?php function watermarkImage ($SourceFile, $WaterMarkText, $DestinationFile, $x, $y, $font_size) { if(stripos($SourceFile, ".png")) { $ext = ".png"; } elseif(stripos($SourceFile, ".jpg") OR stripos($SourceFile, ".jpeg")) { $ext = ".jpg"; } list($width, $height) = getimagesize($SourceFile); $image_p = imagecreatetruecolor($width, $height); if($ext == ".png") $image = imagecreatefrompng($SourceFile); elseif($ext == ".jpg") $image = imagecreatefromjpeg($SourceFile); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width, $height); $black = imagecolorallocate($image_p, 0, 0, 0); $font = 'arial.ttf'; imagettftext($image_p, $font_size, 0, $x, $y, $black, $font, $WaterMarkText); if ($DestinationFile<>'') { if($ext == ".png") imagepng ($image_p, $DestinationFile, 100); elseif($ext == ".jpg") imagejpeg ($image_p, $DestinationFile, 100); } else { if($ext == ".png") { header('Content-Type: image/png'); imagepng($image_p, null, 100); } elseif($ext == ".jpg") { header('Content-Type: image/jpeg'); imagejpeg($image_p, null, 100); } } imagedestroy($image); imagedestroy($image_p); } ?> Help please[/code] Quote Link to comment Share on other sites More sharing options...
ansarka Posted March 25, 2008 Share Posted March 25, 2008 what is the problem ????? :o :o ??? ??? ??? ??? ??? ??? ??? Quote Link to comment Share on other sites More sharing options...
moon 111 Posted March 25, 2008 Author Share Posted March 25, 2008 If the file is .png it gives me one of those squares with red symbol (what you get when you can't display the image). Read the code again - I edited it. Quote Link to comment Share on other sites More sharing options...
moon 111 Posted March 25, 2008 Author Share Posted March 25, 2008 Oh, sorry I fixed the code. The "code" tags Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.