Advertisement
Guest User

Untitled

a guest
Aug 21st, 2012
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.28 KB | None | 0 0
  1. <?php
  2.  
  3. require_once "SimpleImage.class.php";
  4.  
  5. header("Content-Type: image/jpg");
  6.  
  7. if(file_exists($_GET["src"]) === false) {
  8.     header("HTTP/1.0 404 Not Found");
  9.     die();
  10. }
  11.  
  12. $existingSize = false;
  13. $maxWidth = +($_GET["width"]);
  14. $maxHeight = +($_GET["height"]);
  15. $filenameParts = pathinfo($_GET["src"]);
  16. $resizedNameTpl = "%s/%s_%ux%u.%s";
  17. $image = new SimpleImage($_GET["src"]);
  18.  
  19. if($image->getWidth() > $image->getHeight()) {
  20.     $ratio = $maxWidth / $image->getWidth();
  21.     $newHeight = $image->getHeight() * $ratio;
  22.     $resizedName = sprintf(
  23.         $resizedNameTpl,
  24.         $filenameParts["dirname"],
  25.         $filenameParts["filename"],
  26.         $maxWidth,
  27.         $newHeight,
  28.         $filenameParts["extension"]
  29.     );
  30.     $existingSize = file_exists($resizedName);
  31.  
  32.     if(!$existingSize) {
  33.         $image->resizeToWidth($maxWidth);
  34.     }
  35. }
  36. else {
  37.     $ratio = $maxHeight / $image->getHeight();
  38.     $newWidth = $image->getWidth() * $ratio;
  39.     $resizedName = sprintf(
  40.         $resizedNameTpl,
  41.         $filenameParts["dirname"],
  42.         $filenameParts["filename"],
  43.         $newWidth,
  44.         $maxHeight,
  45.         $filenameParts["extension"]
  46.     );
  47.     $existingSize = file_exists($resizedName);
  48.  
  49.     if(!$existingSize) {
  50.         $image->resizeToHeight($maxHeight);
  51.     }
  52. }
  53.  
  54. if(!$existingSize) {
  55.     $image->save($resizedName);
  56. }
  57.  
  58. echo file_get_contents($resizedName);
  59.  
  60. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement