Search code examples
phpgdimagecreatefrompng

imagecreatefrompng() and size limitation


I have some troubles with the function imagecreatefrompng(), in PHP.

I develop a website which has the goal to permit users to upload their own Sprite Comics (kinds of Comics made with ressources extracted from videogames, called sprites).

I want to display in their galeries some miniatures of their comics, so I use GD and, of course, imagecreatefrompng().

But it throw a fatal error with large images:

Fatal error: Out of memory (allocated 8388608) (tried to allocate 4545600 bytes)

The same error occurs even after setting the value of "memory_limit" via ini_set()...

After few hours of researches, it seems to be because of the resolution: imagecreatefrompng() can't manage images having more than 1 040 000 pixels...!

It's very very inconvenient, since I can't limit the size of comics sent by the users...

Do you know any tips to resolve this issue?

Thnaks in advance!


Solution

  • You need to ask your hosting provider to set more virtual memory. It's a setting in php.ini - memory_limit and shouldn't be problem to do it free. You are now on the most lowest value.