actually a kind french guy helped me out, I wrote the following function (using GD library - no gif support =( )
here is my functions, one for uploading, then one for resizing then one to delete.
it is a little messy, and it uses a switch called $type to make the suffix (not a prefix) on the file changed, which is far better when storing images in my opinion.
// **********************************************
// Image uploader, uploads $img and $img_name to $abpath
// **********************************************
function fileUpload($img,$img_name,$abpath,$debug)
{
//user defined variables
// $abpath is absolute path to where images are uploaded. No trailing slash eg $abpath = "/usr/local/etc/httpd/vhosts/user/somewhere";
$url = "http://www.civicvideo.co.nz/tempupload or whatever"; //Url to where images are uploaded. No trailing slash
$sizelim = "no"; //Do you want size limit, yes or no
$size = "60000"; //What do you want size limited to be if there is one
if($debug==1){echo"Path=$abpath<br>URL:$url<p>Image:$img<p>Image_name: $img_name<p>Img_size:$img_size<p>";}
//checks if file was selected to upload
if ($img == 'none') {
echo("No image selected for upload.<br>");
}
else
{
if ($sizelim == "yes") {
if ($img_size > $size) {
die("<b>Error</b> The file you are trying to upload must be $size or smaller");
}
}
//checks if file exists
//if (file_exists("$abpath/$img_name")) {
//unlink("$abpath/$img_name");
//}
copy("$img", "$abpath/$img_name") or die("<b>Error:</b> Directory Not Created or chmod correctly");
echo"Image Successfully Uploaded ($abpath/$img_name)<br>";
}
}
// **********************************************
// Image Resizer, resizes the width and the rest of the image
// follows in proportion
// **********************************************
function resize_image($image_name,$new_width,$type,$action,$debug){
$PicPathIn="/path to temporary directory where you uploaded the file, usually $abpath in the above function/";
}
$PicPathOut2="/where you are saving the resized files to/";
// Picture
$bild="$image_name";
// fileprefix
$tn=$prefix;
$neueBreite=$new_width; //New width
$size=getimagesize("$PicPathIn"."$bild");
$breite=$size[0];
$hoehe=$size[1];
$neueHoehe=intval($hoehe*$neueBreite/$breite);
if($size[2]==1) {
// GIF
$altesBild=ImageCreateFromGIF("$PicPathIn"."$bild");
$neuesBild=ImageCreate($neueBreite,$neueHoehe);
ImageCopyResized($neuesBild,$altesBild,0,0,0,0,$neueBreite,
$neueHoehe,$breite,$hoehe);
if($type==video_sml){$bild2 = ereg_replace(".gif","sml.gif", $bild);}
elseif($type==video){$bild2 = ereg_replace(".gif","big.gif", $bild);}
elseif($type==game){$bild2 = ereg_replace(".gif","_gme.gif", $bild);}
ImageGIF($neuesBild,"$PicPathOut$bild");
}
if($size[2]==2) {
// JPG
$altesBild=ImageCreateFromJPEG("$PicPathIn"."$bild");
$neuesBild=ImageCreate($neueBreite,$neueHoehe);
ImageCopyResized($neuesBild,$altesBild,0,0,0,0,$neueBreite,
$neueHoehe,$breite,$hoehe);
if($type==video_sml){$bild2 = ereg_replace(".jpg","sml.jpg", $bild);}
elseif($type==video){$bild2 = ereg_replace(".jpg","big.jpg", $bild);}
elseif($type==game){$bild2 = ereg_replace(".jpg","_gme.jpg", $bild);}
ImageJPEG($neuesBild,"$PicPathOut$bild2");
}
if($size[2]==3) {
// PNG
$altesBild=ImageCreateFromPNG("$PicPathIn"."$bild");
$neuesBild=ImageCreate($neueBreite,$neueHoehe);
ImageCopyResized($neuesBild,$altesBild,0,0,0,0,$neueBreite,
$neueHoehe,$breite,$hoehe);
if($type==video_sml){$bild2 = ereg_replace(".png","sml.png", $bild);}
elseif($type==video){$bild2 = ereg_replace(".png","big.png", $bild);}
elseif($type==game){$bild2 = ereg_replace(".png","_gme.png", $bild);}
ImagePNG($neuesBild,"$PicPathOut$bild2");
}
if($debug==1){
echo "Old Picture: <BR>";
echo "<IMG SRC=\"tempup/$bild\" WIDTH=\"$breite\" HEIGHT=\"$hoehe\">
<BR><BR>";
echo "New Picture:<BR>";
echo "<IMG SRC=\"slicks/$bild2\" WIDTH=\"$neueBreite\" HEIGHT=\"$neueHoehe\">";
}
//if($action=='delete')
//{
//if (file_exists("$PicPathIn/$image_name"))
// {
//$file_unlink="$PicPathIn$image_name";
//if($debug==1){echo"file_unlink=$file_unlink";}
//unlink("$file_unlink");
// }
//}
// close function resize_image
echo"Image $bild2 created and resized to width $neueBreite<br>";
}
//***************************************************************************
function delete_image($img_name,$abpath,$debug){
if(file_exists("$abpath/$img_name"))
{
unlink("$abpath/$img_name");
echo"File $img_name deleted<br><br>";
}else{echo"File $img_name doesn't exists, cannot delete<br><br>";}
}