圖片壓縮

說明:原圖爲png,返回縮略圖爲jpg格式ide

$fileName = md5(basename($template) . $url);
$source = '../public/uploads/' . $file . '/invite/' . $time . '/' . $uid . '_' . $fileName . '.png'; //原圖ui

public function handlePic($srcPathName){url

$srcFile = $srcPathName;
    $srcFileExt = strtolower(trim(substr(strrchr($srcFile, '.'), 1)));
    if ($srcFileExt == 'png') {
                        $dstFile = str_replace('.png', '.jpg', $srcPathName);
                        $photoSize = GetImageSize($srcFile);
                        $pw = $photoSize[0];
                        $ph = $photoSize[1];
                        $dstImage = ImageCreateTrueColor($pw, $ph);
                        imagecolorallocate($dstImage, 255, 255, 255);
                        //讀取圖片
                        $srcImage = ImageCreateFromPNG($srcFile);
                        //合拼圖片
                        imagecopyresampled($dstImage, $srcImage, 0, 0, 0, 0, $pw, $ph, $pw, $ph);
                        imagejpeg($dstImage, $dstFile, 70);
                        imagedestroy($srcImage);
    }

}code

相關文章
相關標籤/搜索