A tumblelog CMS built on AJAX, PHP and MySQL.

imgsize.php 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. if (!defined('entry')) {
  3. define('entry', true);
  4. }
  5. $img = @$_GET['img'];
  6. $w = @$_GET['w'];
  7. $h = @$_GET['h'];
  8. $x = getimagesize($img);
  9. $sw = $x[0];
  10. $sh = $x[1];
  11. if (isset($w) and !isset($h)) {
  12. $h = (100 / ($sw / $w)) * .01;
  13. $h = @round($sh * $h);
  14. } elseif (isset($h) and !isset($w)) {
  15. $w = (100 / ($sh / $h)) * .01;
  16. $w = @round($sw * $w);
  17. }
  18. $imgext = pathinfo($img, PATHINFO_EXTENSION);
  19. switch ($imgext) {
  20. case 'png':
  21. header("Content-type: image/png");
  22. $s_img = imagecreatefrompng($img);
  23. break;
  24. case 'jpg':
  25. case 'jpeg':
  26. header("Content-type: image/jpeg");
  27. $s_img = imagecreatefromjpeg($img);
  28. break;
  29. case 'gif':
  30. header("Content-type: image/gif");
  31. $s_img = imagecreatefromgif($img);
  32. break;
  33. default:
  34. readfile($img);
  35. exit();
  36. break;
  37. }
  38. $d_img = imagecreatetruecolor($w, $h);
  39. $sw = imagesx($s_img);
  40. $sh = imagesy($s_img);
  41. $dw = imagesx($d_img);
  42. $dh = imagesy($d_img);
  43. imagecopyresampled($d_img, $s_img, 0, 0, 0, 0, $dw, $dh, $sw, $sh);
  44. switch ($imgext) {
  45. case 'png':
  46. imagepng($d_img);
  47. break;
  48. case 'jpg':
  49. case 'jpeg':
  50. imagejpeg($d_img);
  51. break;
  52. case 'gif':
  53. imagegif($d_img);
  54. break;
  55. default:
  56. readfile($img);
  57. exit();
  58. break;
  59. }