Forum Moderators: coopster

Message Too Old, No Replies

Trouble resizing user submitted image

can anyone enlighten me to what this error means please

         

Smad

2:09 pm on Nov 24, 2003 (gmt 0)

10+ Year Member



Fatal error: Allowed memory size of 8388608 bytes exhausted at (null):0 (tried to allocate 6400 bytes) in /home/fhlinux195/t/mydomain.co.uk/user/htdocs/php/cj/submit_car.php on line 48

I am basically trying to reduce the image stored in $_FILES['picture']['tmp_name'] and then send it to my destination dir.. but i get this error..

TIA for any help.

DrDoc

5:02 pm on Nov 24, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld!
Basically, you have about 8Mb of memory to work with... How big is the image?

Smad

5:52 pm on Nov 24, 2003 (gmt 0)

10+ Year Member



jatar_k

the image is a 300k jpeg...the script will take smaller fine and resize one for a thumbnail, but if the image is bigger like 300k it gives that error..

i have read various posts about this to no avail, but unless when i resize the image it uncompresses it i dont understand how it burns 8m like that...

Distel

6:06 pm on Nov 24, 2003 (gmt 0)

10+ Year Member



Looks like your script might be looping somewhere. It seems to try to allocate 6400 bytes per iteration, and fails when it reaches the maximum total limit of 8 Mb.

Smad

6:13 pm on Nov 24, 2003 (gmt 0)

10+ Year Member



<?php
include_once('db.php');
//connect to db
$conn = db_connect();
//capture form vars
$model = $HTTP_POST_VARS['model'];
$price = $HTTP_POST_VARS['price'];
$description = $HTTP_POST_VARS['description'];
$year = $HTTP_POST_VARS['year'];
$imagetype = $HTTP_POST_FILES['picture']['type'];
$imagesize = $HTTP_POST_FILES['picture']['size'];
$imagetemp = $_FILES['picture']['tmp_name'];
//$filename = $HTTP_POST_FILES['picture'] ['name'];

//check for jpeg
if ($imagetype!= 'image/pjpeg') {
echo 'Only jpegs are accepted, please use your back button and retry';
exit;
}
//check size
if ($imagesize > 1000000) {
echo 'File size exceeds limit, please use your back button and retry';
exit;
}
else {
$filename = "".uniqid(I).".jpg";
$upfiledir = 'uploads/' .$filename;
$thumb = "thumbs/$filename";
move_uploaded_file($imagetemp, $upfiledir);
}
if (isset($HTTP_POST_VARS['model']) && $HTTP_POST_VARS['model']!='')

$sql = "insert into cars
(model, description, price, year, picture, thumb)
values
('$model', '$description', '$price', '$year', '$upfiledir','$thumb')";

$result = mysql_query($sql, $conn);

if (!$result) {
print "There was a database error when executing <pre>$sql</pre>";
print mysql_error();
exit;
}
/*
if (move_uploaded_file($imagetemp, $upfiledir)) {
$msg = "File is successfully uploaded.";

}
else {
$msg = "File is not successfully uploaded.";
//print_r($_FILES);
} */
// show what was uploaded
print ("$msg<br />\n");
print ( "This is the picture file, $filename, you have uploaded:<br />");
print ( "<img src=\"$upfiledir\" border=\"0\"><br /><br />");

// create thumbnail image
$sourcefile = "$upfiledir";
if (!$max_width)
$max_width = 80;
if (!$max_height)
$max_height = 60;

$targetfile = "$thumb";
$jpegqual = 75;
/* Get the dimensions of the source picture */
$size=getimagesize("$sourcefile");
$width = $size[0];
$height = $size[1];
$source_id = imageCreatefromjpeg("$sourcefile");

$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;

if ( ($width <= $max_width) && ($height <= $max_height) ) {
$tn_width = $width;
$tn_height = $height;
}
else if (($x_ratio * $height) < $max_height) {
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
}
else {
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}
/* Create a new image object (not neccessarily true colour) */
$target_id=imagecreatetruecolor($tn_width,$tn_height);
$target_pic=imagecopyresampled
($target_id,$source_id,0,0,0,0,$tn_width,$tn_height,$width,$height);
imagejpeg ($target_id,"$targetfile",$jpegqual);
//display thumbnail
print ( "This is the thumbnail file:<br />");
print ( "<img src=\"$thumb\" border=\"0\">");

This is my script..only been doing php a few weeks now so any tips are soooo welcome..

Thanks

Distel

6:32 pm on Nov 24, 2003 (gmt 0)

10+ Year Member



At first glance, I don't see anything that might be causing this error. Then again, you seem to be using some functions you defined somewhere else (in dp.php apparently). The error may be in any of those.

Smad

7:00 pm on Nov 24, 2003 (gmt 0)

10+ Year Member



distel

db.php is only my db_connect command nothing else there..

Distel

7:18 pm on Nov 24, 2003 (gmt 0)

10+ Year Member



Yeah, those functions I referred to seem to be standard functions. My bad (I never work with those dynamic image things). I'll keep looking.

Smad

7:38 pm on Nov 24, 2003 (gmt 0)

10+ Year Member



the line the original error refers to has been removed but the error seems to indicate imagecreatefromjpeg() is to blame but only if image is say 250k+.

smaller images work fine.. if thats any help.

Distel

7:45 pm on Nov 24, 2003 (gmt 0)

10+ Year Member



Seems like it might be a memory-limit thing:

[devnetwork.net...]

and

www.fuitadnet.com/forums/showthread.php?s=&threadid=782

There's more to be found if you enter "imagecreatefromjpeg Allowed memory size" in Google.

[edited by: jatar_k at 8:25 pm (utc) on Nov. 24, 2003]
[edit reason] delinked [/edit]

Smad

7:52 pm on Nov 24, 2003 (gmt 0)

10+ Year Member



Thanks Distel that seemed to answer the question.

Just need to think of a work around if one exists.