Alecos
Newbie

Posts: 9
|
 |
« on: February 14, 2007, 06:22:10 am » |
|
Hello! I have a digital camera (5.1 MPixel) and I'd like to put my photos into my web site but the script thumb.php doesn't show images bigger than 1280x1024 and so resufes to resize an image 1600x1200 for example... I use the script as follow into my web blog using a regex: $body = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.+?)\[\/img\]/", '<A HREF="$3" TARGET="_blank"><IMG SRC="http://www.alecos.it/set/thumb.php?src=$3&x=$1&y=$2&f=0"></A>', $body);
How to fix this bug? -- Kind Regards -- Alessandro Marinuzzi [Alecos]
|
|
|
|
|
Logged
|
|
|
|
|
zubrag
|
 |
« Reply #1 on: February 15, 2007, 05:42:23 am » |
|
Alessandro, I tried it with 2816x2112 (6 Mpixel, 2.8 Mb size) image, and it resized ok. I tested on jpeg image. Are you resizing jpeg image?
Does it show some error? Some hostings limit memory available for php scripts in php ini file. I'm not sure, but this could be the reason. memory_limit = 2M; Maximum amount of memory a script may consume
What GD version you have? Mine is 2.0.28 compatible
You can do following to get GD version. - create phpinfo.php file, and put following code inside: <?php phpinfo(); ?> - save it on server, and open in browser. It will show php information. - find GD section. There should be GD Version line
|
|
|
|
|
Logged
|
|
|
|
Alecos
Newbie

Posts: 9
|
 |
« Reply #2 on: February 15, 2007, 08:53:50 am » |
|
GD Support enabled GD Version bundled ( 2.0.28 compatible) FreeType Support enabled FreeType Linkage with freetype T1Lib Support enabled GIF Read Support enabled GIF Create Support enabled JPG Support enabled PNG Support enabled WBMP Support enabled XBM Support enabled May be that the problem is really memory_limit = 2M; Thanks for your help 
|
|
|
|
|
Logged
|
|
|
|
Alecos
Newbie

Posts: 9
|
 |
« Reply #3 on: February 15, 2007, 08:59:30 am » |
|
Alessandro, I tried it with 2816x2112 (6 Mpixel, 2.8 Mb size) image, and it resized ok. I tested on jpeg image. Are you resizing jpeg image?
Does it show some error? Some hostings limit memory available for php scripts in php ini file. I'm not sure, but this could be the reason. memory_limit = 2M; Maximum amount of memory a script may consume
What GD version you have? Mine is 2.0.28 compatible
You can do following to get GD version. - create phpinfo.php file, and put following code inside: <?php phpinfo(); ?> - save it on server, and open in browser. It will show php information. - find GD section. There should be GD Version line
memory_limit = 12M; you can see at: http://www.alecos.it/set/info.phphummm... seem to be a strange case...
|
|
|
|
|
Logged
|
|
|
|
|
|
Alecos
Newbie

Posts: 9
|
 |
« Reply #5 on: February 15, 2007, 11:02:10 am » |
|
Alessandro, I tried it with 2816x2112 (6 Mpixel, 2.8 Mb size) image, and it resized ok. I tested on jpeg image. Are you resizing jpeg image?
Does it show some error? Some hostings limit memory available for php scripts in php ini file. I'm not sure, but this could be the reason. memory_limit = 2M; Maximum amount of memory a script may consume
What GD version you have? Mine is 2.0.28 compatible
You can do following to get GD version. - create phpinfo.php file, and put following code inside: <?php phpinfo(); ?> - save it on server, and open in browser. It will show php information. - find GD section. There should be GD Version line
I solved the problem putting in top of the script: <?php ini_set('memory_limit', '30M');
Can you write the script in order to get the correct memory_limit from image in order to set the exact memory usage? -- Alessandro Marinuzzi [Alecos]
|
|
|
|
|
Logged
|
|
|
|
|
zubrag
|
 |
« Reply #6 on: February 15, 2007, 11:15:47 am » |
|
Great you resolved it!
I'm not sure if there is a way for php script to calculate correct memory_limit from image in order to set the exact memory usage. Image manipulations are done by GD2 library, and I assume it "unpacks" image before resizing, thus even GD2 may not know the memory needed before image is unpacked. But I'll think on what could be done here. Anyway thanks for sharing the solution!
BTW: you seem to resize image using URL as src. I would suggest to change it to local server names instead, should work faster. URL was added to support images located on other servers.
For example you have: http://www.alecos.it/set/thumb.php?src=http://www.alecos.it/files/Natale.jpg&x=300&y=300&f=0
Instead you could save thumb.php in the files/ folder, and run it like this: http://www.alecos.it/set/thumb.php?src=Natale.jpg&x=300&y=300&f=0
You could also set $save_to_file setting to false in the thumb.php and omit &f=0 parameter: http://www.alecos.it/files/thumb.php?src=Natale.jpg&x=300&y=300
|
|
|
|
|
Logged
|
|
|
|
Alecos
Newbie

Posts: 9
|
 |
« Reply #7 on: February 15, 2007, 11:46:29 am » |
|
|
|
|
|
|
Logged
|
|
|
|
|
zubrag
|
 |
« Reply #8 on: February 15, 2007, 12:12:00 pm » |
|
Thank you for help  I'll add that code.
|
|
|
|
|
Logged
|
|
|
|
Alecos
Newbie

Posts: 9
|
 |
« Reply #9 on: February 18, 2007, 08:29:22 am » |
|
this is the code fixed for inclusion into your script  <?php function setMemoryForImage($filename) { $imageInfo = getimagesize($filename); $MB = 1048576; $K64 = 65536; $TWEAKFACTOR = 1.5; $memoryNeeded = round(($imageInfo[0] * $imageInfo[1] * $imageInfo['bits'] * $imageInfo['channels'] / 8 + $K64) * $TWEAKFACTOR); $memoryLimitMB = 8; $memoryLimit = $memoryLimitMB * $MB; if (function_exists('memory_get_usage') && memory_get_usage() + $memoryNeeded > $memoryLimit) { $newLimit = $memoryLimitMB + ceil((memory_get_usage() + $memoryNeeded - $memoryLimit) / $MB); ini_set('memory_limit', $newLimit . 'M'); return true; } else { return false; } } ?>
I'm waiting for the bugfix 
|
|
|
|
|
Logged
|
|
|
|
|
zubrag
|
 |
« Reply #10 on: February 18, 2007, 03:33:02 pm » |
|
Thank you for providing code. Implemented. Added comment about your contribution. But not sure if it would be ok to provide your email there. Just let me know if you do not afraid of spammers and I'll add your email there 
|
|
|
|
|
Logged
|
|
|
|
Alecos
Newbie

Posts: 9
|
 |
« Reply #11 on: February 19, 2007, 02:45:14 am » |
|
Thank you for providing code. Implemented. Added comment about your contribution. But not sure if it would be ok to provide your email there. Just let me know if you do not afraid of spammers and I'll add your email there  Of course  But the problem I solved so: ini_set('memory_limit', '-1'); -1 means allocate all needed memory for script so the script that I posted in this forum doesn't need to be implemented since ini_set('memory_limit', '-1'); solves the problem! my email address is info[at]alecos[dot]it (please do not spam to my address).
|
|
|
|
|
Logged
|
|
|
|
Alecos
Newbie

Posts: 9
|
 |
« Reply #12 on: February 19, 2007, 03:00:09 am » |
|
this is the code fixed for inclusion into your script  <?php function setMemoryForImage($filename) { $imageInfo = getimagesize($filename); $MB = 1048576; $K64 = 65536; $TWEAKFACTOR = 1.5; $memoryNeeded = round(($imageInfo[0] * $imageInfo[1] * $imageInfo['bits'] * $imageInfo['channels'] / 8 + $K64) * $TWEAKFACTOR); $memoryLimitMB = 8; $memoryLimit = $memoryLimitMB * $MB; if (function_exists('memory_get_usage') && memory_get_usage() + $memoryNeeded > $memoryLimit) { $newLimit = $memoryLimitMB + ceil((memory_get_usage() + $memoryNeeded - $memoryLimit) / $MB); ini_set('memory_limit', $newLimit . 'M'); return true; } else { return false; } } ?>
I'm waiting for the bugfix  Fatal error: Allowed memory size of 23068672 bytes exhausted (tried to allocate 10368 bytes) in /web/htdocs/www.alecos.it/home/set/thumb.php on line 148 this piece of code doesen't work put at the end of script so don't afraid for this mistake... the right solution is ini_set('memory_limit', '-1'); at the top of script <?php // allocate all necessary memory for the image ini_set('memory_limit', '-1');
this workround works 
|
|
|
|
|
Logged
|
|
|
|
|
zubrag
|
 |
« Reply #13 on: February 19, 2007, 04:27:40 am » |
|
Implemented. Thanks again for your help!
|
|
|
|
|
Logged
|
|
|
|
|