请选择 进入手机版 | 继续访问电脑版

AI 社区

 找回密码
 立即注册
查看: 2117|回复: 0

PHP GD 縮放圖片大小 imagecopyresampled

[复制链接]

82

主题

18

回帖

496

积分

区板主

Rank: 8Rank: 8

积分
496
发表于 2021-10-19 19:24:30 | 显示全部楼层 |阅读模式
  1. <?php
  2. // File and new size
  3. $filename = 'test.jpg';
  4. $percent = 0.5;

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

  7. // Get new sizes
  8. list($width, $height) = getimagesize($filename);
  9. $newwidth = $width * $percent;
  10. $newheight = $height * $percent;

  11. // Load
  12. $thumb = imagecreatetruecolor($newwidth, $newheight);
  13. $source = imagecreatefromjpeg($filename);

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

  16. // Output
  17. imagejpeg($thumb);
  18. ?>
复制代码


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

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|AI 社区

GMT+8, 2023-6-2 09:26 , Processed in 0.021902 second(s), 20 queries .

Copyright © 2021 AI 社区

快速回复 返回顶部 返回列表