Jump to content

resizing images


andy_b_1502

Recommended Posts

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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

"$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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.