日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Php传图缩图,使用以下用于上传图像的PHP代码上传时缩小图像大小

發布時間:2025/5/22 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Php传图缩图,使用以下用于上传图像的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 );

總結

以上是生活随笔為你收集整理的Php传图缩图,使用以下用于上传图像的PHP代码上传时缩小图像大小的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。