I have been looking around all day for some decent info regarding resizing images, most appear to be for resizing on the fly when displaying, I dunno for sure tho cuz this is my first try with it.
I have a mysql driven tool I want to upload an image with. Some people take images from their digital cam and try to upload files that are like 3000 pixels wide...I wanna catch those and scale it down...plus, create a thumbnail as well.
I don't have the big file size catch in here yet cuz I can't even get this much working. Here is my function:
Function createImages($filename,$ins_id,$full_w,$tn_w)
{
$orig_filename=strrpos($filename, strrpos($url,"/") + 1);
$system=explode('.',$orig_filename);
if(preg_match('/.jpg|jpeg/',$system[1]))
{
$full_filename="fl_".$ins_id.".jpg";
$thumb_filename="tn_".$ins_id.".jpg";
$src_img=imagecreatefromjpeg($filename);
}
if(preg_match('/.png/',$system[1]))
{
$full_filename="fl_".$ins_id.".png";
$thumb_filename="tn_".$ins_id.".png";
$src_img=imagecreatefrompng($filename);
}
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
if($old_x != $old_y)
{
$fullsize_percentage=$old_x / $full_w;
$thumb_percentage=$old_x / $tn_w;
$fullsize_w=$full_w;
$fullsize_h=$old_y*$fullsize_percentage;
$thumb_w=$tn_w;
$thumb_h=$old_y*$thumb_percentage;
}
if($old_x == $old_y)
{
$fullsize_w=$full_w;
$fullsize_h=$full_w;
$thumb_w=$tn_w;
$thumb_h=$tn_w;
}
$fullsize_img=ImageCreateTrueColor($fullsize_w,$fullsize_h);
imagecopyresampled($fullsize_img,$src_img,0,0,0,0,$fullsize_w,$fullsize_h,$old_x,$old_y);
$thumb_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($thumb_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
ob_start();
if(preg_match("/.png/",$system[1]))
{
imagepng($thumb_img,$thumb_filename);
imagepng($fullsize_img,$full_filename);
}
else
{
imagejpeg($thumb_img,$thumb_filename);
imagejpeg($fullsize_img,$full_filename);
}
ob_end_clean();
imagedestroy($fullsize_img);
imagedestroy($thumb_img);
imagedestroy($src_img);
unlink($filename);
}
Pass the path to the file which has been uploaded, the record ID (to later use as part of the naming) and the width for the full size and thumbnail versions of the file.
Running this I get no error messages, but the final unlink to delete the original file works, so it is getting there...but no full size or thumbnail is saved. I am sure I am missing something simple, could someone pelase advise?
And yes, I do have GD, create enabled and 2.0.28 GD version...
little help would be mucho appreciated.