imagecopyresized - Reducing Memory Usage
Posted: Tue Oct 30, 2007 6:56 pm
Is there a way to resize images and use less memory?
I want to be able to handle users that upload 5-10 megapixel images (for my open source project). Resize them first (to save cpu), and then resample them. I'm creating two images - one with a maximum width of 800 pixels, and a more thumbnail version with a width of 200 pixels.
MySpace seems to handle large images - for instance, I successfully uploaded a 40 megapixel (4mb) jpg image - and it resized fine (with php this could have used 300 mb memory). Which makes me think there might be a better way of doing this.
My resizing seems to use around 7-8 bytes per pixel - as I'm using imagecreatetruecolor() to create the images. So a 10 megapixel image can use 70-80mb of memory - and several years from now, it's possible that people wll upload 20 megapixel images.
Would only resizing part of the image at a time help? Can I do it, while mantaining a decent quality, without using imagecreatetruecolor? Any other ideas? I'm not that familiar with the GD library or how php image functions work in general.
I want to be able to handle users that upload 5-10 megapixel images (for my open source project). Resize them first (to save cpu), and then resample them. I'm creating two images - one with a maximum width of 800 pixels, and a more thumbnail version with a width of 200 pixels.
MySpace seems to handle large images - for instance, I successfully uploaded a 40 megapixel (4mb) jpg image - and it resized fine (with php this could have used 300 mb memory). Which makes me think there might be a better way of doing this.
My resizing seems to use around 7-8 bytes per pixel - as I'm using imagecreatetruecolor() to create the images. So a 10 megapixel image can use 70-80mb of memory - and several years from now, it's possible that people wll upload 20 megapixel images.
Would only resizing part of the image at a time help? Can I do it, while mantaining a decent quality, without using imagecreatetruecolor? Any other ideas? I'm not that familiar with the GD library or how php image functions work in general.