Jump to content

Archived

This topic is now archived and is closed to further replies.

spyke01

Auto thumnailer problems

Recommended Posts

I need to create 2 different sized thumbnails automaticly from an image being uploaded, the databas insertion works fine, but after the first image is uploaded, the other two never get made. I only get a dialog box saying that the script on the page is taking too long to execute and asks if i want to stop it or continue.

I added echo statements in but the script wont print past some basic html for the menus

page:
[code]
<?php


include "includes/header.php";



//=====================================================

// If the user is not logged in redirect them

//=====================================================

if (!isset($_SESSION[user_level])) {

// User is not allowed in the admin section, kick them out

echo "\n You do not have sufficient access rights to access this section, or you are not logged in. You are being redirected to the login page.<br />";

echo "\n If you are not redirected automaticly, please click <a href=\"$menuvar[LOGIN]\">here</a>.<br />";

echo "\n <meta http-equiv='refresh' content='1;url=$menuvar[LOGIN]'>";

}

//=====================================================

// If the user is an employee the print the page

//=====================================================

else {

if ($_SESSION[user_level] != ADMIN && $_SESSION[user_level] != EDITORS && $_SESSION[user_level] != STREET_TEAM) {

echo "\n You do not have sufficient access rights, please contact an administrator.";

}

else {

//========================================================

// Upload the photo

//========================================================

if(isset($_POST[submit])){



$typeOfFile = $_FILES['large_pic']['type'];

$fileName = $_FILES['large_pic']['name'];

$fileExt = strtolower(substr($fileName,strrpos($fileName,".")));

$fileName = str_replace("\\","",$fileName);

$fileName = str_replace("'","",$fileName);

$randName = md5(rand() * time()); // make a random filename



$largefilename = "../assets/galleries2/maroonweeklystreetteam/" . $randName . $fileExt;



// Upload the full sixed image

move_uploaded_file($_FILES['large_pic']['tmp_name'], "../assets/galleries2/maroonweeklystreetteam/" . $randName . $fileExt);





// Get the image size so we can calculate the new size

list($width, $height) = getimagesize("../assets/galleries2/maroonweeklystreetteam/" . $randName . $fileExt);



if ($width < $height) {

// Get what the next ID will be - not pretty but i dont feel like fixing it

$sql = "SELECT ID FROM galleryimages ORDER BY ID DESC LIMIT 1";

$result = mysql_query($sql) or die(mysql_error());



if ($row = mysql_fetch_array($result)) {

$last_id = $row['ID'] + 1;

}

mysql_free_result($result);


// Insert the caption and image into the DB

$sql = "INSERT INTO `galleryimages` (ID, filename, memberof, caption, numinorder, height, width, owner) VALUES('$last_id', 'assets/galleries2/maroonweeklystreetteam/". $randName . $fileExt . "', '0', '$_POST[caption]', '$last_id', '0', '540', '0')";

$result = mysql_query($sql) or die(mysql_error());



// Our files

$mediumfilename = "assets/galleries2/maroonweeklystreetteam/" . $randName . "_mid." . $fileExt;

$smallfilename = "assets/galleries2/maroonweeklystreetteam/" . $randName . "_thumb." . $fileExt;



// Create the Medium sized pic - Height is more important than width to us

$tosubtract = $height - 380; // This tells what to subtract the current hieght and width by to get 380

$newwidth = $width - $tosubtract;

$newheight = $tosubtract;



createthumb($largefilename, $mediumfilename, $width, $height, $newwidth, $newheight);



// Create the Thumbnail - Height is more important than width to us

$tosubtract = $height - 159; // This tells what to subtract the current hieght and width by to get 159

$newwidth = $width - $tosubtract;

$newheight = $tosubtract;



createthumb($largefilename, $smallfilename, $width, $height, $newwidth, $newheight);

}

else {

echo "\n <center>";

echo "\n The height of your image should be larger than the width. Please crop the image and try again";

echo "\n </center>";

echo "\n <br />";

echo "\n <br />";

}

unset($_POST[submit]);

}



//========================================================

// Print our form

//========================================================

echo "\n <center>";

echo "\n <form method=\"POST\" action=\"$menuvar[STREETTEAM]\" enctype=\"multipart/form-data\">";

echo "\n <table class='TableBorder' border='0' cellpadding='0' cellspacing='1' style=\"width: 400px;\">";

echo "\n <tr>";

echo "\n <td colspan=\"2\" class=\"title1\">Add Street Team Photo</td>";

echo "\n </tr>";

echo "\n <tr>";

echo "\n <td colspan=\"2\" class=\"title2\">Please only upload JPG images with a height larger than their width.</td>";

echo "\n </tr>";

echo "\n <tr>";

echo "\n <td class=\"row2\">Caption</td><td class=\"row1\"><input name=\"caption\" type=\"text\" size=\"30\" /></td>";

echo "\n </tr>";

echo "\n <tr>";

echo "\n <td class=\"row2\">Picture</td><td class=\"row1\"><input type=\"file\" name=\"large_pic\" /></td>";

echo "\n </tr>";

echo "\n </table>";

echo "\n <br />";

echo "\n <input type=\"submit\" name=\"submit\" class=\"button\" value=\"Add It!\" />";

echo "\n </form>";

echo "\n </center>";

}

}



include "includes/footer.php";

?>
[/code]

function:
[code]
//============================================

// This function is designed to create a

// thumbnail from the given image.

//

// ORIGINALLY FROM:

// http://icant.co.uk/articles/phpthumbnails/

// Modified for use here

//

// USAGE:

// createthumb($p, "tn_".$p, 150, 150);

//

// OPTIONS:

// $name Original filename

// $filename Filename of the resized image

// $new_w width of resized image

// $new_h height of resized image

//============================================

function createthumb($name, $filename, $old_w, $old_h, $new_w, $new_h) {

echo "$name, $filename, $old_w, $old_h, $new_w, $new_h<br />";


$system=explode(".",$name);

print_r($system);


if (preg_match("/jpg|jpeg/", $system[3])){$src_img = imagecreatefromjpeg($name);}

if (preg_match("/png/", $system[3])){$src_img = imagecreatefrompng($name);}



$dst_img = ImageCreateTrueColor($new_w, $new_h);



if (imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, $old_x, $old_y)) { echo "made copyresampled<br />"; }

else { echo "didnt make copyresampled<br />"; }


if (preg_match("/png/", $system[3])) {

imagepng($dst_img, "../" . $filename);

}



else {

imagejpeg($dst_img, "../" . $filename);

}



imagedestroy($dst_img);

imagedestroy($src_img);

}
[/code]

Share this post


Link to post
Share on other sites
Im not advanced at php but you should set the thumbnail image height and width (make it smaller ). Then set the default height and width when you want to view the image. Hope this helps.

Share this post


Link to post
Share on other sites
that would still be one image, the large one, i need to actually create the smaller ones for a shorter load time

Share this post


Link to post
Share on other sites

×

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.