PageRenderTime 32ms CodeModel.GetById 5ms RepoModel.GetById 0ms app.codeStats 0ms

/image_thumbnail_s.php

http://github.com/MightyGorgon/icy_phoenix
PHP | 152 lines | 107 code | 21 blank | 24 comment | 17 complexity | 45c9b156e5c250bb4aa6abcea4e7eefb MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package Icy Phoenix
  5. * @version $Id$
  6. * @copyright (c) 2008 Icy Phoenix
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. define('IMG_THUMB', true);
  11. define('CT_SECLEVEL', 'MEDIUM');
  12. $ct_ignoregvar = array('');
  13. define('IN_ICYPHOENIX', true);
  14. if (!defined('IP_ROOT_PATH')) define('IP_ROOT_PATH', './');
  15. if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
  16. include(IP_ROOT_PATH . 'common.' . PHP_EXT);
  17. // Start session management
  18. $user->session_begin();
  19. $auth->acl($user->data);
  20. $user->setup();
  21. // End session management
  22. require(IP_ROOT_PATH . 'includes/class_image.' . PHP_EXT);
  23. include(IP_ROOT_PATH . 'includes/class_images.' . PHP_EXT);
  24. $class_images = new class_images();
  25. // ------------------------------------
  26. // Check the request
  27. // ------------------------------------
  28. $pic_id = request_var('pic_id', '');
  29. if (empty($pic_id))
  30. {
  31. image_no_thumbnail('no_thumb.jpg');
  32. exit;
  33. //die($lang['NO_PICS_SPECIFIED']);
  34. //message_die(GENERAL_MESSAGE, $lang['NO_PICS_SPECIFIED']);
  35. }
  36. $pic_id = urldecode($pic_id);
  37. $tmp_split = explode('/', $pic_id);
  38. $pic_user_id = intval((int) $tmp_split[0]);
  39. if ($pic_user_id < 0)
  40. {
  41. image_no_thumbnail('no_thumb.jpg');
  42. exit;
  43. //message_die(GENERAL_MESSAGE, $lang['NO_PICS_SPECIFIED']);
  44. }
  45. $pic_filename = $tmp_split[1];
  46. $pic_fullpath = POSTED_IMAGES_PATH . $pic_user_id . '/' . $pic_filename;
  47. $pic_thumbnail = 'thumb_' . $pic_filename;
  48. $pic_thumbnail_fullpath = POSTED_IMAGES_THUMBS_S_PATH . $pic_thumbnail;
  49. $file_part = explode('.', strtolower($pic_filename));
  50. $pic_filetype = $file_part[sizeof($file_part) - 1];
  51. $pic_title = substr($pic_filename, 0, strlen($pic_filename) - strlen($pic_filetype) - 1);
  52. $pic_title_reg = preg_replace('/[^A-Za-z0-9]+/', '_', $pic_title);
  53. if (USERS_SUBFOLDERS_IMG == true)
  54. {
  55. $pic_thumbnail_prefix = '';
  56. $pic_thumbnail_path = POSTED_IMAGES_THUMBS_S_PATH . $pic_user_id . '/';
  57. $thumbnail_data = $class_images->get_thumbnail_data($pic_thumbnail_path, $pic_thumbnail, $pic_thumbnail_fullpath, $pic_filename, $pic_thumbnail_prefix);
  58. $pic_thumbnail = $thumbnail_data['thumbnail'];
  59. $pic_thumbnail_fullpath = $thumbnail_data['full_path'];
  60. }
  61. if (!in_array($pic_filetype, array('gif', 'jpg', 'jpeg', 'png')))
  62. {
  63. image_no_thumbnail('thumb_' . $pic_title_reg . '.' . $pic_filetype);
  64. exit;
  65. }
  66. // --------------------------------
  67. // Check thumbnail cache. If cache is available we will SEND & EXIT
  68. // --------------------------------
  69. if(!empty($config['thumbnail_cache']) && file_exists($pic_thumbnail_fullpath))
  70. {
  71. image_output($pic_thumbnail_fullpath, $pic_title_reg, $pic_filetype, 'thumb_');
  72. exit;
  73. }
  74. if(!@file_exists($pic_fullpath))
  75. {
  76. image_no_thumbnail('no_thumb.jpg');
  77. exit;
  78. //message_die(GENERAL_MESSAGE, $lang['Pic_not_exist']);
  79. }
  80. $pic_size = @getimagesize($pic_fullpath);
  81. $pic_width = $pic_size[0];
  82. $pic_height = $pic_size[1];
  83. if(($pic_width < $config['thumbnail_s_size']) && ($pic_height < $config['thumbnail_s_size']))
  84. {
  85. $copy_success = @copy($pic_fullpath, $pic_thumbnail_fullpath);
  86. @chmod($pic_thumbnail_fullpath, 0777);
  87. image_output($pic_fullpath, $pic_title_reg, $pic_filetype, 'thumb_');
  88. exit;
  89. }
  90. else
  91. {
  92. // --------------------------------
  93. // Cache is empty. Try to re-generate!
  94. // --------------------------------
  95. if ($pic_width > $pic_height)
  96. {
  97. $thumbnail_width = $config['thumbnail_s_size'];
  98. $thumbnail_height = $config['thumbnail_s_size'] * ($pic_height / $pic_width);
  99. }
  100. else
  101. {
  102. $thumbnail_height = $config['thumbnail_s_size'];
  103. $thumbnail_width = $config['thumbnail_s_size'] * ($pic_width / $pic_height);
  104. }
  105. $Image = new ImgObj();
  106. $Image->ReadSourceFile($pic_fullpath);
  107. $Image->Resize($thumbnail_width, $thumbnail_height);
  108. if (!empty($config['show_pic_size_on_thumb']))
  109. {
  110. $dimension_string = intval($pic_width) . 'x' . intval($pic_height) . '(' . intval(filesize($pic_fullpath) / 1024) . 'KB)';
  111. $Image->Text($dimension_string);
  112. }
  113. if (!empty($config['thumbnail_cache']))
  114. {
  115. $Image->SendToFile($pic_thumbnail_fullpath, $config['thumbnail_quality']);
  116. //@chmod($pic_thumbnail_fullpath, 0777);
  117. }
  118. $Image->SendToBrowser($pic_title_reg, $pic_filetype, 'thumb_', '', $config['thumbnail_quality']);
  119. if ($Image == true)
  120. {
  121. $Image->Destroy();
  122. exit;
  123. }
  124. else
  125. {
  126. $Image->Destroy();
  127. image_no_thumbnail('thumb_' . $pic_title_reg . '.' . $pic_filetype);
  128. exit;
  129. }
  130. }
  131. ?>