Hi everybody,
I'm writting a script which take image data from mysql (blob) and draw
the image to screen.
At the end of the message you will find my php code. I put lots of
numbered message about the memory usage.
The image in the database is about 520ko.
Here is the output in my browser :
-1 - 34816
0 - 123672
0bis - 652064
1 - 6693928
2 - 6693928
3 - 8957256
4 - 8957336
What I see is just before the use of the function imagecreatefrom string,
the script is using about 650ko, and just after about 6,5Mo !
I do not understand why it is using so much memory for just a 'little'
picture.
I'm using redhat fedora 1 linux distribution.
php-4.3.3
httpd-2.0.47
gd-2.0.15
Is someone understand my problem ?
Thanks
Matthieu MARC
------ PHP CODE -----
<?php
echo "-1 - ".memory_get_us age() . "\n<br>";
include_once("i nclude/include.php");
$photo_id = $_POST['id'];
if ( $photo_id == '' ){
$photo_id = $_GET['id'];
}
echo "0 - ".memory_get_us age() . "\n<br>";
$photo_data = db_getphotodata fromid(session_ getuser(),$phot o_id);
if ( $photo_data != NULL ){
# header("Content-Type: ".$photo_da ta['type']);
$size = 600;
echo "0bis - ".memory_get_us age() . "\n<br>";
$src = imagecreatefrom string($photo_d ata['data']);
unset($photo_da ta);
echo "1 - ".memory_get_us age() . "\n<br>";
$width = imagesx($src);
$height = imagesy($src);
$aspect_ratio = $height/$width;
if ($height <= $size) {
$new_w = $width;
$new_h = $height;
} else {
$new_h = $size;
$new_w = abs($new_h / $aspect_ratio);
}
echo "2 - ".memory_get_us age() . "\n<br>";
$img = imagecreatetrue color ($new_w,$new_h) ;
echo "3 - ".memory_get_us age() . "\n<br>";
imagecopyresamp led
($img,$src,0,0, 0,0,$new_w,$new _h,$width,$heig ht);
echo "4 - ".memory_get_us age() . "\n<br>";
imagejpeg($img, '', 90);
echo "5 - ".memory_get_us age() . "\n<br>";
imagedestroy($i mg);
} else {
header ("Content-Type: text/html");
print ("no photo found");
}
?>
------ END PHP CODE ------
Comment