adam291086 Posted September 25, 2007 Share Posted September 25, 2007 sorry about the code, but if i move anything it stops working. I keep getting the error Still here! Fatal error: Call to undefined method: gallerysizer->getthumblocation() in /homepages/12/d214897219/htdocs/adam/create_thumbnails The still here bit is an echo saying this part of the code works. Below are the two connecting files. The method is defined and named properly. I am a novice and have no idea what to do <?php // Define script constants DEFINE("IMAGE_BASE", '/adam/photos/'); DEFINE("THUMB_BASE", '/adam/thumbs/'); DEFINE("MAX_WIDTH", 100); DEFINE("MAX_HEIGHT", 100); DEFINE("RESIZE_WIDTH", 800); DEFINE("RESIZE_HEIGHT", 600); class GallerySizer{ var $img; // Original image file object var $thumb; // Thumbnail file object var $resize; // Resized image file name var $width; // Original image width var $height; // Original image height var $new_width; // Resized image width var $new_height; // Resized image height var $image_path; // Path to image var $thumbscale; // Scale to resize thumbnail var $image_file; // Resized image filename var $thumbnail; // Thumbnail image file object var $random_file; // Resized image file name (random) /***** * Retrieves path to uploaded image. * Retrieves filename of uploaded image */ function getLocation($image){ $this->image_file = str_replace("..", "/", $image); $this->image_path = IMAGE_BASE . $this->image_file; return true; } /***** * Determines image type, and creates an image object */ function loadIMAGE(){ $this->img = null; $extension = strtolower(end(explode('.', $this->image_path))); if ($extension == 'JPG' || $extension == 'JPEG'){ $this->img = imagecreatefromjpeg($this->image_path); } else if ($extension == 'png'){ $this->img = imagecreatefrompng($this->image_path); } else { return true; } // Sets a random name for the image based on the extension type $file_name = strtolower(current(explode('.', $this->image_file))); $this->random_file = $file_name . $this->getRandom() . "." . $extension; $this->thumbnail = $this->random_file; $this->converted = $this->random_file; $this->resize = $this->random_file; return true; } /***** * Retrieves size of original image. Sets the conversion scale for both * the thumbnail and resized image */ function getSize(){ if ($this->img){ $this->width = imagesx($this->img); $this->height = imagesy($this->img); $this->thumbscale = min(MAX_WIDTH / $this->width, MAX_HEIGHT / $this->height); } else { return false; } return true; min(MAX_WIDTH / $this->width, MAX_HEIGHT / $this->height); /***** * Creates a thumbnail image from the original uploaded image */ function setThumbnail(){ // Check if image is larger than max size if ($this->thumbscale < 1){ $this->new_width = floor($this->thumbscale * $this->width); $this->new_height = floor($this->thumbscale * $this->height); // Create temp image $tmp_img = imagecreatetruecolor($this->new_width, $this->new_height); // Copy and resize old image into new imagecopyresampled($tmp_img, $this->img, 0, 0, 0, 0, $this->new_width, $this->new_height, $this->width, $this->height); $this->thumb = $tmp_img; } return true; } $this->new_width = floor($this->thumbscale * $this->width); $this->new_height = floor($this->thumbscale * $this->height); // Create temp image $tmp_img = imagecreatetruecolor($this->new_width, $this->new_height); imagecopyresampled($tmp_img, $this->img, 0, 0, 0, 0, $this->new_width, $this->new_height, $this->width, $this->height); $this->thumb = $tmp_img; /***** * Resizes uploaded image to desired viewing size */ function resizeImage(){ if ($this->width < RESIZE_WIDTH){ $this->resize = $this->img; return true; } else { // Create re-sized image $tmp_resize = imagecreatetruecolor(RESIZE_WIDTH, RESIZE_HEIGHT); // Copy and resize image imagecopyresized($tmp_resize, $this->img, 0, 0, 0, 0, RESIZE_WIDTH, RESIZE_HEIGHT, $this->width, $this->height); imagedestroy($this->img); $this->resize = $tmp_resize; return true; } } $tmp_resize = imagecreatetruecolor(RESIZE_WIDTH, RESIZE_HEIGHT); imagecopyresampled($tmp_resize, $this->img, 0, 0, 0, 0, RESIZE_WIDTH, RESIZE_HEIGHT, $this->width, $this->height); imagedestroy($this->img); $this->resize = $tmp_resize; /***** * Copies thumbnail image to specified thumbnail directory. * Sets permissions on file */ function copyThumbImage(){ imagejpeg($this->thumb, $this->thumbnail); if(!@copy($this->thumbnail, THUMB_BASE . $this->thumbnail)){ echo("Error processing file... Please try again!"); return false; } if(!@chmod($this->thumbnail, 666)){ echo("Error processing file... Please try again!"); return false; } if(!@unlink($this->thumbnail)){ echo("Error processing file... Please try again!"); return false; } return true; } imagejpeg($this->thumb, $this->thumbnail); /***** * Copies the resized image to the specified images directory. * Sets permissions on file. */ function copyResizedImage(){ imagejpeg($this->resize, $this->converted); if(!@copy($this->converted, IMAGE_BASE . $this->converted)){ echo("Error processing file... Please try again!"); return false; } if(!@chmod($this->converted, 666)){ echo("Error processing file... Please try again!"); return false; } if(!unlink($this->converted)){ echo("Error processing file... Please try again!"); return false; } // Delete the original uploaded image if(!unlink(IMAGE_BASE . $this->image_file)){ echo("Error processing file... Please try again!"); return false; } return true; } /***** * Generates a random number. Random number is used to rename * the original uploaded image, once resized. */ function getRandom(){ return "_" . date("dmy_His"); } /***** * Returns path to thumbnail image */ function getThumbLocation(){ return "../adam/thumbs/" . $this->random_file; } /***** * Returns path to resized image */ function getImageLocation(){ return "../adam/photos/" . $this->random_file; } } } ?> <?php include("GallerySizer.php"); include("config.php"); DEFINE("IMAGE_FULL",'../adam/photos/'); // Album cover $cover = $_FILES['image']['name'][$_POST['album_cover']]; if (!$_REQUEST['process']){ echo("Error! No images chosen for processing. <br />"); echo("Click <a href='index.html'>here</a> to start processing your images."); die(); } elseif (!$_POST['album_id']){ echo("No album selected. Please <a href=\"\">choose an album</a> to upload images to."); die(); } else { for($i = 0; $i < count($_FILES['image']['tmp_name']); $i++){ $fileName = $_FILES['image']['name'][$i]; copy($_FILES['image']['tmp_name'][$i], IMAGE_FULL . $fileName); $thumb = new GallerySizer(); if($thumb->getLocation($_FILES['image']['name'][$i])){ if($thumb->loadImage()){ echo("Still here!"); if($thumb->getSize()){ if($thumb->setThumbnail()){ if($thumb->copyImage()){ if($thumb->resizeImage()){ $thumb->copyResize(); $thumb->display(); } } } } } else { echo("Invalid image/file has been uploaded. Please upload a supported file-type (JPEG/PNG)"); unlink(IMAGE_FULL . $fileName); die(); } insert_location($thumb); } else { echo("Error processing images: " . mysql_error()); } // If image matches cover selection, update album cover if($cover == $_FILES['image']['name'][$i]){ $sql = "UPDATE albums SET album_cover = '" . $thumb->getThumbLocation() . "' WHERE album_id = " . $_POST['album_id']; $result = @mysql_query($sql) or die("Error inserting records: " . mysql_error()); } } } function insert_location($thumb_obj){ $image_location=$thumb_obj->getThumbLocation(); $thumb_location=$thumb_obj->getThumbLocation(); $dbcnx = mysql_connect("localhost", "root", ""); mysql_select_db("album", $dbcnx); $sql = "INSERT INTO photos values(0, '$_POST[photo_title]', '$_POST[photo_desc]', NOW(), '$image_location', '$thumb_location', $_POST[album_id])"; $result = mysql_query($sql, $dbcnx) or die("Error inserting record(s) into the database: " . mysql_error()); if ($result){ echo("Images successfully converted and stored! <br />Click <a href='../admin'>here</a> to continue."); } } ?> [\code] Quote Link to comment Share on other sites More sharing options...
Dragen Posted September 25, 2007 Share Posted September 25, 2007 does it say what line the error is on? Quote Link to comment Share on other sites More sharing options...
adam291086 Posted September 25, 2007 Author Share Posted September 25, 2007 its on line 52. Thats line 52 of the second lot of code, where the include("GallerySizer.php"); is written. The gallerysizer code is above it Quote Link to comment Share on other sites More sharing options...
Dragen Posted September 25, 2007 Share Posted September 25, 2007 try changing this: function insert_location($thumb_obj){ $image_location=$thumb_obj->getThumbLocation(); $thumb_location=$thumb_obj->getThumbLocation(); to this: function insert_location(){ global $thumb; $image_location=$thumb->getThumbLocation(); $thumb_location=$thumb->getThumbLocation(); Quote Link to comment Share on other sites More sharing options...
adam291086 Posted September 25, 2007 Author Share Posted September 25, 2007 now i get this message, still the same problem relally Fatal error: Call to undefined method: gallerysizer->getthumblocation() in /homepages/12/d214897219/htdocs/adam/create_thumbnails.php on line 53 Quote Link to comment Share on other sites More sharing options...
Dragen Posted September 25, 2007 Share Posted September 25, 2007 I think it may be because you haven't closed off one of your functions until the end of the file, so in effect you've got functions within function, which I'm not sure work. this function's closing bracket is after all of the following functions: function getSize(){ if ($this->img){ $this->width = imagesx($this->img); $this->height = imagesy($this->img); $this->thumbscale = min(MAX_WIDTH / $this->width, MAX_HEIGHT / $this->height); } else { return false; } return true; min(MAX_WIDTH / $this->width, MAX_HEIGHT / $this->height); } //add this bracket here! so just put a } after it, then go to the bottom of the page and remove the extra bracket.. so from this: } } ?> to this: } ?> Quote Link to comment Share on other sites More sharing options...
adam291086 Posted September 25, 2007 Author Share Posted September 25, 2007 Now i get this error Parse error: parse error, unexpected T_VARIABLE, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /homepages/12/d214897219/htdocs/adam/GallerySizer.php on line 99 Quote Link to comment Share on other sites More sharing options...
Dragen Posted September 25, 2007 Share Posted September 25, 2007 okay.. scrap what I asked you to do a minute ago. I'm not sure how to access a function within a function. It would make more sense to me if function getSize(), was a class containing the other functions, then you could call it up like this: $thumb_obj->getThumbLocation() but have $thumb_obj set as this: $thumb_obj = new getSize; Quote Link to comment Share on other sites More sharing options...
adam291086 Posted September 25, 2007 Author Share Posted September 25, 2007 i am a novice at this and just followed a tutorial, where do you want me to put that code. Sorry to be a pain Quote Link to comment Share on other sites More sharing options...
Dragen Posted September 25, 2007 Share Posted September 25, 2007 I'm not saying that this will definitly work, but it's just an idea. in GallerySizer.php find: function getSize(){ and change to: class getSize extends GallerySizer{ then in the seconf file find: insert_location($thumb); and change to: $thumb_2 = new getSize; insert_location($thumb_2); Quote Link to comment Share on other sites More sharing options...
adam291086 Posted September 25, 2007 Author Share Posted September 25, 2007 i now get the error Parse error: parse error, unexpected T_CLASS, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /homepages/12/d214897219/htdocs/adam/GallerySizer.php on line 67 Quote Link to comment Share on other sites More sharing options...
Dragen Posted September 25, 2007 Share Posted September 25, 2007 just before class getSize extends GallerySizer{ add a } so it looks like this: } class getSize extends GallerySizer{ then at the end of your code where you have this: } } ?> change it to this (as I suggested before): } ?> Quote Link to comment Share on other sites More sharing options...
adam291086 Posted September 25, 2007 Author Share Posted September 25, 2007 New error message. Parse error: parse error, unexpected T_IF, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /homepages/12/d214897219/htdocs/adam/GallerySizer.php on line 69 Quote Link to comment Share on other sites More sharing options...
Dragen Posted September 25, 2007 Share Posted September 25, 2007 oh.. sorry I've been a bit of a fool.. you can't have random vars in a class, it all needs to be inside functions. Quote Link to comment Share on other sites More sharing options...
adam291086 Posted September 25, 2007 Author Share Posted September 25, 2007 Your no fool, this is far above me. So i need to remove all the VAR? Quote Link to comment Share on other sites More sharing options...
Dragen Posted September 25, 2007 Share Posted September 25, 2007 no.. it basically means the changes I've been asking you to make were pointless sorry. and I can't find any references of calling functions that are inside another function.. I didn't think it was possible.. Where did you get the tutorial from? if you link me to it I'll skim through it and try and see if I can find a problem.. Quote Link to comment Share on other sites More sharing options...
adam291086 Posted September 26, 2007 Author Share Posted September 26, 2007 i got the tutorial from http://www.devarticles.com/c/a/MySQL/Creating-An-Online-Photo-Album-with-PHP-and-GD-Part-1/ http://www.devarticles.com/c/a/MySQL/Creating-An-Online-Photo-Album-with-PHP-and-GD-Part-2/ http://www.devarticles.com/c/a/MySQL/Creating-An-Online-Photo-Album-with-PHP-and-GD-Part-3/ http://www.devarticles.com/c/a/MySQL/Creating-An-Online-Photo-Album-with-PHP-and-GD-Part-4/ There are four parts all linked above. Quote Link to comment Share on other sites More sharing options...
Dragen Posted September 26, 2007 Share Posted September 26, 2007 okay.. this is what GallerySizer.php should look like: <?php // Define script constants DEFINE("IMAGE_BASE", '/adam/photos/'); DEFINE("THUMB_BASE", '/adam/thumbs/'); DEFINE("MAX_WIDTH", 100); DEFINE("MAX_HEIGHT", 100); DEFINE("RESIZE_WIDTH", 800); DEFINE("RESIZE_HEIGHT", 600); class GallerySizer{ var $img; // Original image file object var $thumb; // Thumbnail file object var $resize; // Resized image file name var $width; // Original image width var $height; // Original image height var $new_width; // Resized image width var $new_height; // Resized image height var $image_path; // Path to image var $thumbscale; // Scale to resize thumbnail var $image_file; // Resized image filename var $thumbnail; // Thumbnail image file object var $random_file; // Resized image file name (random) /***** * Retrieves path to uploaded image. * Retrieves filename of uploaded image */ function getLocation($image){ $this->image_file = str_replace("..", "/", $image); $this->image_path = IMAGE_BASE . $this->image_file; return true; } /***** * Determines image type, and creates an image object */ function loadIMAGE(){ $this->img = null; $extension = strtolower(end(explode('.', $this->image_path))); if ($extension == 'JPG' || $extension == 'JPEG'){ $this->img = imagecreatefromjpeg($this->image_path); } else if ($extension == 'png'){ $this->img = imagecreatefrompng($this->image_path); } else { return true; } // Sets a random name for the image based on the extension type $file_name = strtolower(current(explode('.', $this->image_file))); $this->random_file = $file_name . $this->getRandom() . "." . $extension; $this->thumbnail = $this->random_file; $this->converted = $this->random_file; $this->resize = $this->random_file; return true; } /***** * Retrieves size of original image. Sets the conversion scale for both * the thumbnail and resized image */ function getSize(){ if ($this->img){ $this->width = imagesx($this->img); $this->height = imagesy($this->img); $this->thumbscale = min(MAX_WIDTH / $this->width, MAX_HEIGHT / $this->height); } else { return false; } return true; } min(MAX_WIDTH / $this->width, MAX_HEIGHT / $this->height); /***** * Creates a thumbnail image from the original uploaded image */ function setThumbnail(){ // Check if image is larger than max size if ($this->thumbscale < 1){ $this->new_width = floor($this->thumbscale * $this->width); $this->new_height = floor($this->thumbscale * $this->height); // Create temp image $tmp_img = imagecreatetruecolor($this->new_width, $this->new_height); // Copy and resize old image into new imagecopyresampled($tmp_img, $this->img, 0, 0, 0, 0, $this->new_width, $this->new_height, $this->width, $this->height); $this->thumb = $tmp_img; } return true; } $this->new_width = floor($this->thumbscale * $this->width); $this->new_height = floor($this->thumbscale * $this->height); // Create temp image $tmp_img = imagecreatetruecolor($this->new_width, $this->new_height); imagecopyresampled($tmp_img, $this->img, 0, 0, 0, 0, $this->new_width, $this->new_height, $this->width, $this->height); $this->thumb = $tmp_img; /***** * Resizes uploaded image to desired viewing size */ function resizeImage(){ if ($this->width < RESIZE_WIDTH){ $this->resize = $this->img; return true; } else { // Create re-sized image $tmp_resize = imagecreatetruecolor(RESIZE_WIDTH, RESIZE_HEIGHT); // Copy and resize image imagecopyresized($tmp_resize, $this->img, 0, 0, 0, 0, RESIZE_WIDTH, RESIZE_HEIGHT, $this->width, $this->height); imagedestroy($this->img); $this->resize = $tmp_resize; return true; } } $tmp_resize = imagecreatetruecolor(RESIZE_WIDTH, RESIZE_HEIGHT); imagecopyresampled($tmp_resize, $this->img, 0, 0, 0, 0, RESIZE_WIDTH, RESIZE_HEIGHT, $this->width, $this->height); imagedestroy($this->img); $this->resize = $tmp_resize; /***** * Copies thumbnail image to specified thumbnail directory. * Sets permissions on file */ function copyThumbImage(){ imagejpeg($this->thumb, $this->thumbnail); if(!@copy($this->thumbnail, THUMB_BASE . $this->thumbnail)){ echo("Error processing file... Please try again!"); return false; } if(!@chmod($this->thumbnail, 666)){ echo("Error processing file... Please try again!"); return false; } if(!@unlink($this->thumbnail)){ echo("Error processing file... Please try again!"); return false; } return true; } imagejpeg($this->thumb, $this->thumbnail); /***** * Copies the resized image to the specified images directory. * Sets permissions on file. */ function copyResizedImage(){ imagejpeg($this->resize, $this->converted); if(!@copy($this->converted, IMAGE_BASE . $this->converted)){ echo("Error processing file... Please try again!"); return false; } if(!@chmod($this->converted, 666)){ echo("Error processing file... Please try again!"); return false; } if(!unlink($this->converted)){ echo("Error processing file... Please try again!"); return false; } // Delete the original uploaded image if(!unlink(IMAGE_BASE . $this->image_file)){ echo("Error processing file... Please try again!"); return false; } return true; } /***** * Generates a random number. Random number is used to rename * the original uploaded image, once resized. */ function getRandom(){ return "_" . date("dmy_His"); } /***** * Returns path to thumbnail image */ function getThumbLocation(){ return "thumbs/" . $this->random_file; } /***** * Returns path to resized image */ function getImageLocation(){ return "photos/" . $this->random_file; } ?> The other file looked fine to me. Hopefully that will solve your problems.. If not, I'd suggest contacting the author of the tutorial: Frank Manno Quote Link to comment Share on other sites More sharing options...
adam291086 Posted September 26, 2007 Author Share Posted September 26, 2007 hey thanks for the help. Still not going right. I have tried contacting the creator but he isn't replying. I now get the error Parse error: parse error, unexpected $ in /homepages/12/d214897219/htdocs/adam/create_thumbnails.php on line 64 and have no idea what it means, there is no $ on line 64. This is the code for the page i am having problems with <?php include("GallerySizer.php"); include("config.php"); DEFINE("IMAGE_FULL",'../adam/photos/'); // Album cover $cover = $_FILES['image']['name'][$_POST['album_cover']]; if (!$_REQUEST['process']){ echo("Error! No images chosen for processing. <br />"); echo("Click <a href='index.html'>here</a> to start processing your images."); die(); } elseif (!$_POST['album_id']){ echo("No album selected. Please <a href=\"\">choose an album</a> to upload images to."); die(); } else { for($i = 0; $i < count($_FILES['image']['tmp_name']); $i++){ $fileName = $_FILES['image']['name'][$i]; copy($_FILES['image']['tmp_name'][$i], IMAGE_FULL . $fileName); $thumb = new GallerySizer(); if($thumb->getLocation($_FILES['image']['name'][$i])){ if($thumb->loadImage()){ echo("Still here!"); if($thumb->getSize()){ if($thumb->setThumbnail()){ if($thumb->copyImage()){ if($thumb->resizeImage()){ $thumb->copyResize(); $thumb->display(); } } } } } else { echo("Invalid image/file has been uploaded. Please upload a supported file-type (JPEG/PNG)"); unlink(IMAGE_FULL . $fileName); die(); } insert_location($thumb); } else { echo("Error processing images: " . mysql_error()); } // If image matches cover selection, update album cover if($cover == $_FILES['image']['name'][$i]){ $sql = "UPDATE albums SET album_cover = '" . $thumb->getThumbLocation() . "' WHERE album_id = " . $_POST['album_id']; $result = @mysql_query($sql) or die("Error inserting records: " . mysql_error()); } } } function insert_location(){ global $thumb; $image_location=$thumb->getThumbLocation(); $thumb_location=$thumb->getThumbLocation(); $thumb_location=$thumb_obj->getThumbLocation(); $dbcnx = mysql_connect("localhost", "root", ""); mysql_select_db("album", $dbcnx); $sql = "INSERT INTO photos values(0, '$_POST[photo_title]', '$_POST[photo_desc]', NOW(), '$image_location', '$thumb_location', $_POST[album_id])"; $result = mysql_query($sql, $dbcnx) or die("Error inserting record(s) into the database: " . mysql_error()); if ($result){ echo("Images successfully converted and stored! <br />Click <a href='../admin'>here</a> to continue."); } ?> Quote Link to comment Share on other sites More sharing options...
Dragen Posted September 26, 2007 Share Posted September 26, 2007 there is no line 64... You'd missed out the closing bracket on the last function. I've indented your code for you so it's easier to read, and added the bracket. It should hopefully work now! <?php include("GallerySizer.php"); include("config.php"); DEFINE("IMAGE_FULL",'../adam/photos/'); // Album cover $cover = $_FILES['image']['name'][$_POST['album_cover']]; if(!$_REQUEST['process']){ echo("Error! No images chosen for processing. <br />"); echo("Click <a href='index.html'>here</a> to start processing your images."); die(); }elseif(!$_POST['album_id']){ echo("No album selected. Please <a href=\"\">choose an album</a> to upload images to."); die(); }else{ for($i = 0; $i < count($_FILES['image']['tmp_name']); $i++){ $fileName = $_FILES['image']['name'][$i]; copy($_FILES['image']['tmp_name'][$i], IMAGE_FULL . $fileName); $thumb = new GallerySizer(); if($thumb->getLocation($_FILES['image']['name'][$i])){ if($thumb->loadImage()){ echo("Still here!"); if($thumb->getSize()){ if($thumb->setThumbnail()){ if($thumb->copyImage()){ if($thumb->resizeImage()){ $thumb->copyResize(); $thumb->display(); } } } } }else{ echo("Invalid image/file has been uploaded. Please upload a supported file-type (JPEG/PNG)"); unlink(IMAGE_FULL . $fileName); die(); } insert_location($thumb); }else{ echo("Error processing images: " . mysql_error()); } // If image matches cover selection, update album cover if($cover == $_FILES['image']['name'][$i]){ $sql = "UPDATE albums SET album_cover = '" . $thumb->getThumbLocation() . "' WHERE album_id = " . $_POST['album_id']; $result = @mysql_query($sql) or die("Error inserting records: " . mysql_error()); } } } function insert_location(){ global $thumb; $image_location=$thumb->getThumbLocation(); $thumb_location=$thumb->getThumbLocation(); $thumb_location=$thumb_obj->getThumbLocation(); $dbcnx = mysql_connect("localhost", "root", ""); mysql_select_db("album", $dbcnx); $sql = "INSERT INTO photos values(0, '$_POST[photo_title]', '$_POST[photo_desc]', NOW(), '$image_location', '$thumb_location', $_POST[album_id])"; $result = mysql_query($sql, $dbcnx) or die("Error inserting record(s) into the database: " . mysql_error()); if ($result){ echo("Images successfully converted and stored! <br />Click <a href='../admin'>here</a> to continue."); } } ?> Quote Link to comment Share on other sites More sharing options...
adam291086 Posted September 26, 2007 Author Share Posted September 26, 2007 I wish this would bloody work. Now getting the error Parse error: parse error, unexpected $ in /homepages/12/d214897219/htdocs/adam/GallerySizer.php on line 64 Quote Link to comment Share on other sites More sharing options...
Dragen Posted September 26, 2007 Share Posted September 26, 2007 what's on the line with the error on? Quote Link to comment Share on other sites More sharing options...
adam291086 Posted September 26, 2007 Author Share Posted September 26, 2007 Scrap that last post, i made a mistake. I now get this error. I wish this would just work. Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /homepages/12/d214897219/htdocs/adam/GallerySizer.php on line 79 that using your galleysizer code Quote Link to comment Share on other sites More sharing options...
Dragen Posted September 26, 2007 Share Posted September 26, 2007 heh.. It's not the clearest tutorial in the world and I basically copied and pasted it from the pages, but half of it was going over the same stuff, so that explains the errors. I've just gone through it and think I've weeded them all out now! <?php // Define script constants DEFINE("IMAGE_BASE", '/adam/photos/'); DEFINE("THUMB_BASE", '/adam/thumbs/'); DEFINE("MAX_WIDTH", 100); DEFINE("MAX_HEIGHT", 100); DEFINE("RESIZE_WIDTH", 800); DEFINE("RESIZE_HEIGHT", 600); class GallerySizer{ var $img; // Original image file object var $thumb; // Thumbnail file object var $resize; // Resized image file name var $width; // Original image width var $height; // Original image height var $new_width; // Resized image width var $new_height; // Resized image height var $image_path; // Path to image var $thumbscale; // Scale to resize thumbnail var $image_file; // Resized image filename var $thumbnail; // Thumbnail image file object var $random_file; // Resized image file name (random) /***** * Retrieves path to uploaded image. * Retrieves filename of uploaded image */ function getLocation($image){ $this->image_file = str_replace("..", "/", $image); $this->image_path = IMAGE_BASE . $this->image_file; return true; } /***** * Determines image type, and creates an image object */ function loadIMAGE(){ $this->img = null; $extension = strtolower(end(explode('.', $this->image_path))); if ($extension == 'JPG' || $extension == 'JPEG'){ $this->img = imagecreatefromjpeg($this->image_path); } else if ($extension == 'png'){ $this->img = imagecreatefrompng($this->image_path); } else { return true; } // Sets a random name for the image based on the extension type $file_name = strtolower(current(explode('.', $this->image_file))); $this->random_file = $file_name . $this->getRandom() . "." . $extension; $this->thumbnail = $this->random_file; $this->converted = $this->random_file; $this->resize = $this->random_file; return true; } /***** * Retrieves size of original image. Sets the conversion scale for both * the thumbnail and resized image */ function getSize(){ if ($this->img){ $this->width = imagesx($this->img); $this->height = imagesy($this->img); $this->thumbscale = min(MAX_WIDTH / $this->width, MAX_HEIGHT / $this->height); } else { return false; } return true; } /***** * Creates a thumbnail image from the original uploaded image */ function setThumbnail(){ // Check if image is larger than max size if ($this->thumbscale < 1){ $this->new_width = floor($this->thumbscale * $this->width); $this->new_height = floor($this->thumbscale * $this->height); // Create temp image $tmp_img = imagecreatetruecolor($this->new_width, $this->new_height); // Copy and resize old image into new imagecopyresampled($tmp_img, $this->img, 0, 0, 0, 0, $this->new_width, $this->new_height, $this->width, $this->height); $this->thumb = $tmp_img; } return true; } /***** * Resizes uploaded image to desired viewing size */ function resizeImage(){ if ($this->width < RESIZE_WIDTH){ $this->resize = $this->img; return true; } else { // Create re-sized image $tmp_resize = imagecreatetruecolor(RESIZE_WIDTH, RESIZE_HEIGHT); // Copy and resize image imagecopyresized($tmp_resize, $this->img, 0, 0, 0, 0, RESIZE_WIDTH, RESIZE_HEIGHT, $this->width, $this->height); imagedestroy($this->img); $this->resize = $tmp_resize; return true; } } /***** * Copies thumbnail image to specified thumbnail directory. * Sets permissions on file */ function copyThumbImage(){ imagejpeg($this->thumb, $this->thumbnail); if(!@copy($this->thumbnail, THUMB_BASE . $this->thumbnail)){ echo("Error processing file... Please try again!"); return false; } if(!@chmod($this->thumbnail, 666)){ echo("Error processing file... Please try again!"); return false; } if(!@unlink($this->thumbnail)){ echo("Error processing file... Please try again!"); return false; } return true; } /***** * Copies the resized image to the specified images directory. * Sets permissions on file. */ function copyResizedImage(){ imagejpeg($this->resize, $this->converted); if(!@copy($this->converted, IMAGE_BASE . $this->converted)){ echo("Error processing file... Please try again!"); return false; } if(!@chmod($this->converted, 666)){ echo("Error processing file... Please try again!"); return false; } if(!unlink($this->converted)){ echo("Error processing file... Please try again!"); return false; } // Delete the original uploaded image if(!unlink(IMAGE_BASE . $this->image_file)){ echo("Error processing file... Please try again!"); return false; } return true; } /***** * Generates a random number. Random number is used to rename * the original uploaded image, once resized. */ function getRandom(){ return "_" . date("dmy_His"); } /***** * Returns path to thumbnail image */ function getThumbLocation(){ return "thumbs/" . $this->random_file; } /***** * Returns path to resized image */ function getImageLocation(){ return "photos/" . $this->random_file; } ?> Quote Link to comment Share on other sites More sharing options...
adam291086 Posted September 26, 2007 Author Share Posted September 26, 2007 Get this error now. Parse error: parse error, unexpected ';', expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /homepages/12/d214897219/htdocs/adam/GallerySizer.php on line 186 This is turning to be a pain in the arse, do you know any other tutorials that will do a similar thing. 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.