如何将图像转换为jpg?

时间:2014-03-25 12:41:47

标签: php mysql

如何为此上传功能添加图像转换器?我希望始终以JPG格式保存图像。

这是我的PHP代码:

    foreach($_FILES["thpostimg"]["error"] as $key => $value) {
      if($_FILES["thpostimg"]["tmp_name"][$key] == NULL)
                  { $thpostimg = $_FILES["thpostimg"]["name"][$key]; } else 
                   { 
                   $ext = strtolower(pathinfo($_FILES["thpostimg"]["name"][$key], PATHINFO_EXTENSION));
                   $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
                   $rand_dir_name = substr(str_shuffle($chars), 0, 30);
                   $path = uniqid().'-'.$rand_dir_name.'.' .$ext;
                   $thpostimg = $path;
                   }
     if($_FILES["thpostimg"]["tmp_name"][$key] == NULL){  } else 
             { 
            $arr_image_details = getimagesize($_FILES["thpostimg"]["tmp_name"][$key]); 
            $width = $arr_image_details[0];
            $height = $arr_image_details[1];
            $mime = $arr_image_details['mime'];
             copy($_FILES['thpostimg']['tmp_name'][$key], './upload/'.$thpostimg);
             }
          }

0 个答案:

没有答案