steviez Posted January 24, 2010 Share Posted January 24, 2010 Hi, I am developing a image upload system for my site where users will be able to upload images in to their photo albums. My problem is this: When uploading the images the script has to create a few different sized thumbnails for each image and so far the system fails. I keep getting an error saying "failed to allocate xxxx bytes ....." I know that when an images is to be resized first it is uncompressed and it takes up a lot of memory but surly there is a way to do it even on shared hosting where you cant change your memory allocation? I will have quite a few users uploading at the same time so it has to work, can anyone shed some light on a good way to resize? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/189654-best-way-to-resize-images/ Share on other sites More sharing options...
pernest Posted January 24, 2010 Share Posted January 24, 2010 I asked the very same question earlier today. http://www.phpfreaks.com/forums/index.php/topic,285284.msg1353046.html#msg1353046 From what I can tell, the issue is that the php script creates a memory bitmap of any photo which is uploaded in order to resize it. It is possible to increase the memory allocated to the php scripts by changing memory_limit = 16M in php.ini however my host will not allow me to increase this limit as far as I need. jl5501 pointed me towards phpThumb, which manipulates images to create arbitray sized thumbnails. It uses the gd library, but I got an equivalent memory error with that. If your host has ImageMagick installed, then phpThumb can use that, but as my host doesn't then I can't say if it would work any better. Another option I was playing around with was a command line image resizer, convert. (I later found out that this was a tool from Imagemagick). If your host has this tool, then you could just use shell_exec like shell_exec("convert rose.jpg -resize 50% rose.png"); If your host wont let you do any of these things and you find an alternate solution, then please post it, because I'm stuck too. convert rose.jpg -resize 50% rose.png Quote Link to comment https://forums.phpfreaks.com/topic/189654-best-way-to-resize-images/#findComment-1000954 Share on other sites More sharing options...
MadTechie Posted January 24, 2010 Share Posted January 24, 2010 Their are a few ways to do this, and I had the same problem a while ago, (Skip to the last few lines if you wish,) Now you can do some memory hacks to increase the memory limit and while this does work on some host, you may end up causing another problem, called resource limit, this is when the shared host will notice the extra resource and may even suspend your site causing the whole site to be down for a few hours or a day or worse remove your site for breaking the terms of agreement, So how can we resolve this? Well the problem I had was member were attempting to upload quite large images and this cause timeout and memory limit problems, and even when i got around all of that they complained about it taking ages to upload the images (that was due to their upload speed), so I looked at the problem as a whole, and the solution is very simple, resize the images before uploading.. okay that doesn't help the poor souls who have no idea how to do that, but the solution is the same.. i need the clients to resize the images or put another way.. i need the resizing to be done on the clients PC, So the real question is HOW ? I played around with a few client sided options, Silverlight, Java & Flash, I wrote some basic up-loaders for each and they all solved the problem, however Silverlight crashed a failed more times than i would care to support (could of been my code) Java worked great but not everyone has this pre-installed, but lots of people have Flash installed and it can look quite good.. So try swfupload here is a link the a demo doing the pre-resize Hope that helps Quote Link to comment https://forums.phpfreaks.com/topic/189654-best-way-to-resize-images/#findComment-1000973 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.