We help IT Professionals succeed at work.

imagecreatetruecolor limit on width and height attributes

tripat used Ask the Experts™
In PHP5  running on windows server

For the function imagecreatetruecolor is there a way we can incease the limit of width and height as presently, we are working on a program for which I need to specify the width and height in the range of 4000 x 5000 but it does not work. It works till 512x1260 only

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

I already had bigger images created... I think, there may be some limitations in your environment... Could you specify what are you using? (OS, PHP ver, GDLib ver, whatever)

Do you have any error message/notice somewhere, or you just have that 512*1260 image always?

it might be a memory limitation. Look in your php.ini for memory_limit and increase it to see if you can make bigger images. if that works, then increase it till you can get your script to run ok
Richard QuadlingSenior Software Developer

A few steps and questions.

1 - Is the code running from a URL like ...  sort of thing?
2 - If so, take the URL and http://www.site.com/script.php?id=xxxx and run it directly in the browser.
3 - Any output? You may need to do a view-source to see anything.
4 - If not, try amending the script ...

error_reporting(-1); // Report ALL errors.
ini_set('display_errors', 1); // Show all errors.
set_time_limit(0); // Allow the script to take more than the default 30 seconds.

// Your code.

At some stage I would expect you to issue a header() statement setting the content-type to image/xxx (png/jpg/etc.).

Prior to this line, you need something like ...

if (!headers_sent()) {
  header('Content-type: ......');
  // Your code to output the image.
} else {
 die('An error occurred.');

sort of thing.

That way, if your code DOES produce an error, you can run the URL directly from the browser and see the error without PHP changing the content-type and generating the image.

if is a memory problem you can set the limit just for the script by using ini_set():
ini_set('memory_limit','65M'); // remember that every pixel have 3 bytes for color (without alpha channel)
$im = imagecreatetruecolor(4000,5000);

Open in new window

Richard QuadlingSenior Software Developer
If you feel risky, setting that value to -1 will allow ALL memory to be used : http://docs.php.net/manual/en/ini.core.php#ini.memory-limit