Page 1 of 1

Resize images before they go into a database??

Posted: Sat Oct 21, 2006 5:37 pm
by gloveny2
Hi, I ve made a program which acts like a small blog. You can upload an image for the main header, and you can upload multiple images for each entry.

The header image is uploaded and goes straight into a database, because I will tell the users the perfect size they need for it to fit correctly. The images for the entries can be any size as they are resized after they are uploaded but only if they are over a certain size. A thumbnail is also created which is 80x80px. They are kept as files on the sever, rather than going into the database.

So the header image is left alone and goes straight into the database
And the entry images are resized if they are too big, a thumbnail created and then stored as files.

Here’s where I’m scratching my head.....

I can upload a HUGE image for the header which goes straight into the database, but if I try to upload the same image using the file store method I get :: Allowed memory size of 20971520 bytes exhausted (tried to allocate 9088 bytes)

Which stage exactly is taking up the memory? Is it the writing to file bit?

Another thing I want to know which would solve this problem is Can I check an images width and height as it comes in, resize it if necessary and put it straight in the database?

Thanks all, hope you can help.
Graham Vincent

Posted: Sat Oct 21, 2006 5:49 pm
by amir
Do you want to know this?

Code: Select all

list($width, $height) = getimagesize("images/".$prod_arr[0]['prodimage']);
	
	if($width > 250) {
		$width = 250;				
	} else {
		$width = $width;
	}

Posted: Mon Oct 23, 2006 4:13 am
by gloveny2
amir, thanks for posting but your going to have to explain that code a bit :oops:

Ok, what is the prod_arr[] ? and where is it comming form. Is the prod_arr just the array of objects comming form the form?

Is getimagesize() getting the image form the file system or can it look direclty at the images as its uploaded?

Thanks again for posting, cheers.
Graham