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

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