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
GD & Images
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Welcome to the forums.
Searching the forums, you'll find all that you asked for:
Searching the forums, you'll find all that you asked for:
- Resize stuff: viewtopic.php?t=18814
- Resize stuff: viewtopic.php?t=23757
- Resize stuff: viewtopic.php?t=24077
- Image storage: viewtopic.php?t=23318&highlight=image+mysql
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
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.
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);
}Real programmers don't comment their code. If it was hard to write, it should be hard to understand.