Zubrag.com
December 14, 2018, 06:16:11 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: thumb.php doesn't show images bigger than 1280x1024...  (Read 35205 times)
Alecos
Newbie
*
Posts: 16


« 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:

Code:
$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
Administrator
Hero Member
*****
Posts: 788


WWW
« 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: 16


« 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  Smiley
Logged
Alecos
Newbie
*
Posts: 16


« 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.php

hummm... seem to be a strange case...
Logged
Alecos
Newbie
*
Posts: 16


« Reply #4 on: February 15, 2007, 10:24:36 AM »

I used as follow:

http://www.alecos.it/set/thumb.php?src=http://www.alecos.it/files/Natale.jpg&x=300&y=300&f=0

Now I have an error:

Fatal error: Allowed memory size of 12582912 bytes exhausted (tried to allocate 10368 bytes) in /web/htdocs/www.alecos.it/home/set/thumb.php on line 143

While...

http://www.alecos.it/files/Natale.jpg

works! Why?
Logged
Alecos
Newbie
*
Posts: 16


« 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:

Code:
<?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
Administrator
Hero Member
*****
Posts: 788


WWW
« 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: 16


« Reply #7 on: February 15, 2007, 11:46:29 AM »

See these url:

http://it2.php.net/manual/it/function.imagecreatefromjpeg.php#64155

and

http://it2.php.net/manual/it/function.imagecreatefromjpeg.php#65161

I hope this post can help you in some way Wink
Logged
zubrag
Administrator
Hero Member
*****
Posts: 788


WWW
« Reply #8 on: February 15, 2007, 12:12:00 PM »

Thank you for help Smiley  I'll add that code.
Logged
Alecos
Newbie
*
Posts: 16


« Reply #9 on: February 18, 2007, 08:29:22 AM »

this is the code fixed for inclusion into your script Wink

Code:
<?php
  
function setMemoryForImage($filename) {
    
$imageInfo getimagesize($filename);
    
$MB 1048576;
    
$K64 65536;
    
$TWEAKFACTOR 1.5;
    
$memoryNeeded round(($imageInfo[0] * $imageInfo[1] * $imageInfo['bits'] * $imageInfo['channels'] / $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 Wink
Logged
zubrag
Administrator
Hero Member
*****
Posts: 788


WWW
« 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 Smiley
Logged
Alecos
Newbie
*
Posts: 16


« 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 Smiley

Of course Wink But the problem I solved so:

Code:
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: 16


« Reply #12 on: February 19, 2007, 03:00:09 AM »

this is the code fixed for inclusion into your script Wink

Code:
<?php
  
function setMemoryForImage($filename) {
    
$imageInfo getimagesize($filename);
    
$MB 1048576;
    
$K64 65536;
    
$TWEAKFACTOR 1.5;
    
$memoryNeeded round(($imageInfo[0] * $imageInfo[1] * $imageInfo['bits'] * $imageInfo['channels'] / $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 Wink

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

Code:
<?php
  
// allocate all necessary memory  for the image
  
ini_set('memory_limit''-1');

this workround works Wink
Logged
zubrag
Administrator
Hero Member
*****
Posts: 788


WWW
« Reply #13 on: February 19, 2007, 04:27:40 AM »

Implemented. Thanks again for your help!
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC