nil 发表于 2024-10-28 21:31:03

PHP GD 縮放圖片大小 imagecopyresampled

<?php
// File and new size
$filename = 'test.jpg';
$percent = 0.5;

// Content type
header('Content-Type: image/jpeg');

// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;

// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);

// Resize
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

// Output
imagejpeg($thumb);
?>

使用 imagecopyresampled 的圖片質量比 imagecopyresized 要好得多

页: [1]
查看完整版本: PHP GD 縮放圖片大小 imagecopyresampled