graham23s Posted November 10, 2007 Share Posted November 10, 2007 Hi Guys, i have created an image resizing function that works well here: function resize_images($filename,$uploaddirectory,$var_loggedinuser) { ## Find out the files extension $ext = explode(".", $filename); $ext = $ext[count($ext)-1]; ## Make all filenames lowercase $ext = strtolower($ext); if($ext == "jpg" || $ext == "jpeg") $image = imagecreatefromjpeg($uploaddirectory); elseif($ext == "png") $image = imagecreatefrompng($uploaddirectory); elseif($ext == "gif") $image = imagecreatefromgif($uploaddirectory); ## save the file in % $size = 0.50; ## rename the thumbnail $newimagename_thumb = $var_loggedinuser. "-" .time(); $save = "thumbs/$newimagename_thumb.$ext"; ## get the files dimensions list($width,$height) = getimagesize($uploaddirectory); ## New measurements $modwidth = $width * $size; $modheight = $height * $size; ## Start making the image $thumbnail = imagecreatetruecolor($modwidth, $modheight) ; imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height); ## Only return the image identified correctly if($ext == 'jpg' || $ext == 'jpeg') imagejpeg($thumbnail, $save, 100); if($ext == 'gif') imagegif($thumbnail, $save, 100); if($ext == 'png') imagepng($thumbnail, $save, 100); return($newimagename_thumb. "." .$ext); } what i was going to try next is overlaying text on uploaded images, not so much for the thumbnails but the original uploaded images code: <?php ## See if it's a first time user $query_user = "SELECT `photo`,`thumbnail` FROM `users` WHERE `id`='$var_loggedinuserid'"; $results_user = mysql_query($query_user) or die ("Error getting photo 1"); $row = mysql_fetch_array($results_user) or die ("Error getting the photo array"); $photouploaded = $row['photo']; $thumbnailuploaded = $row['thumbnail']; ## Delete old pic first if(!empty($photouploaded)) { stderr("Error","You already have a headshot uploaded, please delete it from the my account page before uploading another."); include("includes/footer.php"); exit; } ## HTML form echo ("<form action=\"uploadheadshot.php\" method=\"post\" enctype=\"multipart/form-data\" />"); echo ("<table class=\"sub_table\" width=\"500\" border=\"1\" align=\"center\" cellpadding=\"5\" cellspacing=\"0\">"); echo ("<tr>"); echo ("<td colspan=\"2\" class=\"edit\" align=\"left\"><img src=\"images/upload_headshot.jpg\"></td>"); echo ("</tr>"); echo ("<tr>"); echo ("<td align=\"center\"><b>Select a photo to upload</b></td><td align=\"center\"><input name=\"usersphoto\" type=\"file\" size=\"50\" /></td>"); echo ("</tr>"); echo ("<tr>"); echo ("<td colspan=\"2\" align=\"right\"><input type=\"submit\" name=\"submit\" value=\"Upload Photo\" /></td>"); echo ("</tr>"); echo ("</table>"); ## HTML form ## Deal with the submission if($_POST['submit']) { $filesize = $_FILES['usersphoto']['size']; $filetype = $_FILES['usersphoto']['type']; $filetemp = $_FILES['usersphoto']['tmp_name']; $filename = $_FILES['usersphoto']['name']; ## vars $maxheight = 500; $maxwidth = 500; $newimagename = $var_loggedinuser. "-" .time(); ## Allowed file types $allowed_types = array('image/pjpeg','image/gif','image/png','image/jpeg'); if($filesize == 0) { stderr("Upload Failed","No file was uploaded."); include("includes/footer.php"); exit; } if(!in_array($filetype, $allowed_types)) { stderr("Upload Failed","The file you uploaded is not one of the allowed types only .gif and .jpg are allowed."); include("includes/footer.php"); exit; } ## Rename the file $renamedimage = $newimagename.".".substr($_FILES["usersphoto"]["name"],strtolower(strlen($_FILES["usersphoto"]["name"]))-3,3); $uploaddirectory = "uploads/".$renamedimage; ## Upload code move_uploaded_file($filetemp, $uploaddirectory); $var_function = resize_images($filename,$uploaddirectory,$var_loggedinuser); ## insert the photo in the database $photoquery = mysql_query("UPDATE `users` SET `photo`='$renamedimage',`thumbnail`='$var_function' WHERE `id`='$var_loggedinuserid'"); stderr("Upload Successful","Your image has been uploaded successfully."); ## Show the thumbnail echo ('<table class="sub_table" width="20%" cellpadding="2" cellspacing="0"/>'); echo ('<tr>'); echo ('<td align="center"><img src="thumbs/'.$var_function.'"></td>'); echo ('</tr>'); echo ('<tr>'); echo ('<td align="center"><b>[<a class="foot_links" href="">Delete</a>]-[<a class="foot_links" href="uploads/'.$renamedimage.'" target="_blank">View Full Size</a>]</b></b></td>'); echo ('</tr>'); echo ("</table>"); include("includes/footer.php"); exit; } ?> i know i still need GD to do this, but not sure where else to go, could someone point me to a tutorial on this, it'd be appreciated. thanks guys Graham Quote Link to comment Share on other sites More sharing options...
Wuhtzu Posted November 10, 2007 Share Posted November 10, 2007 Here is a tutorial about image resizing and watermarking. Found by searching for "gdlib php watermark" http://www.phpit.net/article/image-manipulation-php-gd-part2/ (have a look at page3) Quote Link to comment Share on other sites More sharing options...
graham23s Posted November 10, 2007 Author Share Posted November 10, 2007 thanks mate pretty good tutorials there. Graham Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.