Jump to content

Archived

This topic is now archived and is closed to further replies.

lpxxfaintxx

Watermarking Small Images

Recommended Posts

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]<?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();

?>
[/code]


function_watermark.php

[code]<?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;

}

?>[/code]



View Image.php

[code]View Image Code, you get the idea.[/code]


Thanks.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.