Jump to content


Photo

Watermarking Small Images


  • Please log in to reply
1 reply to this topic

#1 lpxxfaintxx

lpxxfaintxx
  • Members
  • PipPipPip
  • Advanced Member
  • 181 posts

Posted 25 March 2006 - 12:43 PM

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
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");




Process2.php

<?php
ob_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 file

require_once($_SERVER['DOCUMENT_ROOT'] . '/function_watermark.php');



// Watermark the image and save it to file

watermark($image_location, $watermark_location, $save_watermarked_file_to);

header("Location: http://aimmultimedia.com/membersimage.php?id=$viewid");
ob_end_flush();

?>


function_watermark.php

<?php

function 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;

}

?>



View Image.php

View Image Code, you get the idea.


Thanks.

#2 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 26 March 2006 - 12:57 AM

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...

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users