Pulling my hair out. ( over Thumbnail Images).

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
BuzzParker
Forum Newbie
Posts: 1
Joined: Wed Jul 28, 2004 3:09 pm

Pulling my hair out. ( over Thumbnail Images).

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
Post Reply