Page 1 of 1

Pulling my hair out. ( over Thumbnail Images).

Posted: Wed Jul 28, 2004 3:09 pm
by BuzzParker
I am new to php. I am able to use a form for the user to input/upload a jpeg image and I can save it to a mysql database and bring it back later and display it.

I can't seem to do that with thumbnails.

I can create a thumbnail with imagecreatefromstring on the original uploaded file and then I use imagecreatetruecolor and then imagecopyresized. If I use imagejpeg to save it to disk it works great.

I want to save the thumbnail in a variable.

I found this code that uses imagejpeg with output to a browser and capture that output in a var that I can store in a database.

Here is the code:

$dest_img = imagecreatetruecolor($dest_width, $dest_height)
or die("Cannot Initialize new GD image stream");

imagecopyresized( $dest_img, $src_image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height)
or die("Cannot Resize the image."); // resize the image

ob_start(); // Start capturing stdout.
imageJPEG($dest_img); // As though output to browser.

$Thumbnail = ob_get_contents();
ob_end_clean(); // Dump the stdout so it does not screw other output.


Is this the best/only way to get it into a var?

It is not working. I would like to just put in a var without having to send it to a browser and cature the output buffer.

Any ideas would be greatly appreciated.

TIA

Posted: Wed Jul 28, 2004 3:17 pm
by feyd
That is the only way I know of, without writing the file to a folder.. You may need to make sure there is no other output prior to calling ob_start()

Through a lot of trial and error, I've found it best to not store images in the database though..