Jump to content

Recommended Posts

Here's what I'm hoping for... a page on which the user can upload an image via a web form. PHP then resizes that image to like 1024x1024, watermarks it with text, saves it, resizes it to like 120x120, then saves the thumbnail. (with the watermark saved on the original one resized as well)

here are the "chunks" I have... just dont know how to put it all together...

WEB FORM
[code]<form enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">

<input type="hidden" name="MAX_FILE_SIZE" value="3072000"><input name="userfile" type="file" />

<input type="submit" value="Upload" /></form>[/code]

UPLOAD
[code]if (@is_uploaded_file($_FILES["userfile"]["tmp_name"])) {
copy($_FILES["userfile"]["tmp_name"], "files/" . $_FILES["userfile"]["name"]);[/code]

RESIZE
[code]function Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path) {
    $s_path = trim($s_path);
    $o_path = trim($o_path);
    $save = $s_path . $save;
    $file = $o_path . $file;
    $ext = strtolower(end(explode('.',$save)));
    list($width, $height) = getimagesize($file) ;
    if(($width>$t_w) OR ($height>$t_h)) {
        $r1 = $t_w/$width;
        $r2 = $t_h/$height;
        if($r1<$r2) {
          $size = $t_w/$width;
        }else{
          $size = $t_h/$height;
        }
    }else{
        $size=1;
    }
    $modwidth = $width * $size;
    $modheight = $height * $size;
    $tn = imagecreatetruecolor($modwidth, $modheight) ;
    switch ($ext) {
        case 'jpg':
        case 'jpeg':
                    $image = imagecreatefromjpeg($file) ;
        break;
        case 'gif':
                    $image = imagecreatefromgif($file) ;
        break;
        case 'png':
                    $image = imagecreatefrompng($file) ;
        break;
    }
    imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
    imagejpeg($tn, $save, 100) ;
    return;
}

$save = 'myfile.jpg';
$file = 'original.jpg';
$t_w = 120;
$t_h = 120;
$o_path = " ";
$s_path = " ";

Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path);[/code]


WATERMARK
[code]$white = imagecolorallocate($image, 255, 255, 255);
$text = 'MyText';
$font = 'CALIBRI.TTF';
imagettftext($image, 10, 0, 10, 10, $white, $font, $text);
imagejpeg($image, $save, 100);[/code]

any ideas on how to put it all together?
Link to comment
https://forums.phpfreaks.com/topic/14394-complicated-image-script-help/
Share on other sites

Perhaps I can refer you to this post

http://www.phpfreaks.com/forums/index.php/topic,99470.msg393481.html#msg393481

which was my reply to this exact same question last time you posted it.

Please read the forum guidelines and do not double post.
Just a thought (or two)....

(1) consider the real objective - presumably to prevent unauthorized use of an image.

(2) realizing that your example ( 1024 x 1024  original to 120 x 120 thumb), is exactly that - an example, IF we were to create an image 1024 x 1024, it would take a watermark approximately 400 x 400 to have the mark be of sufficient size to 'protect' the image AND to still be visible when scaled down to 120 x 120.

(3) re-evaluate the need for the thumb to be watermarked, it will have lost sufficient definition during the resizing process so as to make it unsuitable for enlarging.

(4) re-evaluate the need for watermarking at all. If I so desperately wanted to 'steal' an image, it would take well under an hour to remove all traces of a watermark using readily available graphics software.

(5) consider who might attempt to 'steal' your images.  one must remember laws protect all of us, and it is very easy to obtain a judgment against someone who has infringed upon our rights and property. HOWEVER, collecting on that judgement is extremely difficult and time consuming. Not to mention that although a court may agree that you have been 'injured';  the value of that 'injury' may be miniscule in the court's eyes.

Just an old man's two cents.

Lite...

lite,

thanks, but the watermarking isn't really to prevent malicious graphics swindlers from using my images, more to inform people of where the image was loaded from, if people link to my images from their site. I couldn't care less if they SAVE it and alter it, its not using MY bandwidth.

should I resize it to 120x120 BEFORE I watermark it then watermark each one individually(maybe in tinyfont for the thumb) rather than resizing the already watermarked 1024?

Thanks again!
I would think that watermarking the thumbnail AFTER it is created would provide the best clarity of the watermark message. Text has a tendency to become very blurred when it is reduced AFTER it is created. (O's e's, a's, g's and r's end up with the 'loop' closing into a dot).

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