Просмотр файла gallery/resize.php

Размер файла: 4.53Kb
  1. <?php
  2. #-----------------------------------------------------#
  3. # ********* ROTORCMS ********* #
  4. # Made by : VANTUZ #
  5. # E-mail : visavi.net@mail.ru #
  6. # Site : http://pizdec.ru #
  7. # WAP-Site : http://visavi.net #
  8. # ICQ : 36-44-66 #
  9. # Вы не имеете право вносить изменения в код скрипта #
  10. # для его дальнейшего распространения #
  11. #-----------------------------------------------------#
  12. require_once ('../includes/start.php');
  13. require_once ('../includes/functions.php');
  14.  
  15. if (isset($_GET['dir'])) {
  16. $dir = check($_GET['dir']);
  17. } else {
  18. $dir = "";
  19. }
  20. if (isset($_GET['name'])) {
  21. $name = check($_GET['name']);
  22. } else {
  23. $name = "";
  24. }
  25.  
  26. if (preg_match('|^[a-z0-9_\-/]+$|i', $dir) && preg_match('|^[a-z0-9_\.\-]+$|i', $name)) {
  27. if (file_exists(BASEDIR . $dir . '/' . $name)) {
  28. $getim = getimagesize(BASEDIR . $dir . '/' . $name);
  29.  
  30. if ($getim[2] == 1 || $getim[2] == 2 || $getim[2] == 3) {
  31. $width = $getim[0];
  32. $height = $getim[1];
  33.  
  34. if ($width > $config['previewsize'] || $height > $config['previewsize']) {
  35. $x_ratio = $config['previewsize'] / $width;
  36. $y_ratio = $config['previewsize'] / $height;
  37.  
  38. if (($x_ratio * $height) < $config['previewsize']) {
  39. $tn_height = ceil($x_ratio * $height);
  40. $tn_width = $config['previewsize'];
  41. } else {
  42. $tn_width = ceil($y_ratio * $width);
  43. $tn_height = $config['previewsize'];
  44. }
  45. // -------------------------------//
  46. if ($getim[2] == 2) {
  47. $img = imagecreatefromjpeg(BASEDIR . $dir . '/' . $name);
  48. $dst = imagecreatetruecolor($tn_width, $tn_height);
  49. imagecopyresampled($dst, $img, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
  50.  
  51. header('content-type: image/jpeg');
  52. header('Content-Disposition: filename="' . $name . '"');
  53. imagejpeg ($dst, null, 75);
  54. imagedestroy($img);
  55. imagedestroy($dst);
  56. }
  57. // -------------------------------//
  58. if ($getim[2] == 1) {
  59. $img = imagecreatefromgif(BASEDIR . $dir . '/' . $name);
  60. $dst = imagecreatetruecolor($tn_width, $tn_height);
  61.  
  62. $colorTransparent = imagecolortransparent($img);
  63. imagepalettecopy($img, $dst);
  64. imagefill($dst, 0, 0, $colorTransparent);
  65. imagecolortransparent($dst, $colorTransparent);
  66. imagetruecolortopalette($dst, true, 256);
  67.  
  68. imagecopyresampled($dst, $img, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
  69.  
  70. header('content-type: image/gif');
  71. header('Content-Disposition: filename="' . $name . '"');
  72. imagegif ($dst);
  73. imagedestroy($img);
  74. imagedestroy($dst);
  75. }
  76. // -------------------------------//
  77. if ($getim[2] == 3) {
  78. $img = imagecreatefrompng(BASEDIR . $dir . '/' . $name);
  79. $dst = imagecreatetruecolor($tn_width, $tn_height);
  80.  
  81. $colorTransparent = imagecolortransparent($img);
  82. imagepalettecopy($img, $dst);
  83. imagefill($dst, 0, 0, $colorTransparent);
  84. imagecolortransparent($dst, $colorTransparent);
  85. imagetruecolortopalette($dst, true, 256);
  86.  
  87. imagecopyresampled($dst, $img, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
  88.  
  89. header('content-type: image/png');
  90. header('Content-Disposition: filename="' . $name . '"');
  91. imagepng ($dst);
  92. imagedestroy($img);
  93. imagedestroy($dst);
  94. }
  95. } else {
  96. $filename = file_get_contents(BASEDIR . $dir . '/' . $name);
  97. header('Content-type: ' . $getim['mime']);
  98. header('Content-Disposition: filename="' . $name . '"');
  99. header('Content-Length: ' . strlen($filename));
  100. echo $filename;
  101. }
  102. }
  103. }
  104. }
  105.  
  106. exit;
  107.  
  108. ?>