I'm developing a web site to manage images. In this site included an image library for that the users uploads permitted images files(jpg, tiff and psd) and the server creates a low resolution image.
Then I have a problem with the files with layers(tiff and psd). I have used a simple code to merge the layers using the function: mergeImageLayers with the constant(LAYERMETHOD_FLATTEN). Using this the 80% of the files creates a good low resolution but the another 20% not

For example when it uploaded a psd/tiff file with touch-up color layer show an error with Internal Server Error bla bla bla...
I need help with this files. Which is the best way to solved this issue?
Thanks!