Jump to content


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


Complicated image script help

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

[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]

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

[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;
          $size = $t_h/$height;
    $modwidth = $width * $size;
    $modheight = $height * $size;
    $tn = imagecreatetruecolor($modwidth, $modheight) ;
    switch ($ext) {
        case 'jpg':
        case 'jpeg':
                    $image = imagecreatefromjpeg($file) ;
        case 'gif':
                    $image = imagecreatefromgif($file) ;
        case 'png':
                    $image = imagecreatefrompng($file) ;
    imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
    imagejpeg($tn, $save, 100) ;

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


[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?

Share this post

Link to post
Share on other sites
Perhaps I can refer you to this post


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

Please read the forum guidelines and do not double post.

Share this post

Link to post
Share on other sites
Actually the question is not the same. Originally I had not asked for the original image to be resized before it was saved, which throws it all off.

Share this post

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


Share this post

Link to post
Share on other sites

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!

Share this post

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


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.