Page 1 of 1

GD & Images

Posted: Fri Jul 30, 2004 1:14 pm
by jrcal
I know this may sound silly to some of you - but I'm a newbie and I definitely need some direction.

I would like to create a site that allows one to upload & display images. How do I use the GD library to resize/alter images that the user uploads?

Also, how do I store these images in a MySQL database? Is there a special image function?



Thanks,
JR

Posted: Fri Jul 30, 2004 1:26 pm
by feyd
Welcome to the forums.

Searching the forums, you'll find all that you asked for:

Posted: Fri Jul 30, 2004 1:51 pm
by pickle
Be sure to read the links ~feyd has provided, but to sum up what they'll say:

To resize images:

use [php_man]imagecopyresampled[/php_man]() if you've got GD 2.01 or greater, or [php_man]imagecopyresized[/php_man]() if you don't. imagecopyresampled() does a much better job of making thumbnails.

To insert into a DB:
A number of methods to do this, but I use this function

Code: Select all

function read_in($p_file_path,$add_slashes = true)
{
  $filehandle = fopen($p_file_path,'rb');
  $image_data = fread($filehandle,filesize($p_file_path);
  $image_data = ($add_slashes) 
          ? mysql_escape_string($image_data) 
          : $image_data;
  fclose($filehandle);

  return($image_data);
}
Then, take the returned data, and insert it into the DB. Be sure to use a BLOB type so the data will fit. BLOB will only accept 16K worth of data (I think), so I'd use MEDIUMBLOB which can old up to 1.6 MB.