Jump to content

Watermarking Small Images


lpxxfaintxx

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.