Image Thumbnail with GD & GET vars


/ Published in: PHP
Save to your folder(s)

example: thumb.php?p=image.jpg&s=45


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.