уменьшить размер изображения при загрузке, используя следующий код PHP, используемый для загрузки изображения

Я пытаюсь загрузить изображение на сервер, используя следующий код. Ниже приводятся приведенный ниже код

  • Загрузить переименование файлов
    Что мне нужно, мне нужно уменьшить размер изображения с помощью следующего кода

Вот код

$file_name = $HTTP_POST_FILES['ufile']['name']; $random_digit = md5(rand() * time()); $new_file_name = $random_digit . $file_name; $path = "upload/" . $new_file_name; if ($ufile != none) { if (copy($HTTP_POST_FILES['ufile']['tmp_name'], $path)) { echo "Successful<BR/>"; echo "File Name :" . $new_file_name . "<BR/>"; echo "File Size :" . $HTTP_POST_FILES['ufile']['size'] . "<BR/>"; echo "File Type :" . $HTTP_POST_FILES['ufile']['type'] . "<BR/>"; } else { echo "Error"; } } 

как уменьшить размер изображения с заданным кодом

Конечно, все хорошо. Я использую этот класс в PHP:

 <?php function thumbnail( $img, $source, $dest, $maxw, $maxh ) { $jpg = $source.$img; if( $jpg ) { list( $width, $height ) = getimagesize( $jpg ); //$type will return the type of the image $source = imagecreatefromjpeg( $jpg ); if( $maxw >= $width && $maxh >= $height ) { $ratio = 1; }elseif( $width > $height ) { $ratio = $maxw / $width; }else { $ratio = $maxh / $height; } $thumb_width = round( $width * $ratio ); //get the smaller value from cal # floor() $thumb_height = round( $height * $ratio ); $thumb = imagecreatetruecolor( $thumb_width, $thumb_height ); imagecopyresampled( $thumb, $source, 0, 0, 0, 0, $thumb_width, $thumb_height, $width, $height ); $path = $dest.$img."_thumb.jpg"; imagejpeg( $thumb, $path, 75 ); } imagedestroy( $thumb ); imagedestroy( $source ); } 

?>

 imagejpeg( $thumb, $path, 75 ); 

где вы хотите размер и качество изображения после загрузки.

Вызов в скрипте PHP:

 if( isset( $_FILES['img-content'] ) ) { $img = str_replace( " ","_",$_FILES['img-content']['name'] ); move_uploaded_file( $_FILES['img-content']['tmp_name'], "../../images/content/".$img ); $source = "../../images/content/"; $dest = "../../images/thumb/"; thumbnail( $img, $source, $dest, 480, 400 );