PHP 创建缩略图
一、成比例缩小图像 <?php /* 创建缩略图 */ $file = __DIR__.'/button.png'; $scale = 0.5; // 比例 $image = ImageCreateFromPNG($file); $thumbnail = ImageCreateTrueColor( ImageSX($image) * $scale, ImageSY($image) * $scale ); // 保留透明度 ImageColorTransparent($thumbnail, ImageColorAllocateAlpha($thumbnail, 0, 0, 0, 127) ); ImageAlphaBlending($thumbnail, false); ImageSaveAlpha($thumbnail, true); // 缩小 & 复制 ImageCopyResampled($thumbnail, $image, 0, 0, 0, 0, ImageSX($thumbnail), ImageSY($thumbnail), ImageSX($image), ImageSY($image) ); header('Content-type: image/png'); ImageJpeg($thumbnail); ImageDestroy($image);