BioTorrents.de’s version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

image.php 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. // Functions and headers needed by the image proxy
  3. error_reporting(E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR);
  4. if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
  5. header('HTTP/1.1 304 Not Modified');
  6. die();
  7. }
  8. header('Expires: '.date('D, d-M-Y H:i:s \U\T\C', time() + 3600 * 24 * 120)); // 120 days
  9. header('Last-Modified: '.date('D, d-M-Y H:i:s \U\T\C', time()));
  10. if (!extension_loaded('gd')) {
  11. error('nogd');
  12. }
  13. function img_error($Type)
  14. {
  15. header('Content-type: image/gif');
  16. die(file_get_contents(SERVER_ROOT.'/sections/image/err_imgs/'.$Type.'.png'));
  17. }
  18. function invisible($Image)
  19. {
  20. $Count = imagecolorstotal($Image);
  21. if ($Count === 0) {
  22. return false;
  23. }
  24. $TotalAlpha = 0;
  25. for ($i = 0; $i < $Count; ++$i) {
  26. $Color = imagecolorsforindex($Image, $i);
  27. $TotalAlpha += $Color['alpha'];
  28. }
  29. return (($TotalAlpha / $Count) === 127);
  30. }
  31. function verysmall($Image)
  32. {
  33. return ((imagesx($Image) * imagesy($Image)) < 25);
  34. }
  35. function image_type($Data)
  36. {
  37. if (!strncmp($Data, 'GIF', 3)) {
  38. return 'gif';
  39. }
  40. if (!strncmp($Data, pack('H*', '89504E47'), 4)) {
  41. return 'png';
  42. }
  43. if (!strncmp($Data, pack('H*', 'FFD8'), 2)) {
  44. return 'jpeg';
  45. }
  46. if (!strncmp($Data, 'BM', 2)) {
  47. return 'bmp';
  48. }
  49. if (!strncmp($Data, 'II', 2) || !strncmp($Data, 'MM', 2)) {
  50. return 'tiff';
  51. }
  52. if (!substr_compare($Data, 'webm', 31, 4)) {
  53. return 'webm';
  54. }
  55. }
  56. function image_height($Type, $Data)
  57. {
  58. $Length = strlen($Data);
  59. global $URL, $_GET;
  60. switch ($Type) {
  61. case 'jpeg':
  62. // See http://www.obrador.com/essentialjpeg/headerinfo.htm
  63. $i = 4;
  64. $Data = (substr($Data, $i));
  65. $Block = unpack('nLength', $Data);
  66. $Data = substr($Data, $Block['Length']);
  67. $i += $Block['Length'];
  68. $Str []= 'Started 4, + '.$Block['Length'];
  69. while ($Data !== '') { // Iterate through the blocks until we find the start of frame marker (FFC0)
  70. $Block = unpack('CBlock/CType/nLength', $Data); // Get info about the block
  71. if ($Block['Block'] !== '255') { // We should be at the start of a new block
  72. break;
  73. }
  74. if ($Block['Type'] !== '192') { // C0
  75. $Data = substr($Data, $Block['Length'] + 2); // Next block
  76. $Str []= 'Started $i, + '.($Block['Length'] + 2);
  77. $i += ($Block['Length'] + 2);
  78. } else { // We're at the FFC0 block
  79. $Data = substr($Data, 5); // Skip FF C0 Length(2) precision(1)
  80. $i += 5;
  81. $Height = unpack('nHeight', $Data);
  82. return $Height['Height'];
  83. }
  84. }
  85. break;
  86. case 'gif':
  87. $Data = substr($Data, 8);
  88. $Height = unpack('vHeight', $Data);
  89. return $Height['Height'];
  90. case 'png':
  91. $Data = substr($Data, 20);
  92. $Height = unpack('NHeight', $Data);
  93. return $Height['Height'];
  94. default:
  95. return 0;
  96. }
  97. }
  98. define('SKIP_NO_CACHE_HEADERS', 1);
  99. require 'classes/script_start.php'; // script_start.php contains all we need and includes sections/image/index.php