Forum Moderators: coopster
I have a system where admins can upload photos and images....the original photo as well as the thumbnail...At first sight, I had 2 fields, one for the image and one for the thumbnail...however, I was thinking about having only one field while the image should be proccessed by the "submit" script afterwards in order to create the thumbnail aytomatically in the selected folder (/pictures/thumbs/) while storing the original image in the /pictures/ folder...
In the first system I created (2 fields), both images were uploaded in a selected folder while their extensions(names) were stored in the Database...however...if I use GD library to create the new system the whole thing changes...Images are not uploaded but stored directly in the database as strings and called afterwards as images...for instance, the original photo is stored in the database while the automatically created thumbnail proccessed by GD, (opened as text...croped...etc etc.) and also stored in DB as text...Am I right?
Typically I just store the path to the image in the DB since it's faster to pull out the path to the image than 60k or more of image data.
The imagejpeg() [php.net] function will let you save image data to a file.
function resampimagejpg($forcedwidth, $forcedheight, $sourcefile, $destfile) {
$g_imgcomp=$imgcomp;
$g_srcfile="temp/".$sourcefile;
$g_dstfile=$destfile;
$g_fw=$forcedwidth;
$g_fh=$forcedheight;
$g_is=getimagesize($g_srcfile);
if ($g_is[0] >= $g_is[1]) {
$orientation = 0;
} else {
$orientation = 1;
$g_fw = $forcedheight;
$g_fh = $forcedwidth;
}
if ($g_is[0] > $g_fw ¦¦ $g_is[1] > $g_fh) {
if(($g_is[0]-$g_fw)>=($g_is[1]-$g_fh)) {
$g_iw=$g_fw;
$g_ih=($g_fw/$g_is[0])*$g_is[1];
} else {
$g_ih=$g_fh;
$g_iw=($g_ih/$g_is[1])*$g_is[0];
}
$t = 1;
} else {
$g_iw = $g_is[0];
$g_ih = $g_is[1];
$t = 2;
}
if ($t == 1) {
$img_src=imagecreatefromjpeg($g_srcfile);
$img_dst=imagecreatetruecolor($g_iw,$g_ih);
imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $g_iw, $g_ih, $g_is[0], $g_is[1]);
if(!imagejpeg($img_dst, $destfile, 90))
{
exit();
}
} else if ($t == 2) {
copy( $g_srcfile, $g_dstfile );
}
}