Current location: Hot Scripts Forums » Programming Languages » PHP » upload and watermark


upload and watermark

Reply
  #1 (permalink)  
Old 07-26-04, 01:13 AM
StickMan StickMan is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
upload and watermark

Hi, i am farely new to php and i am trying to create a script so my users can upload their photos onto my server into there directory (which will be their username) and add a watermark on the bottom right corner. i found this code on a site earlier but i do not know how to use it. here is the code

PHP Code:

function makeImage() {

global 
$submitimage,$imagefile,$pos,$smallimage,$largeimage,$error_message_l,$alt_text,$desc_text;
$image_info getimagesize ($imagefile);
$image_type $image_info[2];
if (isset(
$submitimage) && $imagefile != "none" && $image_type == 2) {
// START MySQL INSERT & GET ID
$sql "INSERT INTO page_images VALUES('','','','$desc_text','$alt_text',NOW())";
mysql_query($sql) or die (mysql_error());
$image_id mysql_insert_id();

// GET SOURCE PICTURE FROM FORM INPUT
$b imagecreatefromjpeg($imagefile) or die ("Could not create from JPEG");
$bx imagesx($b); // source width
$by imagesy($b); // source height

// CREATE & RESIZE LARGE IMAGE 
if ($bx 499 || $by 499) { // only resize to large if original is bigger than source
if ($bx $by) { // if landscape
$lmx 500// new image width
$lmy intval($lmx $by $bx); // new img height
} else if ($by $bx) { // if portrait
$lmy 500// new image height
$lmx intval($lmy $bx $by); // new img width 
}
$lm ImageResize($b,$lmx,$lmy) or die ("Could not resize large image");
// ADD WATERMARK
if ($pos == "topleft") {
$src_x 0;
$src_y 0;
} else if (
$pos == "topright") {
$src_x $lmx 193;
$src_y 0;
} else if (
$pos == "bottomleft") {
$src_x 0;
$src_y $lmy 187;
} else if (
$pos == "bottomright") {
$src_x $lmx 193;
$src_y $lmy 187;
}
// THIS IS THE CODE FOR THE WATERMARK
ImageAlphaBlending($lmtrue) or die ("Could not alpha blend"); // Enable when on GD 2+
$logoImage ImageCreateFromPNG('../images/page_images/watermark.png');
$logoW ImageSX($logoImage);
$logoH ImageSY($logoImage);
ImageCopy($lm,$logoImage,$src_x,$src_y,0,0,$logoW,$logoH); 

// CREATE & SAVE LARGE IMAGE
$image_l "page_image$image_id".jpg";
imagejpeg($lm,"../images/page_images/$image_l",75) or die ("Could not imageJpeg"); 
imageDestroy($lm);
$largeimage "<img src=\"../images/page_images/$image_l\" width=\"$lmx\" height=\"$lmy\" alt=\"$alt_text\">";
}
// UPDATE DATABASE WITH NEW IMAGE FILE NAMES
$sql "UPDATE page_images SET image_file_s = '$image_s', image_file_l = '$image_l' WHERE image_id = '$image_id'";
mysql_query($sql) or die (mysql_error());
}

will this do what i want? thank you

-stickman

edit: and if a user wants to upload a gif file, will it still watermark it?

Last edited by StickMan; 07-26-04 at 01:53 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-26-04, 05:06 PM
StickMan StickMan is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Hi, i found this upload script http://www.vezine.net/article/7/1

how could i incorparate the watermarking from the other script into this one?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-26-04, 06:18 PM
Bonzo's Avatar
Bonzo Bonzo is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 340
Thanks: 0
Thanked 0 Times in 0 Posts
Somethings to think about before getting to far ahead :

Dose your host have GD or ImageMagick installed.

Is Safe Mode on.

Something else I cant remenber the name TrueFonts or something installed.

Terrible the old memory is going.

Anthony

P.S. I would stick to jpg for now as it makes things a lot easyer

P.P.S. I think the original code is way to complicated for what you want

Last edited by Bonzo; 07-26-04 at 06:20 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 07-26-04, 06:25 PM
StickMan StickMan is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks for replying

My host has GD2 and if your talking about TrueType, I have that too.

I dont really know what you mean by safemode?

I was also thinking about the gif thing and i just decided to only allow jpgs and pngs(?)

Thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 07-26-04, 06:32 PM
Bonzo's Avatar
Bonzo Bonzo is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 340
Thanks: 0
Thanked 0 Times in 0 Posts
Safe mode I found yesterday stops my method of doing things with ImageMagick but GD still works.

http://snipe.net/geek/toolz/ has some examples of what you want and a below is an upload bit of code ( I found somewhere ); you should be able to just tack the two bits together. Bed time for me now PM me if you still have problems.

Anthony

PHP Code:

// Image upload bit START

    
    
if ($_FILES['image']['name'] == "") {
    
#there's no file name return an error
    
echo "Please select a file to upload!\n";
    exit;    }

    
$uploads "temp/";
    
$types_array = array("image/pjpeg");

    if (!
in_array($_FILES['image']['type'], $types_array)) {
    
#the type of the file is not in the list we want to allow
    
echo "That file type is not allowed!\n";
    exit;      }

    
$max_filesize 102400;

    if (
$_FILES['image']['size'] > $max_filesize) {
    
#file is too large
    
}

move_uploaded_file($_FILES['image']['tmp_name'], "".$uploads."/".$_FILES['image']['name']) or die ("Couldn't upload file!"); 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 07-28-04, 06:32 PM
php~pro php~pro is offline
Wannabe Coder
 
Join Date: Jun 2004
Location: In a nice house.
Posts: 132
Thanks: 0
Thanked 0 Times in 0 Posts
RE: the original code.

Write standard file upload then run the file through this function.
Alter you database queries and aim your upload form at it.

//edit to suit table
$sql = "INSERT INTO page_images VALUES('','','','$desc_text','$alt_text',NOW())";

//edit to suit table
$sql = "UPDATE page_images SET image_file_s = '$image_s', image_file_l = '$image_l' WHERE image_id = '$image_id'";


and edit filepaths to suit you site directory.

Easy code to use.

Last edited by php~pro; 07-28-04 at 06:35 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 07-28-04, 09:33 PM
infinitylimit's Avatar
infinitylimit infinitylimit is offline
Code Guru
 
Join Date: Jun 2004
Location: Oregon
Posts: 758
Thanks: 0
Thanked 0 Times in 0 Posts
<scrambles through files> I have a bunch of image functions somewhere... hmmm

Here is the pseudo-code:

Grab POST data (your file)
Make sure it's a file on your server
Move that file to a directory
Read in the entire contents of the file (via GD)
read in the entire contents of the watermark (via GD)
Use ImageCreateTrueColor to make a new image
Fille it with date from the original file
Use ImageCopyResize and copy the watermark over
Write entrie contents to original file.


So yeah there is the idea behind it. You can learn about files at www.php.net/files and you can learn about images at www.php.net/image

So take it from there Sam.
__________________
Hawk Enterprises -- Home to PHP games, open-source code, tutorials and free downloads
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Image Upload Script Chives Script Requests 1 05-14-04 03:27 PM


All times are GMT -5. The time now is 09:48 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.