andy_b_1502 Posted February 28, 2012 Share Posted February 28, 2012 I am absolutley stumped with this: im trying to have PHP get the size of an image that has been uploaded to mySQL, and return it to a certain size, lets say 200X200px. The problems im having to finding an existing script to help me understand - and then fit it into a table? All the help from google searches seem to suggest using software, but i would like to learn how to do this properly. First off the upload script: <?php error_reporting(E_ALL); ini_set("display_errors", 1); echo '<pre>' . print_r($_FILES, true) . '</pre>'; //This is the directory where images will be saved $target = "/home/users/web/b109/ipg.removalspacecom/images/COMPANIES"; $target = $target . basename( $_FILES['upload']['name']); //This gets all the other information from the form $company_name=$_POST['company_name']; $basicpackage_description=$_POST['basicpackage_description']; $location=$_POST['location']; $postcode=$_POST['postcode']; $upload=($_FILES['upload']['name']); // Connects to your Database mysql_connect("server", "user", "password") or die(mysql_error()) ; mysql_select_db("removalspacelogin") or die(mysql_error()) ; //Writes the information to the database mysql_query("INSERT INTO `Companies` (company_name, basicpackage_description, location, postcode, upload) VALUES ('$company_name', '$basicpackage_description', '$location', '$postcode', '$upload')") ; echo mysql_error(); //Writes the photo to the server if(move_uploaded_file($_FILES['upload']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ". basename( $_FILES['upload']['name']). " has been uploaded, and your information has been added to the directory"; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } ?> this works great, it uploads the users pictures. This displays them out: <?php $database="removalspacelogin"; mysql_connect ("server", "user", "password"); @mysql_select_db($database) or die( "Unable to select database"); $result = mysql_query( "SELECT company_name, location, postcode, basicpackage_description, premiumuser_description, upload FROM Companies" ) or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($result); print "\n\n\nThere are $num_rows records.<P>"; echo "<table><tr><th>Comppany Name</th><th>Location</th><th>Postcode</th><th>Basic Members</th><th>Upgraded Users</th><th>Company Logo</th></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td></tr>";// store the records into $row array and loop through while ( $row = mysql_fetch_array( $result, MYSQL_ASSOC ) ) { // Print out the contents of the entry echo "<tr><td>{$row['company_name']}</td>"; echo "<td>{$row['location']}</td>"; echo "<td>{$row['postcode']}</td>"; echo "<td>{$row['basicpackage_description']}</td>"; echo "<td>{$row['premiumuser_description']}</td>"; echo "<td><img src=\"http://www.removalspace.com/images/COMPANIES{$row['upload']}\" alt=\"logo\" /></td></tr>";} echo "</table>"; ?> Right now all the information in my table is fine except the image coloumn, the images are all the same size as they went in, i'd like them to all be one size so there in a uniformed fashion. But need all the rest of the mySQL table displayed, so how does it fit into my script to display the table? Many thanks!??? :confused: Quote Link to comment https://forums.phpfreaks.com/topic/257933-resizing-images/ Share on other sites More sharing options...
litebearer Posted February 28, 2012 Share Posted February 28, 2012 the images are all the same size as they went in, i'd like them to all be one size so there in a uniformed fashion To get them all the same size will probably entail both RESIZING and CROPPING, as they are currently unlikely to be bigger/smaller than each other proportionately. these two might be a starting point... Cropping - http://www.nstoia.com/sat/crop/ Resizing - http://www.nstoia.com/sat/resize/ (using a "picture frame" might also lend visual symmetry) Quote Link to comment https://forums.phpfreaks.com/topic/257933-resizing-images/#findComment-1322108 Share on other sites More sharing options...
andy_b_1502 Posted February 29, 2012 Author Share Posted February 29, 2012 "$file is the name of the original image WITHOUT the path;" ---- I need to state this everytime?? isn't there a way of choosing every image thats uploaded? $save is the name of the resized image WITHOUT the path; ---- My existing script currently gives uploaded images a generated name to put to the server; what do i put here. $t_w is the MAXIMUM width of the new image; ---- this will end up being 200px $t_h is the MAXIMUM height of the new image; ---- this will end up 200px also $o_path is the path to the original image INCLUDING the trailing slash; ---- "http://www.removalspace.com/images/COMPANIES $s_path is the path where you want to save the new image INCLUDING the trailing slash. ---- "http://www.removalspace.com/images/COMPANIES then all these fit under the while loop? right? Quote Link to comment https://forums.phpfreaks.com/topic/257933-resizing-images/#findComment-1322397 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.