func.php 1.59 KB
<?php
        function upload_ImageResize($upload,$option){

   $type = substr(strrchr($upload['name'],"."),1);
   $newWidth = $option["width"];
   $newHeight = $option["height"];
   $nameFile = mktime() . "." . $type;
   $save_image = $option["upload_path"] . $nameFile;
   $img = $upload["tmp_name"];

switch($type){
case "jpg":
   $function_image_create = "ImageCreateFromJpeg";
   $function_image_new = "ImageJpeg";
case "jpeg":
   $function_image_create = "ImageCreateFromJpeg";
   $function_image_new = "ImageJpeg";
break;
case "png":
   $function_image_create = "ImageCreateFromPng";
   $function_image_new = "ImagePNG";
break;
case "gif":
   $function_image_create = "ImageCreateFromGif";
   $function_image_new = "ImageGif";
break;
default:
   $function_image_create = "ImageCreateFromJpeg";
   $function_image_new = "ImageJpeg";
break;
}


   $srcImage = @$function_image_create($img);

   $srcWidth  = ImageSX($srcImage);
   $srcHeight = ImageSY($srcImage);


  if ( ($newWidth < $srcWidth) || ($newHeight < $srcHeight) ) {
   if( $srcWidth < $srcHeight ){
       $destWidth  = $newWidth * $srcWidth/$srcHeight;
       $destHeight = $newHeight;
   }else{
       $destWidth  = $newWidth;
       $destHeight = $newHeight * $srcHeight/$srcWidth;
   }
  }else{ $destWidth = $srcWidth;$destHeight = $srcHeight;}



   $destImage = imagecreatetruecolor($destWidth, $destHeight);

   ImageCopyResampled( $destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight );
  @$function_image_new($destImage,$save_image,100);

   ImageDestroy( $srcImage  );
   ImageDestroy( $destImage );

return $nameFile;
}
?>