hi, im doing a multiple upload. everything works well except that it only allows upload of jpeg. the reason is because of the cropimage function i did. it accept imagecreatefromjpeg. knowing from this, is there a way to convert all $_FILES['file']['tmp_name'] to jpeg before croping?? in that way i wont face any problem with having images not a jpeg.
$n=0;
$file_array=array();
foreach($_FILES['file']['tmp_name'] as $k=>$v){
if($v){
$preupload=$v;
$finalupload=$this->uploadobj->cropimage($preupload,300);
$filename=date('ymdGis').$n.'.gif';
$target='uploads/'.$filename;
if(!copy($finalupload, $target))
$this->error='Your photo was not uploaded successfully';
else{
$file_array[$n]=$filename;
}
$n++;
}
function cropimage($upload,$ratio=0)
{
$src = imagecreatefromjpeg($upload);
list($width,$height)=getimagesize($upload);
list($newwidth,$newheight)=Kgcupload::resizeratio($ratio,$width,$height);
if(!$newwidth && !$newheight)
return;
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
$finalupload = $upload;
imagejpeg($tmp,$finalupload,100);
imagedestroy($src);
imagedestroy($tmp);
return $finalupload;
}
function resizeratio($newwidth=0,$width=0,$height=0)
{
if(!$newwidth || $newwidth==NULL || $newwidth=="")
return NULL;
$array_size=array();
$percentage='';
$newheight='';
if(($width > $newwidth) || ($height > $newwidth)){
if($width > $height)
$percentage=($newwidth/$width);
else
$percentage=($newwidth/$height);
$newwidth = round($width * $percentage);
$newheight = round($height * $percentage);
}
else{
$newwdith=$width;
$newheight=$height;
}
$array_size[]=$newwidth;
$array_size[]=$newheight;
return $array_size;
}