lpxxfaintxx Posted March 25, 2006 Share Posted March 25, 2006 Hello, I got the watermarking part of my website, but it doesn't look right when the images are really small. Is there any way so that if an image is too small, then it skips the watermarking part?Edit: Damn, the example links are not working for now. My host got attacked..Here's an example of a small image watermarked: [a href=\"http://aimmultimedia.com/membersimage.php?id=Userimage13\" target=\"_blank\"]http://aimmultimedia.com/membersimage.php?id=Userimage13[/a]Here's an example of a normal image: [a href=\"http://aimmultimedia.com/membersimage.php?id=DJ16\" target=\"_blank\"]http://aimmultimedia.com/membersimage.php?id=DJ16[/a]Sorry the server is extremely slow.Code: MembersUpload.php [code]UPLOAD CODE HERE$uploadfile = $uploaddir . $id . "." . $ext;$idpath = 'http://aimmultimedia.com/members/images/imagesbin/'.$id. '.'.$ext;$viewid = $imagename.$id;move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile);mysql_query("INSERT INTO `registered_files` (`id`,`path`,`owner`,`idpath`,`description`,`category`,`status`,`imagename`,`viewid`) VALUES('$id','$path','$owner','$idpath','$description','$category','$status','$imagename','$viewid')");header("Location: http://aimmultimedia.com/process2.php?id=$id&ext=$ext&viewid=$viewid");[/code]Process2.php[code]<?phpob_start();// The image should be located in a non public directory$id = $_GET['id'];$ext = $_GET['ext'];$viewid = $_GET['viewid'];$image_location = '/home/lpxxfain/public_html/members/images/'.$id. '.' .$ext; // Locate the watermark file wherever you choose (remember PNG format)$watermark_location = '/home/lpxxfain/public_html/members/water.png';// Location where you want to save the created watermarked file$save_watermarked_file_to = '/home/lpxxfain/public_html/members/images/imagesbin/'.$id. '.' .$ext;// Include the watermarking function filerequire_once($_SERVER['DOCUMENT_ROOT'] . '/function_watermark.php');// Watermark the image and save it to filewatermark($image_location, $watermark_location, $save_watermarked_file_to);header("Location: http://aimmultimedia.com/membersimage.php?id=$viewid");ob_end_flush();?>[/code]function_watermark.php[code]<?phpfunction watermark($SourceFile, $WatermarkFile, $SaveToFile = NULL){ $watermark = @imagecreatefrompng($WatermarkFile) or exit('Cannot open the watermark file.'); imageAlphaBlending($watermark, false); imageSaveAlpha($watermark, true); $image_string = @file_get_contents($SourceFile) or exit('Cannot open image file.'); $image = @imagecreatefromstring($image_string) or exit('Not a valid image format.'); $imageWidth=imageSX($image); $imageHeight=imageSY($image); $watermarkWidth=imageSX($watermark); $watermarkHeight=imageSY($watermark); $coordinate_X = ( $imageWidth - 5) - ( $watermarkWidth); $coordinate_Y = ( $imageHeight - 5) - ( $watermarkHeight); imagecopy($image, $watermark, $coordinate_X, $coordinate_Y, 0, 0, $watermarkWidth, $watermarkHeight); if(!($SaveToFile)) header('Content-Type: image/jpeg'); imagejpeg ($image, $SaveToFile, 100); imagedestroy($image); imagedestroy($watermark); if(!($SaveToFile)) exit;}?>[/code]View Image.php[code]View Image Code, you get the idea.[/code]Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/5763-watermarking-small-images/ Share on other sites More sharing options...
litebearer Posted March 26, 2006 Share Posted March 26, 2006 Use the [a href=\"http://us3.php.net/manual/en/function.getimagesize.php\" target=\"_blank\"]http://us3.php.net/manual/en/function.getimagesize.php[/a]to determine if the image is 'large' enough to warrant watermarking, if not skip it.Lite... Quote Link to comment https://forums.phpfreaks.com/topic/5763-watermarking-small-images/#findComment-20743 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.