|
Posted by f.amann on 10/13/94 11:39
hi there!
i save images in a mysql db and i wrote a script called getimage.php to
display them.
in my getimage.php i want to resize my images to display them as
thumbnails but there always occurs the following error:
<b>Fatal error</b>: Allowed memory size of 188743680 bytes exhausted
(tried to allocate 240 bytes) in <b>.../public_html/getimage.php</b> on
line <b>x</b><br />
it always tries to allocate either 240 or 60 bytes.
line x equals: $image_p = imagecreatetruecolor($newWidth, $newHeight);
my configuration:
PHP Version 4.3.10
Apache/2.0.49 (Linux/SuSE)
GD Version: bundled (2.0.15 compatible)
memory_limit 180M !!!!!!!!
the machine has 512MB RAM.
I tried it with a jpg:
- the size was 163kb.
- the width was 533px
- the height was 400px
it was not a really big image but it also didn't worked with smaller
ones.
my code:
include "inc/Main.inc";
$Main = new Main();
$Database = new Database();
$Database->SQLStatement = "SELECT ImgData, ImgType, ImgExt, ImgWidth,
ImgHeight FROM ProductPic WHERE ProductId=". $_REQUEST[ pid ];
$Pic = $Database->Query();
$type = $Pic[ 0 ][ ImgType ];
// set headers for image mime type
Header( "Content-type: $type");
// request thumbnail
if ( $_REQUEST[ t ] == "tmb" )
{
$newWidth = 60;
$factor = $newWidth * $Pic[ 0 ][ ImgWidth ];
$newHeight = $factor * $Pic[ 0 ][ ImgHeight ];
// resample
$image_p = imagecreatetruecolor($newWidth, $newHeight);
$image = imagecreatefromstring( $Pic[ 0 ][ ImgData ] );
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $newWidth,
$newHeight, $Pic[ 0 ][ ImgWidth ], $Pic[ 0 ][ ImgHeight ]);
// output
switch ( $Pic[ 0 ][ ImgExt ] )
{
case 1:
imagegif($image_p, null, 75);
break;
case 2:
imagejpeg($image_p, null, 75);
break;
case 3:
imagepng($image_p, null, 75);
break;
}
}
else // request full size image
{
$data = $Pic[ 0 ][ ImgData ];
echo $data;
}
I know this problem if the memory limit is set to 8 MB but what the
hell is the solution here?
the free command on the linux-console returned:
total used free shared buffers
cached
Mem: 508588 122300 386288 0 14572
61948
-/+ buffers/cache: 45780 462808
Swap: 497972 0 497972
kind regards
flo
Navigation:
[Reply to this message]
|