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.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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('Please install and enable the GD Graphics Library.');
  13. }
  14. /**
  15. * img_error
  16. */
  17. function img_error($Type)
  18. {
  19. $ENV = ENV::go();
  20. header('Content-type: image/gif');
  21. error(file_get_contents("$ENV->SERVER_ROOT/sections/image/err_imgs/$Type.png"));
  22. }
  23. /**
  24. * invisible
  25. */
  26. function invisible($Image)
  27. {
  28. $Count = imagecolorstotal($Image);
  29. if ($Count === 0) {
  30. return false;
  31. }
  32. $TotalAlpha = 0;
  33. for ($i = 0; $i < $Count; ++$i) {
  34. $Color = imagecolorsforindex($Image, $i);
  35. $TotalAlpha += $Color['alpha'];
  36. }
  37. return (($TotalAlpha / $Count) === 127);
  38. }
  39. /**
  40. * verysmall
  41. */
  42. function verysmall($Image)
  43. {
  44. return ((imagesx($Image) * imagesy($Image)) < 25);
  45. }
  46. /**
  47. * image_type
  48. */
  49. function image_type($Data)
  50. {
  51. if (!strncmp($Data, 'GIF', 3)) {
  52. return 'gif';
  53. }
  54. if (!strncmp($Data, pack('H*', '89504E47'), 4)) {
  55. return 'png';
  56. }
  57. if (!strncmp($Data, pack('H*', 'FFD8'), 2)) {
  58. return 'jpeg';
  59. }
  60. if (!strncmp($Data, 'BM', 2)) {
  61. return 'bmp';
  62. }
  63. if (!strncmp($Data, 'II', 2) || !strncmp($Data, 'MM', 2)) {
  64. return 'tiff';
  65. }
  66. if (!substr_compare($Data, 'webm', 31, 4)) {
  67. return 'webm';
  68. }
  69. }
  70. /**
  71. * image_height
  72. */
  73. function image_height($Type, $Data)
  74. {
  75. global $URL, $_GET;
  76. $Length = strlen($Data);
  77. switch ($Type) {
  78. case 'jpeg':
  79. # https://www.geocities.ws/crestwoodsdd/JPEG.htm
  80. $i = 4;
  81. $Data = (substr($Data, $i));
  82. $Block = unpack('nLength', $Data);
  83. $Data = substr($Data, $Block['Length']);
  84. $i += $Block['Length'];
  85. $Str []= 'Started 4, + '.$Block['Length'];
  86. # Iterate through the blocks until we find the start of frame marker (FFC0)
  87. while ($Data !== '') {
  88. # Get info about the block
  89. $Block = unpack('CBlock/CType/nLength', $Data);
  90. # We should be at the start of a new block
  91. if ($Block['Block'] !== '255') {
  92. break;
  93. }
  94. if ($Block['Type'] !== '192') { # C0
  95. $Data = substr($Data, $Block['Length'] + 2); # Next block
  96. $Str []= 'Started $i, + '.($Block['Length'] + 2);
  97. $i += ($Block['Length'] + 2);
  98. }
  99. # We're at the FFC0 block
  100. else {
  101. # Skip FF C0 Length(2) precision(1)
  102. $Data = substr($Data, 5);
  103. $i += 5;
  104. $Height = unpack('nHeight', $Data);
  105. return $Height['Height'];
  106. }
  107. }
  108. break;
  109. case 'gif':
  110. $Data = substr($Data, 8);
  111. $Height = unpack('vHeight', $Data);
  112. return $Height['Height'];
  113. case 'png':
  114. $Data = substr($Data, 20);
  115. $Height = unpack('NHeight', $Data);
  116. return $Height['Height'];
  117. default:
  118. return 0;
  119. }
  120. }
  121. # script_start.php contains all we need and includes sections/image/index.php
  122. require_once 'classes/script_start.php';