热搜:NVER node 开发 php

学习中 请教 一段代码图片缩放的问题

2024-07-21 10:40:02
学习中 请教 一段代码图片缩放的问题

function resize($srcImage,$toFile,$maxWidth = 450,$maxHeight = 450,$imgQuality=100) 

   
    list($width, $height, $type, $attr) = getimagesize($srcImage); 
    if($width     switch ($type) { 
    case 1: $img = imagecreatefromgif($srcImage); break; 
    case 2: $img = imagecreatefromjpeg($srcImage); break; 
    case 3: $img = imagecreatefrompng($srcImage); break; 
    } 
    $scale = min($maxWidth/$width, $maxHeight/$height); //求出绽放比例 
     
    if($scale     $newWidth = floor($scale*$width); 
    $newHeight = floor($scale*$height); 
    $newImg = imagecreatetruecolor($newWidth, $newHeight); 
    imagecopyresampled($newImg, $img, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); 
    $newName = ""; 
    $toFile = preg_replace("/(.gif|.jpg|.jpeg|.png)/i","",$toFile); 
 
    switch($type) { 
        case 1: if(imagegif($newImg, "$toFile$newName.gif", $imgQuality)) 
        return "$newName.gif"; break; 
        case 2: if(imagejpeg($newImg, "$toFile$newName.jpg", $imgQuality)) 
        return "$newName.jpg"; break; 
        case 3: if(imagepng($newImg, "$toFile$newName.png", $imgQuality)) 
        return "$newName.png"; break; 
        default: if(imagejpeg($newImg, "$toFile$newName.jpg", $imgQuality))
        return "$newName.jpg"; break; 
    } 
    imagedestroy($newImg); 
    } 
    imagedestroy($img); 
    return false; 
}


在网上找到了这个, 可以正常缩小   但是怎么没法放大呢,

求大虾解惑


回复讨论(解决方案)

你把  if($scale 

你把  if($scale 

我去。。 我这眼睛。。 哈哈 懂了  谢谢你