Jump to content


Photo

Complicated image script help


  • Please log in to reply
7 replies to this topic

#1 DaveLinger

DaveLinger
  • Members
  • PipPipPip
  • Advanced Member
  • 268 posts
  • LocationWV, USA

Posted 12 July 2006 - 04:12 PM

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

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

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


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

any ideas on how to put it all together?
http://www.DaveLinger.com
dave at linger dot com

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,020 posts

Posted 12 July 2006 - 07:27 PM

Perhaps I can refer you to this post

http://www.phpfreaks....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.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 DaveLinger

DaveLinger
  • Members
  • PipPipPip
  • Advanced Member
  • 268 posts
  • LocationWV, USA

Posted 12 July 2006 - 08:06 PM

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.
http://www.DaveLinger.com
dave at linger dot com

#4 litebearer

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

Posted 13 July 2006 - 12:28 AM

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


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

#5 DaveLinger

DaveLinger
  • Members
  • PipPipPip
  • Advanced Member
  • 268 posts
  • LocationWV, USA

Posted 13 July 2006 - 01:20 AM

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!
http://www.DaveLinger.com
dave at linger dot com

#6 litebearer

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

Posted 13 July 2006 - 01:30 AM

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

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

#7 DaveLinger

DaveLinger
  • Members
  • PipPipPip
  • Advanced Member
  • 268 posts
  • LocationWV, USA

Posted 13 July 2006 - 01:34 AM

alright :)

so...
http://www.DaveLinger.com
dave at linger dot com

#8 DaveLinger

DaveLinger
  • Members
  • PipPipPip
  • Advanced Member
  • 268 posts
  • LocationWV, USA

Posted 13 July 2006 - 12:20 PM

bizzump
http://www.DaveLinger.com
dave at linger dot com




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users