Contributing back some bug fixes

image.php 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?
  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. header('Content-type: image/gif');
  15. die(file_get_contents(SERVER_ROOT.'/sections/image/err_imgs/'.$Type.'.png'));
  16. }
  17. function invisible($Image) {
  18. $Count = imagecolorstotal($Image);
  19. if ($Count == 0) {
  20. return false;
  21. }
  22. $TotalAlpha = 0;
  23. for ($i = 0; $i < $Count; ++$i) {
  24. $Color = imagecolorsforindex($Image, $i);
  25. $TotalAlpha += $Color['alpha'];
  26. }
  27. return (($TotalAlpha / $Count) == 127);
  28. }
  29. function verysmall($Image) {
  30. return ((imagesx($Image) * imagesy($Image)) < 25);
  31. }
  32. function image_type($Data) {
  33. if (!strncmp($Data, 'GIF', 3)) {
  34. return 'gif';
  35. }
  36. if (!strncmp($Data, pack('H*', '89504E47'), 4)) {
  37. return 'png';
  38. }
  39. if (!strncmp($Data, pack('H*', 'FFD8'), 2)) {
  40. return 'jpeg';
  41. }
  42. if (!strncmp($Data, 'BM', 2)) {
  43. return 'bmp';
  44. }
  45. if (!strncmp($Data, 'II', 2) || !strncmp($Data, 'MM', 2)) {
  46. return 'tiff';
  47. }
  48. if (!substr_compare($Data, 'webm', 31, 4)) {
  49. return 'webm';
  50. }
  51. }
  52. function image_height($Type, $Data) {
  53. $Length = strlen($Data);
  54. global $URL, $_GET;
  55. switch ($Type) {
  56. case 'jpeg':
  57. // See http://www.obrador.com/essentialjpeg/headerinfo.htm
  58. $i = 4;
  59. $Data = (substr($Data, $i));
  60. $Block = unpack('nLength', $Data);
  61. $Data = substr($Data, $Block['Length']);
  62. $i += $Block['Length'];
  63. $Str []= "Started 4, + ".$Block['Length'];
  64. while ($Data != '') { // iterate through the blocks until we find the start of frame marker (FFC0)
  65. $Block = unpack('CBlock/CType/nLength', $Data); // Get info about the block
  66. if ($Block['Block'] != '255') { // We should be at the start of a new block
  67. break;
  68. }
  69. if ($Block['Type'] != '192') { // C0
  70. $Data = substr($Data, $Block['Length'] + 2); // Next block
  71. $Str []= "Started $i, + ".($Block['Length'] + 2);
  72. $i += ($Block['Length'] + 2);
  73. } else { // We're at the FFC0 block
  74. $Data = substr($Data, 5); // Skip FF C0 Length(2) precision(1)
  75. $i += 5;
  76. $Height = unpack('nHeight', $Data);
  77. return $Height['Height'];
  78. }
  79. }
  80. break;
  81. case 'gif':
  82. $Data = substr($Data, 8);
  83. $Height = unpack('vHeight', $Data);
  84. return $Height['Height'];
  85. case 'png':
  86. $Data = substr($Data, 20);
  87. $Height = unpack('NHeight', $Data);
  88. return $Height['Height'];
  89. default:
  90. return 0;
  91. }
  92. }
  93. define('SKIP_NO_CACHE_HEADERS', 1);
  94. require('classes/script_start.php'); // script_start contains all we need and includes sections/image/index.php
  95. ?>