andy_b_1502 Posted March 15, 2012 Share Posted March 15, 2012 Hi everyone, I am after a scrpit/function that will get information of an uploaded image, resize it, then display the manipulated image. in my "upload" script, there will be a size limit and a file extension/type limit to: 600 x 200px / jpg, gif, jpeg... this is to keep the script i'm after more simple. As using vector images i'm told is such a complicated problem for me at this time. So... to get the size info/dimensions its like this: <?php list($width, $height, $type, $attr) = getimagesize("image_name.jpg"); echo "Image width " .$width; echo "<BR>"; echo "Image height " .$height; echo "<BR>"; echo "Image type " .$type; echo "<BR>"; echo "Attribute " .$attr; ?> and..... resize something like this: function get_image_sizes($sourceImageFilePath, $maxResizeWidth, $maxResizeHeight) { // Get width and height of original image $size = getimagesize($sourceImageFilePath); if($size === FALSE) return FALSE; // Error $origWidth = $size[0]; $origHeight = $size[1]; // Change dimensions to fit maximum width and height $resizedWidth = $origWidth; $resizedHeight = $origHeight; if($resizedWidth > $maxResizeWidth) { $aspectRatio = $maxResizeWidth / $resizedWidth; $resizedWidth = round($aspectRatio * $resizedWidth); $resizedHeight = round($aspectRatio * $resizedHeight); } if($resizedHeight > $maxResizeHeight) { $aspectRatio = $maxResizeHeight / $resizedHeight; $resizedWidth = round($aspectRatio * $resizedWidth); $resizedHeight = round($aspectRatio * $resizedHeight); } // Return an array with the original and resized dimensions return array($origWidth, $origHeight, $resizedWidth, $resizedHeight); } // Get dimensions $sizes = get_image_sizes($sourceImageFilePath, $maxResizeWidth, $maxResizeHeight); $origWidth = $sizes[0]; $origHeight = $sizes[1]; $resizedWidth = $sizes[2]; $resizedHeight = $sizes[3]; // Create the resized image $imageOutput = imagecreatetruecolor($resizedWidth, $resizedHeight); if($imageOutput === FALSE) return FALSE; // Error condition // Load the source image $imageSource = imagecreatefromjpeg($sourceImageFilePath); if($imageSource === FALSE) return FALSE; // Error condition $result = imagecopyresampled($imageOutput, $imageSource, 0, 0, 0, 0, $resizedWidth, $resizedHeight, $origWidth, $origHeight); if($result === FALSE) return false; // Error condition // Write out the JPEG file with the highest quality value $result = imagejpeg($imageOutput, $outputPath, 100); if($result === FALSE) return false; // Error condition And.... display is this: <?php $database="***"; mysql_connect ("***", "***", "***"); @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>"; ?> How will all these fit together in one script? any help i'd love it! many thanks in advance Quote Link to comment Share on other sites More sharing options...
blacknight Posted March 15, 2012 Share Posted March 15, 2012 first make a forum to upload the image run upload script on finish run resize then display Quote Link to comment Share on other sites More sharing options...
andy_b_1502 Posted March 16, 2012 Author Share Posted March 16, 2012 Thanks but i need help fitting all the pieces together, im not sure where each bit goes. I have this upload and resize script but now iv'e modified it, it won't upload the image or resize? What am i doing wrong? <?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("sever", "user", "password") or die(mysql_error()) ; mysql_select_db("DB") 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(); $uploadDir = 'images/COMPANIES'; // main picture folder $max_height = 450; // largest height you allowed; 0 means any $max_width = 450; // largest width you allowed; 0 means any $max_file = 2000000; // set the max file size in bytes $image_overwrite = 1; // 0 means overwite; 1 means new name $allowed_type01 = array( "image/gif", "image/pjpeg", "image/jpeg", "image/png", "image/x-png", "image/jpg"); // add or delete allowed image types $do_thumb = 1; // 1 make thumbnails; 0 means do NOT make $thumbDir = "/images/thumbs"; // thumbnail folder $thumb_prefix = ""; // prefix for thumbnails $thumb_width = 90; // max thumb width $thumb_height = 70; // max thumb height $do_shadow = 0; // 0 to add drop shadow to main image. 1 do NOT $flat_file = 0; // 1 flat file for data; 0 database $what_error = array(); // error message array/* // RESIZE FUNCTION */ 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;} /* END OF RESIZE FUNCTION */ //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 is what i end up with: http://www.removalspace.com/index.php note all the images different sizes. Quote Link to comment Share on other sites More sharing options...
andy_b_1502 Posted March 17, 2012 Author Share Posted March 17, 2012 Any ideas??? :wtf: Quote Link to comment Share on other sites More sharing options...
SaCH Posted March 17, 2012 Share Posted March 17, 2012 You need a basic idea about the coding.. Please follow my simple steps. 1. Create a html form to upload image file. 2. Get the image file 3. Get the size info/dimensions by using the uploaded image. 4. Resize it with your function 5. Display the image Quote Link to comment Share on other sites More sharing options...
andy_b_1502 Posted March 17, 2012 Author Share Posted March 17, 2012 I have got the form <form enctype="multipart/form-data" action="basicpackage-send.php" method="POST"> Compnany Name:<br /> <input type="text" name="company_name" id="company_name"><br> Company Description:<br /> <input type="text" name = "basicpackage_description" id="basicpackage_description"><br> Location:<br /> <input type="text" name = "location" id="location"><br> Postcode:<br /> <input type="text" name = "postcode" id="postcode"><br> Company Logo/Photo:<br /> <input type="file" name="upload" id="upload"><br> <input type="submit" value="Add to our directory"> </form> i have got the get imagesize functions and resize funtctions: <?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 //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(); $uploadDir = 'images/COMPANIES'; // main picture folder $max_height = 450; // largest height you allowed; 0 means any $max_width = 450; // largest width you allowed; 0 means any $max_file = 2000000; // set the max file size in bytes $image_overwrite = 1; // 0 means overwite; 1 means new name $allowed_type01 = array( "image/gif", "image/pjpeg", "image/jpeg", "image/png", "image/x-png", "image/jpg"); // add or delete allowed image types $do_thumb = 1; // 1 make thumbnails; 0 means do NOT make $thumbDir = "/images/thumbs"; // thumbnail folder $thumb_prefix = ""; // prefix for thumbnails $thumb_width = 90; // max thumb width $thumb_height = 70; // max thumb height $do_shadow = 0; // 0 to add drop shadow to main image. 1 do NOT $flat_file = 0; // 1 flat file for data; 0 database $what_error = array(); // error message array/* // RESIZE FUNCTION */ 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;} /* END OF RESIZE FUNCTION */ //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."; } ?> My question is, what is going wrong in this code to make it fail/ or why isnt this working? it only uploads the image BUT doesnt resize them. Could you please shed some light on to this for me? it should work but it doesnt? many thanks. Quote Link to comment Share on other sites More sharing options...
andy_b_1502 Posted March 17, 2012 Author Share Posted March 17, 2012 it's not working, the resize function...? Quote Link to comment Share on other sites More sharing options...
litebearer Posted March 17, 2012 Share Posted March 17, 2012 You have defined the function, but where have you 'called' the function? Quote Link to comment Share on other sites More sharing options...
andy_b_1502 Posted March 18, 2012 Author Share Posted March 18, 2012 <?php $database=""; mysql_connect (""; @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>"; ?> include resize_function? or select resize_function? Quote Link to comment Share on other sites More sharing options...
litebearer Posted March 18, 2012 Share Posted March 18, 2012 NOT in the display section, but in the upload section (Look way down in the section that moves the image)... ALSO, do your database inserting AFTER you have moved the image, otherwise, your table data may point to a non-existent image. <?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 //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(); $uploadDir = 'images/COMPANIES'; // main picture folder $max_height = 450; // largest height you allowed; 0 means any $max_width = 450; // largest width you allowed; 0 means any $max_file = 2000000; // set the max file size in bytes $image_overwrite = 1; // 0 means overwite; 1 means new name $allowed_type01 = array( "image/gif", "image/pjpeg", "image/jpeg", "image/png", "image/x-png", "image/jpg"); // add or delete allowed image types $do_thumb = 1; // 1 make thumbnails; 0 means do NOT make $thumbDir = "/images/thumbs"; // thumbnail folder $thumb_prefix = ""; // prefix for thumbnails $thumb_width = 90; // max thumb width $thumb_height = 70; // max thumb height $do_shadow = 0; // 0 to add drop shadow to main image. 1 do NOT $flat_file = 0; // 1 flat file for data; 0 database $what_error = array(); // error message array/* // RESIZE FUNCTION */ 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;} /* END OF RESIZE FUNCTION */ //Writes the photo to the server if(move_uploaded_file($_FILES['upload']['tmp_name'], $target)) { /* CALL THE FUNCTION HERE */ Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path) //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."; } ?> Quote Link to comment Share on other sites More sharing options...
andy_b_1502 Posted March 18, 2012 Author Share Posted March 18, 2012 im getting a lot of error's with that: Array ( [upload] => Array ( [name] => company%20logo(5).jpg [type] => image/jpeg [tmp_name] => /tmp/phpVlRTx1 [error] => 0 => 24713 ) ) Notice: Undefined variable: save in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 83 Notice: Undefined variable: file in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 83 Notice: Undefined variable: t_w in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 83 Notice: Undefined variable: t_h in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 83 Notice: Undefined variable: s_path in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 83 Notice: Undefined variable: o_path in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 83 Warning: getimagesize() [function.getimagesize]: Filename cannot be empty in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 51 Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 63 Notice: Undefined variable: image in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 74 Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 74 Warning: imagejpeg(): supplied argument is not a valid Image resource in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 75 The file company%20logo(5).jpg has been uploaded, and your information has been added to the directory Quote Link to comment Share on other sites More sharing options...
litebearer Posted March 18, 2012 Share Posted March 18, 2012 you need to define/set the variables that the function uses. Quote Link to comment Share on other sites More sharing options...
andy_b_1502 Posted March 18, 2012 Author Share Posted March 18, 2012 /* CALL THE FUNCTION HERE */ if($Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path)) ; Notice: Undefined variable: Resize_Image in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86 Fatal error: Function name must be a string in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86 if() defines the variable right? why am i getting an undefined variable error message litebearer? Quote Link to comment Share on other sites More sharing options...
guinbRo Posted March 18, 2012 Share Posted March 18, 2012 Correct me if I'm missing a piece of PHP syntax, but in your last post the problem is that PHP thinks Resize_Image is a variable, and not a function as it truly is. Fix it to be this: if(Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path)) { //Notice that the '$' sign was removed } Quote Link to comment Share on other sites More sharing options...
andy_b_1502 Posted March 18, 2012 Author Share Posted March 18, 2012 Thanks guinBro BUT it doesnt seem to have worked changing that. I'm still getting error messages to define the variable: Notice: Undefined variable: save in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86 Notice: Undefined variable: file in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86 Notice: Undefined variable: t_w in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86 Notice: Undefined variable: t_h in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86 Notice: Undefined variable: s_path in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86 Notice: Undefined variable: o_path in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86 Warning: getimagesize() [function.getimagesize]: Filename cannot be empty in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 52 Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 64 Notice: Undefined variable: image in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 75 Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 75 Warning: imagejpeg(): supplied argument is not a valid Image resource in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 76 The file img02.jpg has been uploaded, and your information has been added to the directory So going back to my question, why isnt it working when i define it???? lol Quote Link to comment Share on other sites More sharing options...
guinbRo Posted March 18, 2012 Share Posted March 18, 2012 What are you declaring these variables to be? Do you think that the error may be revolving around this? $save $file $t_w $t_h $s_path $o_path Quote Link to comment Share on other sites More sharing options...
andy_b_1502 Posted March 18, 2012 Author Share Posted March 18, 2012 yes... they are as part of my resize function 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;} /* END OF RESIZE FUNCTION */ do i have to define each one?? Quote Link to comment Share on other sites More sharing options...
guinbRo Posted March 18, 2012 Share Posted March 18, 2012 Well yeah, your function can't work without the specified parameters. It looks like it wants, for example, a location where the image is at, the location where the new image will be placed, etc. Without passing these parameters the function won't work. So what I mean is that when you call the function, you have to be passing it the information it desires. Quote Link to comment Share on other sites More sharing options...
andy_b_1502 Posted March 18, 2012 Author Share Posted March 18, 2012 As i've posted the whole script previously; it knows where the image is, as the image is sent to the main folder then it resizes it. I thought that this piece of code here is "at the end" of the script that drops the image into the image folder. So shouldnt it just do this: 1. Upload the image 2. Drop it into the folder 3. Resize it 4. Display newly re-sized image when called from server "So what I mean is that when you call the function, you have to be passing it the information it desires." What information should it need, thats preventing it from working at present? Quote Link to comment Share on other sites More sharing options...
andy_b_1502 Posted March 18, 2012 Author Share Posted March 18, 2012 if(Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path)) { //Notice that the '$' sign was removed } and is this all i need to define it? im slightly confused Quote Link to comment Share on other sites More sharing options...
litebearer Posted March 18, 2012 Share Posted March 18, 2012 The function takes six parameters: $file is the name of the original image WITHOUT the path; ie. $file = "newburg.jpg"; $save is the name of the resized image WITHOUT the path; ie. $save = "newburg.jpg"; $t_w is the MAXIMUM width of the new image; ie $t_w = 100; $t_h is the MAXIMUM height of the new image; ie $t_h = 100; $o_path is the path to the original image INCLUDING the trailing slash; and ie. $0_path = "/my_large/"; $s_path is the path where you want to save the new image INCLUDING the trailing slash. ie. $s_path = "/my_thumbs/" You MUST set these variables OUTSIDE the function BEFORE you call/use the function. Quote Link to comment Share on other sites More sharing options...
andy_b_1502 Posted March 18, 2012 Author Share Posted March 18, 2012 Isn't there a way of calling $file a generic name? as i won't know the name of every file uploaded each time will i?? same with the resized image? it should be done all automatically shouldn't it? $s_path = trim("/images/thumbs"); $o_path = trim('images/COMPANIES'); $save = $s_path . $save; $file = $o_path . $file; $s_path = trim("/images/thumbs"); $o_path = trim('images/COMPANIES'); $save = thumbs . $save; $file = COMPANIES . $file; Quote Link to comment Share on other sites More sharing options...
andy_b_1502 Posted March 18, 2012 Author Share Posted March 18, 2012 why the hell isn't this sinking in!? i just dont get this, im sorry! Quote Link to comment Share on other sites More sharing options...
litebearer Posted March 18, 2012 Share Posted March 18, 2012 Step back, take a deep breath, then look at your existing code - do you see where you created a variable containing the name of the image? hint: $upload that would be your be your $file ie $file = $upload; you can use the same name for the thumb/resized image if you are either (A) putting the thumb in a different folder than the original, or (b) overwriting the original ALSO did you read the instructions regarding trailing slashes for the paths? Quote Link to comment Share on other sites More sharing options...
andy_b_1502 Posted March 18, 2012 Author Share Posted March 18, 2012 Okay... so... Ive now changed the paths to the original image, and for the thumbnails to read like this: // RESIZE FUNCTION */ function Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path) { $s_path = trim("/images/thumbs"); $o_path = trim("images/COMPANIES"); $save = $upload . $save; $file = $upload . $file; Then is call the function like so: /* CALL THE FUNCTION HERE */ if(Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path)) { //Notice that the '$' sign was removed } However the problem error messages persist: Notice: Undefined variable: save in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86 Notice: Undefined variable: file in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86 Notice: Undefined variable: t_w in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86 Notice: Undefined variable: t_h in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86 Notice: Undefined variable: s_path in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86 Notice: Undefined variable: o_path in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86 Notice: Undefined variable: upload in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 49 Notice: Undefined variable: upload in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 50 Warning: getimagesize() [function.getimagesize]: Filename cannot be empty in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 52 Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 64 Notice: Undefined variable: image in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 75 Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 75 Warning: imagejpeg(): supplied argument is not a valid Image resource in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 76 The file 166899_162370493852077_100174353405025_346144_1721195732_n.jpg has been uploaded, and your information has been added to the directory 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.