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