Posted By

iloveitaly on 05/19/07


Tagged

php image gd thumbnail thumb picture


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

luman


Image Thumbnail with GD & GET vars


 / Published in: PHP
 

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. ?>

Report this snippet  

You need to login to post a comment.