Welcome Guest, Not a member yet? Register   Sign In
image_lib works with some files but not others
#1

[eluser]Peter Axon[/eluser]
I am having a really frustrating problem with image_lib. I upload the images and then make them smaller with 'resize()' and create a thumbnail.

However it is only working with some images and not others. It doesn't work with jpgs which were exported from Publisher and sent to my Mac. I even tried resaving them with Photoshop as both jpg and png. However it works with three sample images I grabbed off the web, in jpg gif and png format.

Is there a problem with image_lib not being able to work with some files or something.

This is really frustrating and has taken me days to get down to this stage.

Thanks in advance.
#2

[eluser]Thorpe Obazee[/eluser]
Try posting code then someone could help you.
#3

[eluser]xwero[/eluser]
Do you get a blank page? If that is the case check the width of the images. It's possible the width is too big to be processed by the image library.
#4

[eluser]Peter Axon[/eluser]
Thanks xwero,

Yes I do get a blank page. And its interesting you should say that the width might be too big. Something possessed me to try changing the size of the image tonight and I noticed that the original images (1280x1754 px) did not work but if I resized the image to 1000 px wide (1000x1415 px) in Photoshop it worked fine.

Do you happen to know what the maximum width that image_lib can process is?

Thanks ever so much for the reply.
#5

[eluser]xwero[/eluser]
It's not an image_lib limitation but a limitation of the php image manipulation library that is used by image_lib. I'm not sure where the limitation comes from because when i tracked the bug i found out it happens when image_lib calls the imagecreatetruecolor function which creates a handle for the resized image and that has nothing to do with the source image.

To prevent this from happening you should add a max_width setting in the upload class.
#6

[eluser]Peter Axon[/eluser]
Ah, I wondered if that might be it. So do you think it might be a problem with GD2? I might try using ImageMagick as the library and see if that has the same problem.

Thank you so much for helping with this, it is such a relief to have a solution. I will do the max_width setting.
#7

[eluser]Peter Axon[/eluser]
I think the script might be running out of memory. I found the following quote here http://www.boutell.com/gd/faq.html

Quote:Why does gd cause my PHP script to run out of memory?
Most often, the problem is that the memory_limit parameter in php.ini is set to something very conservative, like 8M (eight megabytes). Increase that setting and restart the web server.

Of course, opening truly huge images can cause real memory problems, if several are open at once. 8,000 pixels times 8,000 pixels times four bytes for truecolor equals a walloping 256 megabytes.

If the calculations were the same for my original image (1280x1754) it would be:

Code:
1280 * 1754 * 4 = 8980480

About 8.9 Mb which is bigger than the 8 Mb limit specified in my php.ini file.

For my resized image (which worked fine) it would be:

Code:
1000 * 1415 * 4 = 5660000

About 5.6 Mb which is easily in the 8 Mb limit

I think this might be the problem, the script is running out of memory. This would explain the blank page as the script just stops running. I could either raise the 8 Mb limit in the php.ini file or specify a max_width for the uploaded file. I think I will do the latter.
#8

[eluser]xwero[/eluser]
If the script is running out of memory it should display an error. But the strange thing is it happened to me while creating thumbnails so the imagecreatetruecolor parameters where well within the limits of the memory's capacity. It would make more sense if the process breaks down when the imagecopyresampled function is called as that is the workhorse function.

I even altered the library to display an error if the imagecreatetruecolor function fails but it still gave me a blank page.




Theme © iAndrew 2016 - Forum software by © MyBB