使用GD&GET vars的图像缩略图

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用GD&GET vars的图像缩略图相关的知识,希望对你有一定的参考价值。

example: thumb.php?p=image.jpg&s=45
  1. <?php
  2. require_once "Image/Transform/Driver/GD.php";
  3.  
  4. if(isset($_GET['p']) && isset($_GET['s'])) {
  5. $path = "thumbs/".$_GET['p'];
  6. $sideSize = (int)$_GET['s'];
  7.  
  8. $image = new Image_Transform_Driver_GD();
  9. $image->load($path);
  10.  
  11. if($image->getImageWidth() > $image->getImageHeight()) {
  12. $image->scaleByY($sideSize);
  13. $result = $image->crop($sideSize, $sideSize, ($image->new_x - $sideSize)/2, 0);
  14. } else {
  15. $image->scaleByX($sideSize);
  16. $image->crop($sideSize, $sideSize, 0, ($image->new_y - $sideSize)/2);
  17. }
  18.  
  19. $image->display();
  20. } else {
  21. trigger_error("Bad GET vars");
  22. }
  23. ?>

以上是关于使用GD&GET vars的图像缩略图的主要内容,如果未能解决你的问题,请参考以下文章