Andrey Andreev | a92b903 | 2011-12-24 19:05:58 +0200 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Phil Sturgeon | 07c1ac8 | 2012-03-09 17:03:37 +0000 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.2.4 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
Eric Barnes | b167336 | 2011-12-05 22:05:38 -0500 | [diff] [blame] | 8 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 9 | * Licensed under the Open Software License version 3.0 |
Eric Barnes | b167336 | 2011-12-05 22:05:38 -0500 | [diff] [blame] | 10 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 11 | * This source file is subject to the Open Software License (OSL 3.0) that is |
Andrey Andreev | a3d19c4 | 2012-01-24 15:29:29 +0200 | [diff] [blame] | 12 | * bundled with this package in the files license.txt / license.rst. It is |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 13 | * also available through the world wide web at this URL: |
| 14 | * http://opensource.org/licenses/OSL-3.0 |
| 15 | * If you did not receive a copy of the license and are unable to obtain it |
| 16 | * through the world wide web, please send an email to |
| 17 | * licensing@ellislab.com so we can send you a copy immediately. |
| 18 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
Greg Aker | 0defe5d | 2012-01-01 18:46:41 -0600 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 1.0 |
| 25 | * @filesource |
| 26 | */ |
| 27 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 28 | /** |
| 29 | * Image Manipulation class |
| 30 | * |
| 31 | * @package CodeIgniter |
| 32 | * @subpackage Libraries |
| 33 | * @category Image_lib |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 34 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 35 | * @link http://codeigniter.com/user_guide/libraries/image_lib.html |
| 36 | */ |
| 37 | class CI_Image_lib { |
| 38 | |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 39 | /** |
| 40 | * PHP extension/library to use for image manipulation |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 41 | * Can be: imagemagick, netpbm, gd, gd2 |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 42 | * |
| 43 | * @var string |
| 44 | */ |
| 45 | public $image_library = 'gd2'; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 46 | |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 47 | /** |
| 48 | * Path to the graphic library (if applicable) |
| 49 | * |
| 50 | * @var string |
| 51 | */ |
Andrey Andreev | 3a45957 | 2011-12-21 11:23:11 +0200 | [diff] [blame] | 52 | public $library_path = ''; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 53 | |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 54 | /** |
| 55 | * Whether to send to browser or write to disk |
| 56 | * |
| 57 | * @var bool |
| 58 | */ |
| 59 | public $dynamic_output = FALSE; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 60 | |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 61 | /** |
| 62 | * Path to original image |
| 63 | * |
| 64 | * @var string |
| 65 | */ |
Andrey Andreev | 3a45957 | 2011-12-21 11:23:11 +0200 | [diff] [blame] | 66 | public $source_image = ''; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 67 | |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 68 | /** |
| 69 | * Path to the modified image |
| 70 | * |
| 71 | * @var string |
| 72 | */ |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 73 | public $new_image = ''; |
| 74 | |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 75 | /** |
| 76 | * Image width |
| 77 | * |
| 78 | * @var int |
| 79 | */ |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 80 | public $width = ''; |
| 81 | |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 82 | /** |
| 83 | * Image height |
| 84 | * |
| 85 | * @var int |
| 86 | */ |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 87 | public $height = ''; |
| 88 | |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 89 | /** |
| 90 | * Quality percentage of new image |
| 91 | * |
| 92 | * @var int |
| 93 | */ |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 94 | public $quality = 90; |
| 95 | |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 96 | /** |
| 97 | * Whether to create a thumbnail |
| 98 | * |
| 99 | * @var bool |
| 100 | */ |
Andrey Andreev | 3a45957 | 2011-12-21 11:23:11 +0200 | [diff] [blame] | 101 | public $create_thumb = FALSE; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 102 | |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 103 | /** |
| 104 | * String to add to thumbnail version of image |
| 105 | * |
| 106 | * @var string |
| 107 | */ |
Andrey Andreev | 3a45957 | 2011-12-21 11:23:11 +0200 | [diff] [blame] | 108 | public $thumb_marker = '_thumb'; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 109 | |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 110 | /** |
| 111 | * Whether to maintain aspect ratio when resizing or use hard values |
| 112 | * |
| 113 | * @var bool |
| 114 | */ |
| 115 | public $maintain_ratio = TRUE; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 116 | |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 117 | /** |
| 118 | * auto, height, or width. Determines what to use as the master dimension |
| 119 | * |
| 120 | * @var string |
| 121 | */ |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 122 | public $master_dim = 'auto'; |
| 123 | |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 124 | /** |
| 125 | * Angle at to rotate image |
| 126 | * |
| 127 | * @var string |
| 128 | */ |
Andrey Andreev | 3a45957 | 2011-12-21 11:23:11 +0200 | [diff] [blame] | 129 | public $rotation_angle = ''; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 130 | |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 131 | /** |
| 132 | * X Coordinate for manipulation of the current image |
| 133 | * |
| 134 | * @var int |
| 135 | */ |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 136 | public $x_axis = ''; |
| 137 | |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 138 | /** |
| 139 | * Y Coordinate for manipulation of the current image |
| 140 | * |
| 141 | * @var int |
| 142 | */ |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 143 | public $y_axis = ''; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 144 | |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 145 | // -------------------------------------------------------------------------- |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 146 | // Watermark Vars |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 147 | // -------------------------------------------------------------------------- |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 148 | |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 149 | /** |
| 150 | * Watermark text if graphic is not used |
| 151 | * |
| 152 | * @var string |
| 153 | */ |
| 154 | public $wm_text = ''; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 155 | |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 156 | /** |
| 157 | * Type of watermarking. Options: text/overlay |
| 158 | * |
| 159 | * @var string |
| 160 | */ |
| 161 | public $wm_type = 'text'; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 162 | |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 163 | /** |
Timothy Warren | b82bc3a | 2012-04-27 09:12:58 -0400 | [diff] [blame] | 164 | * Default transparency for watermark |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 165 | * |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 166 | * @var int |
| 167 | */ |
Andrey Andreev | 3a45957 | 2011-12-21 11:23:11 +0200 | [diff] [blame] | 168 | public $wm_x_transp = 4; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 169 | |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 170 | /** |
Timothy Warren | b82bc3a | 2012-04-27 09:12:58 -0400 | [diff] [blame] | 171 | * Default transparency for watermark |
| 172 | * |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 173 | * @var int |
| 174 | */ |
Andrey Andreev | 3a45957 | 2011-12-21 11:23:11 +0200 | [diff] [blame] | 175 | public $wm_y_transp = 4; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 176 | |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 177 | /** |
| 178 | * Watermark image path |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 179 | * |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 180 | * @var string |
| 181 | */ |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 182 | public $wm_overlay_path = ''; |
| 183 | |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 184 | /** |
| 185 | * TT font |
| 186 | * |
| 187 | * @var string |
| 188 | */ |
| 189 | public $wm_font_path = ''; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 190 | |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 191 | /** |
| 192 | * Font size (different versions of GD will either use points or pixels) |
| 193 | * |
| 194 | * @var int |
| 195 | */ |
| 196 | public $wm_font_size = 17; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 197 | |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 198 | /** |
| 199 | * Vertical alignment: T M B |
| 200 | * |
| 201 | * @var string |
| 202 | */ |
| 203 | public $wm_vrt_alignment = 'B'; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 204 | |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 205 | /** |
| 206 | * Horizontal alignment: L R C |
| 207 | * |
| 208 | * @var string |
| 209 | */ |
| 210 | public $wm_hor_alignment = 'C'; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 211 | |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 212 | /** |
| 213 | * Padding around text |
| 214 | * |
| 215 | * @var int |
| 216 | */ |
| 217 | public $wm_padding = 0; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 218 | |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 219 | /** |
| 220 | * Lets you push text to the right |
| 221 | * |
| 222 | * @var int |
| 223 | */ |
| 224 | public $wm_hor_offset = 0; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 225 | |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 226 | /** |
| 227 | * Lets you push text down |
| 228 | * |
| 229 | * @var int |
| 230 | */ |
| 231 | public $wm_vrt_offset = 0; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 232 | |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 233 | /** |
| 234 | * Text color |
| 235 | * |
| 236 | * @var string |
| 237 | */ |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 238 | protected $wm_font_color = '#ffffff'; |
| 239 | |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 240 | /** |
| 241 | * Dropshadow color |
| 242 | * |
| 243 | * @var string |
| 244 | */ |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 245 | protected $wm_shadow_color = ''; |
| 246 | |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 247 | /** |
| 248 | * Dropshadow distance |
| 249 | * |
| 250 | * @var int |
| 251 | */ |
| 252 | public $wm_shadow_distance = 2; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 253 | |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 254 | /** |
| 255 | * Image opacity: 1 - 100 Only works with image |
| 256 | * |
| 257 | * @var int |
| 258 | */ |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 259 | public $wm_opacity = 50; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 260 | |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 261 | // -------------------------------------------------------------------------- |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 262 | // Private Vars |
Timothy Warren | b8e6285 | 2012-04-26 18:40:54 -0400 | [diff] [blame] | 263 | // -------------------------------------------------------------------------- |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 264 | |
Timothy Warren | b82bc3a | 2012-04-27 09:12:58 -0400 | [diff] [blame] | 265 | /** |
| 266 | * Source image folder |
| 267 | * |
| 268 | * @var string |
| 269 | */ |
Andrey Andreev | 3a45957 | 2011-12-21 11:23:11 +0200 | [diff] [blame] | 270 | public $source_folder = ''; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 271 | |
Timothy Warren | b82bc3a | 2012-04-27 09:12:58 -0400 | [diff] [blame] | 272 | /** |
| 273 | * Destination image folder |
| 274 | * |
| 275 | * @var string |
| 276 | */ |
Andrey Andreev | 3a45957 | 2011-12-21 11:23:11 +0200 | [diff] [blame] | 277 | public $dest_folder = ''; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 278 | |
Timothy Warren | b82bc3a | 2012-04-27 09:12:58 -0400 | [diff] [blame] | 279 | /** |
| 280 | * Image mime-type |
| 281 | * |
| 282 | * @var string |
| 283 | */ |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 284 | public $mime_type = ''; |
| 285 | |
Timothy Warren | b82bc3a | 2012-04-27 09:12:58 -0400 | [diff] [blame] | 286 | /** |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 287 | * Original image width |
Timothy Warren | b82bc3a | 2012-04-27 09:12:58 -0400 | [diff] [blame] | 288 | * |
| 289 | * @var int |
| 290 | */ |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 291 | public $orig_width = ''; |
| 292 | |
Timothy Warren | b82bc3a | 2012-04-27 09:12:58 -0400 | [diff] [blame] | 293 | /** |
| 294 | * Original image height |
| 295 | * |
| 296 | * @var int |
| 297 | */ |
Andrey Andreev | 3a45957 | 2011-12-21 11:23:11 +0200 | [diff] [blame] | 298 | public $orig_height = ''; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 299 | |
Timothy Warren | b82bc3a | 2012-04-27 09:12:58 -0400 | [diff] [blame] | 300 | /** |
| 301 | * Image format |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 302 | * |
Timothy Warren | b82bc3a | 2012-04-27 09:12:58 -0400 | [diff] [blame] | 303 | * @var string |
| 304 | */ |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 305 | public $image_type = ''; |
| 306 | |
Timothy Warren | b82bc3a | 2012-04-27 09:12:58 -0400 | [diff] [blame] | 307 | /** |
| 308 | * Size of current image |
| 309 | * |
| 310 | * @var string |
| 311 | */ |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 312 | public $size_str = ''; |
| 313 | |
Timothy Warren | b82bc3a | 2012-04-27 09:12:58 -0400 | [diff] [blame] | 314 | /** |
| 315 | * Full path to source image |
| 316 | * |
| 317 | * @var string |
| 318 | */ |
Andrey Andreev | 3a45957 | 2011-12-21 11:23:11 +0200 | [diff] [blame] | 319 | public $full_src_path = ''; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 320 | |
Timothy Warren | b82bc3a | 2012-04-27 09:12:58 -0400 | [diff] [blame] | 321 | /** |
| 322 | * Full path to destination image |
| 323 | * |
| 324 | * @var string |
| 325 | */ |
Andrey Andreev | 3a45957 | 2011-12-21 11:23:11 +0200 | [diff] [blame] | 326 | public $full_dst_path = ''; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 327 | |
Timothy Warren | b82bc3a | 2012-04-27 09:12:58 -0400 | [diff] [blame] | 328 | /** |
| 329 | * Name of function to create image |
| 330 | * |
| 331 | * @var string |
| 332 | */ |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 333 | public $create_fnc = 'imagecreatetruecolor'; |
| 334 | |
Timothy Warren | b82bc3a | 2012-04-27 09:12:58 -0400 | [diff] [blame] | 335 | /** |
| 336 | * Name of function to copy image |
| 337 | * |
| 338 | * @var string |
| 339 | */ |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 340 | public $copy_fnc = 'imagecopyresampled'; |
| 341 | |
Timothy Warren | b82bc3a | 2012-04-27 09:12:58 -0400 | [diff] [blame] | 342 | /** |
| 343 | * Error messages |
| 344 | * |
| 345 | * @var array |
| 346 | */ |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 347 | public $error_msg = array(); |
| 348 | |
Timothy Warren | b82bc3a | 2012-04-27 09:12:58 -0400 | [diff] [blame] | 349 | /** |
| 350 | * Whether to have a drop shadow on watermark |
| 351 | * |
| 352 | * @var bool |
| 353 | */ |
Andrey Andreev | 64dbdfb | 2011-12-30 14:14:07 +0200 | [diff] [blame] | 354 | protected $wm_use_drop_shadow = FALSE; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 355 | |
Timothy Warren | b82bc3a | 2012-04-27 09:12:58 -0400 | [diff] [blame] | 356 | /** |
| 357 | * Whether to use truetype fonts |
| 358 | * |
| 359 | * @var bool |
| 360 | */ |
Andrey Andreev | 3a45957 | 2011-12-21 11:23:11 +0200 | [diff] [blame] | 361 | public $wm_use_truetype = FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 362 | |
Timothy Warren | b82bc3a | 2012-04-27 09:12:58 -0400 | [diff] [blame] | 363 | /** |
| 364 | * Initialize Image Library |
| 365 | * |
| 366 | * @param array $props |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 367 | * @return void |
Timothy Warren | b82bc3a | 2012-04-27 09:12:58 -0400 | [diff] [blame] | 368 | */ |
Greg Aker | a926328 | 2010-11-10 15:26:43 -0600 | [diff] [blame] | 369 | public function __construct($props = array()) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 370 | { |
| 371 | if (count($props) > 0) |
| 372 | { |
| 373 | $this->initialize($props); |
| 374 | } |
| 375 | |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 376 | log_message('debug', 'Image Lib Class Initialized'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | // -------------------------------------------------------------------- |
| 380 | |
| 381 | /** |
| 382 | * Initialize image properties |
| 383 | * |
| 384 | * Resets values in case this class is used in a loop |
| 385 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 386 | * @return void |
| 387 | */ |
Andrey Andreev | 4eea989 | 2011-12-19 12:05:41 +0200 | [diff] [blame] | 388 | public function clear() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 389 | { |
Michael Dennis | cb07a32 | 2011-08-20 23:40:59 -0700 | [diff] [blame] | 390 | $props = array('library_path', 'source_image', 'new_image', 'width', 'height', 'rotation_angle', 'x_axis', 'y_axis', 'wm_text', 'wm_overlay_path', 'wm_font_path', 'wm_shadow_color', 'source_folder', 'dest_folder', 'mime_type', 'orig_width', 'orig_height', 'image_type', 'size_str', 'full_src_path', 'full_dst_path'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 391 | |
| 392 | foreach ($props as $val) |
| 393 | { |
| 394 | $this->$val = ''; |
| 395 | } |
| 396 | |
Michael Dennis | cb07a32 | 2011-08-20 23:40:59 -0700 | [diff] [blame] | 397 | $this->image_library = 'gd2'; |
| 398 | $this->dynamic_output = FALSE; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 399 | $this->quality = 90; |
Michael Dennis | cb07a32 | 2011-08-20 23:40:59 -0700 | [diff] [blame] | 400 | $this->create_thumb = FALSE; |
| 401 | $this->thumb_marker = '_thumb'; |
| 402 | $this->maintain_ratio = TRUE; |
| 403 | $this->master_dim = 'auto'; |
| 404 | $this->wm_type = 'text'; |
| 405 | $this->wm_x_transp = 4; |
| 406 | $this->wm_y_transp = 4; |
| 407 | $this->wm_font_size = 17; |
| 408 | $this->wm_vrt_alignment = 'B'; |
| 409 | $this->wm_hor_alignment = 'C'; |
| 410 | $this->wm_padding = 0; |
| 411 | $this->wm_hor_offset = 0; |
| 412 | $this->wm_vrt_offset = 0; |
| 413 | $this->wm_font_color = '#ffffff'; |
| 414 | $this->wm_shadow_distance = 2; |
| 415 | $this->wm_opacity = 50; |
| 416 | $this->create_fnc = 'imagecreatetruecolor'; |
| 417 | $this->copy_fnc = 'imagecopyresampled'; |
| 418 | $this->error_msg = array(); |
| 419 | $this->wm_use_drop_shadow = FALSE; |
| 420 | $this->wm_use_truetype = FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | // -------------------------------------------------------------------- |
| 424 | |
| 425 | /** |
| 426 | * initialize image preferences |
| 427 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 428 | * @param array |
| 429 | * @return bool |
| 430 | */ |
Andrey Andreev | 4eea989 | 2011-12-19 12:05:41 +0200 | [diff] [blame] | 431 | public function initialize($props = array()) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 432 | { |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 433 | // Convert array elements into class variables |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 434 | if (count($props) > 0) |
| 435 | { |
| 436 | foreach ($props as $key => $val) |
| 437 | { |
Andrey Andreev | 64dbdfb | 2011-12-30 14:14:07 +0200 | [diff] [blame] | 438 | if (property_exists($this, $key)) |
| 439 | { |
| 440 | if (in_array($key, array('wm_font_color', 'wm_shadow_color'))) |
| 441 | { |
Andrey Andreev | 8323ae6 | 2011-12-31 18:39:10 +0200 | [diff] [blame] | 442 | if (preg_match('/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i', $val, $matches)) |
Andrey Andreev | 64dbdfb | 2011-12-30 14:14:07 +0200 | [diff] [blame] | 443 | { |
Andrey Andreev | cf2ba9e | 2012-01-01 21:57:13 +0200 | [diff] [blame] | 444 | /* $matches[1] contains our hex color value, but it might be |
Andrey Andreev | 8323ae6 | 2011-12-31 18:39:10 +0200 | [diff] [blame] | 445 | * both in the full 6-length format or the shortened 3-length |
| 446 | * value. |
Andrey Andreev | bb96c8b | 2011-12-31 18:48:39 +0200 | [diff] [blame] | 447 | * We'll later need the full version, so we keep it if it's |
Andrey Andreev | 8323ae6 | 2011-12-31 18:39:10 +0200 | [diff] [blame] | 448 | * already there and if not - we'll convert to it. We can |
| 449 | * access string characters by their index as in an array, |
| 450 | * so we'll do that and use concatenation to form the final |
| 451 | * value: |
| 452 | */ |
Andrey Andreev | 665af0c | 2011-12-30 14:39:29 +0200 | [diff] [blame] | 453 | $val = (strlen($matches[1]) === 6) |
| 454 | ? '#'.$matches[1] |
| 455 | : '#'.$matches[1][0].$matches[1][0].$matches[1][1].$matches[1][1].$matches[1][2].$matches[1][2]; |
Andrey Andreev | 64dbdfb | 2011-12-30 14:14:07 +0200 | [diff] [blame] | 456 | } |
| 457 | else |
| 458 | { |
| 459 | continue; |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | $this->$key = $val; |
| 464 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 465 | } |
| 466 | } |
| 467 | |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 468 | // Is there a source image? If not, there's no reason to continue |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 469 | if ($this->source_image == '') |
| 470 | { |
| 471 | $this->set_error('imglib_source_image_required'); |
Eric Barnes | b167336 | 2011-12-05 22:05:38 -0500 | [diff] [blame] | 472 | return FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 473 | } |
| 474 | |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 475 | /* Is getimagesize() available? |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 476 | * |
| 477 | * We use it to determine the image properties (width/height). |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 478 | * Note: We need to figure out how to determine image |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 479 | * properties using ImageMagick and NetPBM |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 480 | */ |
| 481 | if ( ! function_exists('getimagesize')) |
| 482 | { |
| 483 | $this->set_error('imglib_gd_required_for_props'); |
| 484 | return FALSE; |
| 485 | } |
| 486 | |
| 487 | $this->image_library = strtolower($this->image_library); |
| 488 | |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 489 | /* Set the full server path |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 490 | * |
| 491 | * The source image may or may not contain a path. |
| 492 | * Either way, we'll try use realpath to generate the |
| 493 | * full server path in order to more reliably read it. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 494 | */ |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 495 | if (function_exists('realpath') && @realpath($this->source_image) !== FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 496 | { |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 497 | $full_source_path = str_replace('\\', '/', realpath($this->source_image)); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 498 | } |
| 499 | else |
| 500 | { |
| 501 | $full_source_path = $this->source_image; |
| 502 | } |
| 503 | |
| 504 | $x = explode('/', $full_source_path); |
| 505 | $this->source_image = end($x); |
| 506 | $this->source_folder = str_replace($this->source_image, '', $full_source_path); |
| 507 | |
| 508 | // Set the Image Properties |
| 509 | if ( ! $this->get_image_properties($this->source_folder.$this->source_image)) |
| 510 | { |
Eric Barnes | b167336 | 2011-12-05 22:05:38 -0500 | [diff] [blame] | 511 | return FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | /* |
| 515 | * Assign the "new" image name/path |
| 516 | * |
| 517 | * If the user has set a "new_image" name it means |
| 518 | * we are making a copy of the source image. If not |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 519 | * it means we are altering the original. We'll |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 520 | * set the destination filename and path accordingly. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 521 | */ |
| 522 | if ($this->new_image == '') |
| 523 | { |
| 524 | $this->dest_image = $this->source_image; |
| 525 | $this->dest_folder = $this->source_folder; |
| 526 | } |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 527 | elseif (strpos($this->new_image, '/') === FALSE) |
| 528 | { |
| 529 | $this->dest_folder = $this->source_folder; |
| 530 | $this->dest_image = $this->new_image; |
| 531 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 532 | else |
| 533 | { |
Andrey Andreev | 1b81553 | 2012-04-03 16:06:03 +0300 | [diff] [blame] | 534 | if (strpos($this->new_image, '/') === FALSE && strpos($this->new_image, '\\') === FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 535 | { |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 536 | $full_dest_path = str_replace('\\', '/', realpath($this->new_image)); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 537 | } |
| 538 | else |
| 539 | { |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 540 | $full_dest_path = $this->new_image; |
| 541 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 542 | |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 543 | // Is there a file name? |
| 544 | if ( ! preg_match('#\.(jpg|jpeg|gif|png)$#i', $full_dest_path)) |
| 545 | { |
| 546 | $this->dest_folder = $full_dest_path.'/'; |
| 547 | $this->dest_image = $this->source_image; |
| 548 | } |
| 549 | else |
| 550 | { |
| 551 | $x = explode('/', $full_dest_path); |
| 552 | $this->dest_image = end($x); |
| 553 | $this->dest_folder = str_replace($this->dest_image, '', $full_dest_path); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 554 | } |
| 555 | } |
| 556 | |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 557 | /* Compile the finalized filenames/paths |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 558 | * |
| 559 | * We'll create two master strings containing the |
| 560 | * full server path to the source image and the |
| 561 | * full server path to the destination image. |
| 562 | * We'll also split the destination image name |
| 563 | * so we can insert the thumbnail marker if needed. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 564 | */ |
| 565 | if ($this->create_thumb === FALSE OR $this->thumb_marker == '') |
| 566 | { |
| 567 | $this->thumb_marker = ''; |
| 568 | } |
| 569 | |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 570 | $xp = $this->explode_name($this->dest_image); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 571 | |
| 572 | $filename = $xp['name']; |
| 573 | $file_ext = $xp['ext']; |
| 574 | |
| 575 | $this->full_src_path = $this->source_folder.$this->source_image; |
| 576 | $this->full_dst_path = $this->dest_folder.$filename.$this->thumb_marker.$file_ext; |
| 577 | |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 578 | /* Should we maintain image proportions? |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 579 | * |
| 580 | * When creating thumbs or copies, the target width/height |
| 581 | * might not be in correct proportion with the source |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 582 | * image's width/height. We'll recalculate it here. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 583 | */ |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 584 | if ($this->maintain_ratio === TRUE && ($this->width != 0 OR $this->height != 0)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 585 | { |
| 586 | $this->image_reproportion(); |
| 587 | } |
| 588 | |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 589 | /* Was a width and height specified? |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 590 | * |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 591 | * If the destination width/height was not submitted we |
| 592 | * will use the values from the actual file |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 593 | */ |
| 594 | if ($this->width == '') |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 595 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 596 | $this->width = $this->orig_width; |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 597 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 598 | |
| 599 | if ($this->height == '') |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 600 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 601 | $this->height = $this->orig_height; |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 602 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 603 | |
| 604 | // Set the quality |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 605 | $this->quality = trim(str_replace('%', '', $this->quality)); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 606 | |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 607 | if ($this->quality == '' OR $this->quality == 0 OR ! preg_match('/^[0-9]+$/', $this->quality)) |
| 608 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 609 | $this->quality = 90; |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 610 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 611 | |
| 612 | // Set the x/y coordinates |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 613 | $this->x_axis = ($this->x_axis == '' OR ! preg_match('/^[0-9]+$/', $this->x_axis)) ? 0 : $this->x_axis; |
| 614 | $this->y_axis = ($this->y_axis == '' OR ! preg_match('/^[0-9]+$/', $this->y_axis)) ? 0 : $this->y_axis; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 615 | |
| 616 | // Watermark-related Stuff... |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 617 | if ($this->wm_overlay_path != '') |
| 618 | { |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 619 | $this->wm_overlay_path = str_replace('\\', '/', realpath($this->wm_overlay_path)); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | if ($this->wm_shadow_color != '') |
| 623 | { |
| 624 | $this->wm_use_drop_shadow = TRUE; |
| 625 | } |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 626 | elseif ($this->wm_use_drop_shadow == TRUE && $this->wm_shadow_color == '') |
Andrey Andreev | 64dbdfb | 2011-12-30 14:14:07 +0200 | [diff] [blame] | 627 | { |
| 628 | $this->wm_use_drop_shadow = FALSE; |
| 629 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 630 | |
| 631 | if ($this->wm_font_path != '') |
| 632 | { |
| 633 | $this->wm_use_truetype = TRUE; |
| 634 | } |
| 635 | |
| 636 | return TRUE; |
| 637 | } |
| 638 | |
| 639 | // -------------------------------------------------------------------- |
| 640 | |
| 641 | /** |
| 642 | * Image Resize |
| 643 | * |
| 644 | * This is a wrapper function that chooses the proper |
| 645 | * resize function based on the protocol specified |
| 646 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 647 | * @return bool |
| 648 | */ |
Andrey Andreev | 4eea989 | 2011-12-19 12:05:41 +0200 | [diff] [blame] | 649 | public function resize() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 650 | { |
Andrey Andreev | 1a9f52c | 2012-01-07 01:06:34 +0200 | [diff] [blame] | 651 | $protocol = ($this->image_library === 'gd2') ? 'image_process_gd' : 'image_process_'.$this->image_library; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 652 | return $this->$protocol('resize'); |
| 653 | } |
| 654 | |
| 655 | // -------------------------------------------------------------------- |
| 656 | |
| 657 | /** |
| 658 | * Image Crop |
| 659 | * |
| 660 | * This is a wrapper function that chooses the proper |
| 661 | * cropping function based on the protocol specified |
| 662 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 663 | * @return bool |
| 664 | */ |
Andrey Andreev | 4eea989 | 2011-12-19 12:05:41 +0200 | [diff] [blame] | 665 | public function crop() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 666 | { |
Andrey Andreev | 5a67e3d | 2012-01-07 01:21:09 +0200 | [diff] [blame] | 667 | $protocol = ($this->image_library === 'gd2') ? 'image_process_gd' : 'image_process_'.$this->image_library; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 668 | return $this->$protocol('crop'); |
| 669 | } |
| 670 | |
| 671 | // -------------------------------------------------------------------- |
| 672 | |
| 673 | /** |
| 674 | * Image Rotate |
| 675 | * |
| 676 | * This is a wrapper function that chooses the proper |
| 677 | * rotation function based on the protocol specified |
| 678 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 679 | * @return bool |
| 680 | */ |
Andrey Andreev | 4eea989 | 2011-12-19 12:05:41 +0200 | [diff] [blame] | 681 | public function rotate() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 682 | { |
| 683 | // Allowed rotation values |
| 684 | $degs = array(90, 180, 270, 'vrt', 'hor'); |
| 685 | |
Derek Allard | d9c7f03 | 2008-12-01 20:18:00 +0000 | [diff] [blame] | 686 | if ($this->rotation_angle == '' OR ! in_array($this->rotation_angle, $degs)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 687 | { |
| 688 | $this->set_error('imglib_rotation_angle_required'); |
Eric Barnes | b167336 | 2011-12-05 22:05:38 -0500 | [diff] [blame] | 689 | return FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | // Reassign the width and height |
| 693 | if ($this->rotation_angle == 90 OR $this->rotation_angle == 270) |
| 694 | { |
| 695 | $this->width = $this->orig_height; |
| 696 | $this->height = $this->orig_width; |
| 697 | } |
| 698 | else |
| 699 | { |
| 700 | $this->width = $this->orig_width; |
| 701 | $this->height = $this->orig_height; |
| 702 | } |
| 703 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 704 | // Choose resizing function |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 705 | if ($this->image_library === 'imagemagick' OR $this->image_library === 'netpbm') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 706 | { |
| 707 | $protocol = 'image_process_'.$this->image_library; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 708 | return $this->$protocol('rotate'); |
| 709 | } |
| 710 | |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 711 | return ($this->rotation_angle === 'hor' OR $this->rotation_angle === 'vrt') |
| 712 | ? $this->image_mirror_gd() |
| 713 | : $this->image_rotate_gd(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | // -------------------------------------------------------------------- |
| 717 | |
| 718 | /** |
| 719 | * Image Process Using GD/GD2 |
| 720 | * |
| 721 | * This function will resize or crop |
| 722 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 723 | * @param string |
| 724 | * @return bool |
| 725 | */ |
Andrey Andreev | 4eea989 | 2011-12-19 12:05:41 +0200 | [diff] [blame] | 726 | public function image_process_gd($action = 'resize') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 727 | { |
| 728 | $v2_override = FALSE; |
| 729 | |
| 730 | // If the target width/height match the source, AND if the new file name is not equal to the old file name |
| 731 | // we'll simply make a copy of the original with the new name... assuming dynamic rendering is off. |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 732 | if ($this->dynamic_output === FALSE && $this->orig_width == $this->width && $this->orig_height == $this->height) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 733 | { |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 734 | if ($this->source_image != $this->new_image && @copy($this->full_src_path, $this->full_dst_path)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 735 | { |
Andrey Andreev | a92b903 | 2011-12-24 19:05:58 +0200 | [diff] [blame] | 736 | @chmod($this->full_dst_path, FILE_WRITE_MODE); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 737 | } |
Andrey Andreev | a92b903 | 2011-12-24 19:05:58 +0200 | [diff] [blame] | 738 | |
| 739 | return TRUE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | // Let's set up our values based on the action |
| 743 | if ($action == 'crop') |
| 744 | { |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 745 | // Reassign the source width/height if cropping |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 746 | $this->orig_width = $this->width; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 747 | $this->orig_height = $this->height; |
| 748 | |
| 749 | // GD 2.0 has a cropping bug so we'll test for it |
| 750 | if ($this->gd_version() !== FALSE) |
| 751 | { |
| 752 | $gd_version = str_replace('0', '', $this->gd_version()); |
| 753 | $v2_override = ($gd_version == 2) ? TRUE : FALSE; |
| 754 | } |
| 755 | } |
| 756 | else |
| 757 | { |
| 758 | // If resizing the x/y axis must be zero |
| 759 | $this->x_axis = 0; |
| 760 | $this->y_axis = 0; |
| 761 | } |
| 762 | |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 763 | // Create the image handle |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 764 | if ( ! ($src_img = $this->image_create_gd())) |
| 765 | { |
| 766 | return FALSE; |
| 767 | } |
| 768 | |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 769 | /* Create the image |
| 770 | * |
| 771 | * Old conditional which users report cause problems with shared GD libs who report themselves as "2.0 or greater" |
| 772 | * it appears that this is no longer the issue that it was in 2004, so we've removed it, retaining it in the comment |
| 773 | * below should that ever prove inaccurate. |
| 774 | * |
| 775 | * if ($this->image_library === 'gd2' && function_exists('imagecreatetruecolor') && $v2_override == FALSE) |
| 776 | */ |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 777 | if ($this->image_library === 'gd2' && function_exists('imagecreatetruecolor')) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 778 | { |
| 779 | $create = 'imagecreatetruecolor'; |
| 780 | $copy = 'imagecopyresampled'; |
| 781 | } |
| 782 | else |
| 783 | { |
| 784 | $create = 'imagecreate'; |
| 785 | $copy = 'imagecopyresized'; |
| 786 | } |
| 787 | |
| 788 | $dst_img = $create($this->width, $this->height); |
Derek Jones | 595bfd1 | 2010-08-20 10:28:22 -0500 | [diff] [blame] | 789 | |
| 790 | if ($this->image_type == 3) // png we can actually preserve transparency |
| 791 | { |
| 792 | imagealphablending($dst_img, FALSE); |
| 793 | imagesavealpha($dst_img, TRUE); |
| 794 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 795 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 796 | $copy($dst_img, $src_img, 0, 0, $this->x_axis, $this->y_axis, $this->width, $this->height, $this->orig_width, $this->orig_height); |
| 797 | |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 798 | // Show the image |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 799 | if ($this->dynamic_output == TRUE) |
| 800 | { |
| 801 | $this->image_display_gd($dst_img); |
| 802 | } |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 803 | elseif ( ! $this->image_save_gd($dst_img)) // Or save it |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 804 | { |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 805 | return FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 806 | } |
| 807 | |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 808 | // Kill the file handles |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 809 | imagedestroy($dst_img); |
| 810 | imagedestroy($src_img); |
| 811 | |
| 812 | // Set the file to 777 |
Derek Jones | 172e161 | 2009-10-13 14:32:48 +0000 | [diff] [blame] | 813 | @chmod($this->full_dst_path, FILE_WRITE_MODE); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 814 | |
| 815 | return TRUE; |
| 816 | } |
| 817 | |
| 818 | // -------------------------------------------------------------------- |
| 819 | |
| 820 | /** |
| 821 | * Image Process Using ImageMagick |
| 822 | * |
| 823 | * This function will resize, crop or rotate |
| 824 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 825 | * @param string |
| 826 | * @return bool |
| 827 | */ |
Andrey Andreev | 4eea989 | 2011-12-19 12:05:41 +0200 | [diff] [blame] | 828 | public function image_process_imagemagick($action = 'resize') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 829 | { |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 830 | // Do we have a vaild library path? |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 831 | if ($this->library_path == '') |
| 832 | { |
| 833 | $this->set_error('imglib_libpath_invalid'); |
| 834 | return FALSE; |
| 835 | } |
| 836 | |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 837 | if ( ! preg_match('/convert$/i', $this->library_path)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 838 | { |
Andrey Andreev | a92b903 | 2011-12-24 19:05:58 +0200 | [diff] [blame] | 839 | $this->library_path = rtrim($this->library_path, '/').'/convert'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | // Execute the command |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 843 | $cmd = $this->library_path.' -quality '.$this->quality; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 844 | |
| 845 | if ($action == 'crop') |
| 846 | { |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 847 | $cmd .= ' -crop '.$this->width.'x'.$this->height.'+'.$this->x_axis.'+'.$this->y_axis.' "'.$this->full_src_path.'" "'.$this->full_dst_path .'" 2>&1'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 848 | } |
| 849 | elseif ($action == 'rotate') |
| 850 | { |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 851 | $angle = ($this->rotation_angle === 'hor' OR $this->rotation_angle === 'vrt') |
| 852 | ? '-flop' : '-rotate '.$this->rotation_angle; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 853 | |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 854 | $cmd .= ' '.$angle.' "'.$this->full_src_path.'" "'.$this->full_dst_path.'" 2>&1'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 855 | } |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 856 | else // Resize |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 857 | { |
Andrey Andreev | e463630 | 2012-01-12 20:23:27 +0200 | [diff] [blame] | 858 | $cmd .= ' -resize '.$this->width.'x'.$this->height.' "'.$this->full_src_path.'" "'.$this->full_dst_path.'" 2>&1'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | $retval = 1; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 862 | @exec($cmd, $output, $retval); |
| 863 | |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 864 | // Did it work? |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 865 | if ($retval > 0) |
| 866 | { |
| 867 | $this->set_error('imglib_image_process_failed'); |
| 868 | return FALSE; |
| 869 | } |
| 870 | |
| 871 | // Set the file to 777 |
Derek Jones | 172e161 | 2009-10-13 14:32:48 +0000 | [diff] [blame] | 872 | @chmod($this->full_dst_path, FILE_WRITE_MODE); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 873 | |
| 874 | return TRUE; |
| 875 | } |
| 876 | |
| 877 | // -------------------------------------------------------------------- |
| 878 | |
| 879 | /** |
| 880 | * Image Process Using NetPBM |
| 881 | * |
| 882 | * This function will resize, crop or rotate |
| 883 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 884 | * @param string |
| 885 | * @return bool |
| 886 | */ |
Andrey Andreev | 4eea989 | 2011-12-19 12:05:41 +0200 | [diff] [blame] | 887 | public function image_process_netpbm($action = 'resize') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 888 | { |
| 889 | if ($this->library_path == '') |
| 890 | { |
| 891 | $this->set_error('imglib_libpath_invalid'); |
| 892 | return FALSE; |
| 893 | } |
| 894 | |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 895 | // Build the resizing command |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 896 | switch ($this->image_type) |
| 897 | { |
| 898 | case 1 : |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 899 | $cmd_in = 'giftopnm'; |
| 900 | $cmd_out = 'ppmtogif'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 901 | break; |
| 902 | case 2 : |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 903 | $cmd_in = 'jpegtopnm'; |
| 904 | $cmd_out = 'ppmtojpeg'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 905 | break; |
| 906 | case 3 : |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 907 | $cmd_in = 'pngtopnm'; |
| 908 | $cmd_out = 'ppmtopng'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 909 | break; |
| 910 | } |
| 911 | |
| 912 | if ($action == 'crop') |
| 913 | { |
| 914 | $cmd_inner = 'pnmcut -left '.$this->x_axis.' -top '.$this->y_axis.' -width '.$this->width.' -height '.$this->height; |
| 915 | } |
| 916 | elseif ($action == 'rotate') |
| 917 | { |
| 918 | switch ($this->rotation_angle) |
| 919 | { |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 920 | case 90: $angle = 'r270'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 921 | break; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 922 | case 180: $angle = 'r180'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 923 | break; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 924 | case 270: $angle = 'r90'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 925 | break; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 926 | case 'vrt': $angle = 'tb'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 927 | break; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 928 | case 'hor': $angle = 'lr'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 929 | break; |
| 930 | } |
| 931 | |
| 932 | $cmd_inner = 'pnmflip -'.$angle.' '; |
| 933 | } |
| 934 | else // Resize |
| 935 | { |
| 936 | $cmd_inner = 'pnmscale -xysize '.$this->width.' '.$this->height; |
| 937 | } |
| 938 | |
| 939 | $cmd = $this->library_path.$cmd_in.' '.$this->full_src_path.' | '.$cmd_inner.' | '.$cmd_out.' > '.$this->dest_folder.'netpbm.tmp'; |
| 940 | |
| 941 | $retval = 1; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 942 | @exec($cmd, $output, $retval); |
| 943 | |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 944 | // Did it work? |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 945 | if ($retval > 0) |
| 946 | { |
| 947 | $this->set_error('imglib_image_process_failed'); |
| 948 | return FALSE; |
| 949 | } |
| 950 | |
| 951 | // With NetPBM we have to create a temporary image. |
| 952 | // If you try manipulating the original it fails so |
| 953 | // we have to rename the temp file. |
| 954 | copy ($this->dest_folder.'netpbm.tmp', $this->full_dst_path); |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 955 | unlink($this->dest_folder.'netpbm.tmp'); |
Derek Jones | 172e161 | 2009-10-13 14:32:48 +0000 | [diff] [blame] | 956 | @chmod($this->full_dst_path, FILE_WRITE_MODE); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 957 | |
| 958 | return TRUE; |
| 959 | } |
| 960 | |
| 961 | // -------------------------------------------------------------------- |
| 962 | |
| 963 | /** |
| 964 | * Image Rotate Using GD |
| 965 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 966 | * @return bool |
| 967 | */ |
Andrey Andreev | 4eea989 | 2011-12-19 12:05:41 +0200 | [diff] [blame] | 968 | public function image_rotate_gd() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 969 | { |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 970 | // Create the image handle |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 971 | if ( ! ($src_img = $this->image_create_gd())) |
| 972 | { |
| 973 | return FALSE; |
| 974 | } |
| 975 | |
| 976 | // Set the background color |
| 977 | // This won't work with transparent PNG files so we are |
| 978 | // going to have to figure out how to determine the color |
| 979 | // of the alpha channel in a future release. |
| 980 | |
| 981 | $white = imagecolorallocate($src_img, 255, 255, 255); |
| 982 | |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 983 | // Rotate it! |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 984 | $dst_img = imagerotate($src_img, $this->rotation_angle, $white); |
| 985 | |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 986 | // Show the image |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 987 | if ($this->dynamic_output == TRUE) |
| 988 | { |
| 989 | $this->image_display_gd($dst_img); |
| 990 | } |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 991 | elseif ( ! $this->image_save_gd($dst_img)) // ... or save it |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 992 | { |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 993 | return FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 994 | } |
| 995 | |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 996 | // Kill the file handles |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 997 | imagedestroy($dst_img); |
| 998 | imagedestroy($src_img); |
| 999 | |
| 1000 | // Set the file to 777 |
Derek Jones | 172e161 | 2009-10-13 14:32:48 +0000 | [diff] [blame] | 1001 | @chmod($this->full_dst_path, FILE_WRITE_MODE); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1002 | |
Pascal Kriete | 8761ef5 | 2011-02-14 13:13:52 -0500 | [diff] [blame] | 1003 | return TRUE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | // -------------------------------------------------------------------- |
| 1007 | |
| 1008 | /** |
| 1009 | * Create Mirror Image using GD |
| 1010 | * |
| 1011 | * This function will flip horizontal or vertical |
| 1012 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1013 | * @return bool |
| 1014 | */ |
Andrey Andreev | 4eea989 | 2011-12-19 12:05:41 +0200 | [diff] [blame] | 1015 | public function image_mirror_gd() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1016 | { |
| 1017 | if ( ! $src_img = $this->image_create_gd()) |
| 1018 | { |
| 1019 | return FALSE; |
| 1020 | } |
| 1021 | |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 1022 | $width = $this->orig_width; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1023 | $height = $this->orig_height; |
| 1024 | |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 1025 | if ($this->rotation_angle === 'hor') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1026 | { |
Andrey Andreev | a92b903 | 2011-12-24 19:05:58 +0200 | [diff] [blame] | 1027 | for ($i = 0; $i < $height; $i++, $left = 0, $right = $width-1) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1028 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1029 | while ($left < $right) |
| 1030 | { |
| 1031 | $cl = imagecolorat($src_img, $left, $i); |
| 1032 | $cr = imagecolorat($src_img, $right, $i); |
| 1033 | |
| 1034 | imagesetpixel($src_img, $left, $i, $cr); |
| 1035 | imagesetpixel($src_img, $right, $i, $cl); |
| 1036 | |
| 1037 | $left++; |
| 1038 | $right--; |
| 1039 | } |
| 1040 | } |
| 1041 | } |
| 1042 | else |
| 1043 | { |
Andrey Andreev | a92b903 | 2011-12-24 19:05:58 +0200 | [diff] [blame] | 1044 | for ($i = 0; $i < $width; $i++, $top = 0, $bot = $height-1) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1045 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1046 | while ($top < $bot) |
| 1047 | { |
| 1048 | $ct = imagecolorat($src_img, $i, $top); |
| 1049 | $cb = imagecolorat($src_img, $i, $bot); |
| 1050 | |
| 1051 | imagesetpixel($src_img, $i, $top, $cb); |
| 1052 | imagesetpixel($src_img, $i, $bot, $ct); |
| 1053 | |
| 1054 | $top++; |
| 1055 | $bot--; |
| 1056 | } |
| 1057 | } |
| 1058 | } |
| 1059 | |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 1060 | // Show the image |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1061 | if ($this->dynamic_output == TRUE) |
| 1062 | { |
| 1063 | $this->image_display_gd($src_img); |
| 1064 | } |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 1065 | elseif ( ! $this->image_save_gd($src_img)) // ... or save it |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1066 | { |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 1067 | return FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1068 | } |
| 1069 | |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 1070 | // Kill the file handles |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1071 | imagedestroy($src_img); |
| 1072 | |
| 1073 | // Set the file to 777 |
Derek Jones | 172e161 | 2009-10-13 14:32:48 +0000 | [diff] [blame] | 1074 | @chmod($this->full_dst_path, FILE_WRITE_MODE); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1075 | |
| 1076 | return TRUE; |
| 1077 | } |
| 1078 | |
| 1079 | // -------------------------------------------------------------------- |
| 1080 | |
| 1081 | /** |
| 1082 | * Image Watermark |
| 1083 | * |
| 1084 | * This is a wrapper function that chooses the type |
| 1085 | * of watermarking based on the specified preference. |
| 1086 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1087 | * @return bool |
| 1088 | */ |
Andrey Andreev | 4eea989 | 2011-12-19 12:05:41 +0200 | [diff] [blame] | 1089 | public function watermark() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1090 | { |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 1091 | return ($this->wm_type === 'overlay') ? $this->overlay_watermark() : $this->text_watermark(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1092 | } |
| 1093 | |
| 1094 | // -------------------------------------------------------------------- |
| 1095 | |
| 1096 | /** |
| 1097 | * Watermark - Graphic Version |
| 1098 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1099 | * @return bool |
| 1100 | */ |
Andrey Andreev | 4eea989 | 2011-12-19 12:05:41 +0200 | [diff] [blame] | 1101 | public function overlay_watermark() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1102 | { |
| 1103 | if ( ! function_exists('imagecolortransparent')) |
| 1104 | { |
| 1105 | $this->set_error('imglib_gd_required'); |
| 1106 | return FALSE; |
| 1107 | } |
| 1108 | |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 1109 | // Fetch source image properties |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1110 | $this->get_image_properties(); |
| 1111 | |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 1112 | // Fetch watermark image properties |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 1113 | $props = $this->get_image_properties($this->wm_overlay_path, TRUE); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1114 | $wm_img_type = $props['image_type']; |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 1115 | $wm_width = $props['width']; |
| 1116 | $wm_height = $props['height']; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1117 | |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 1118 | // Create two image resources |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 1119 | $wm_img = $this->image_create_gd($this->wm_overlay_path, $wm_img_type); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1120 | $src_img = $this->image_create_gd($this->full_src_path); |
| 1121 | |
| 1122 | // Reverse the offset if necessary |
| 1123 | // When the image is positioned at the bottom |
| 1124 | // we don't want the vertical offset to push it |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 1125 | // further down. We want the reverse, so we'll |
| 1126 | // invert the offset. Same with the horizontal |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1127 | // offset when the image is at the right |
| 1128 | |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 1129 | $this->wm_vrt_alignment = strtoupper($this->wm_vrt_alignment[0]); |
| 1130 | $this->wm_hor_alignment = strtoupper($this->wm_hor_alignment[0]); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1131 | |
| 1132 | if ($this->wm_vrt_alignment == 'B') |
| 1133 | $this->wm_vrt_offset = $this->wm_vrt_offset * -1; |
| 1134 | |
| 1135 | if ($this->wm_hor_alignment == 'R') |
| 1136 | $this->wm_hor_offset = $this->wm_hor_offset * -1; |
| 1137 | |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 1138 | // Set the base x and y axis values |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1139 | $x_axis = $this->wm_hor_offset + $this->wm_padding; |
| 1140 | $y_axis = $this->wm_vrt_offset + $this->wm_padding; |
| 1141 | |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 1142 | // Set the vertical position |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 1143 | if ($this->wm_vrt_alignment === 'M') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1144 | { |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 1145 | $y_axis += ($this->orig_height / 2) - ($wm_height / 2); |
| 1146 | } |
| 1147 | elseif ($this->wm_vrt_alignment === 'B') |
| 1148 | { |
| 1149 | $y_axis += $this->orig_height - $wm_height; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1150 | } |
| 1151 | |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 1152 | // Set the horizontal position |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 1153 | if ($this->wm_hor_alignment === 'C') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1154 | { |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 1155 | $x_axis += ($this->orig_width / 2) - ($wm_width / 2); |
| 1156 | } |
| 1157 | elseif ($this->wm_hor_alignment === 'R') |
| 1158 | { |
| 1159 | $x_axis += $this->orig_width - $wm_width; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1160 | } |
| 1161 | |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 1162 | // Build the finalized image |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 1163 | if ($wm_img_type == 3 && function_exists('imagealphablending')) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1164 | { |
| 1165 | @imagealphablending($src_img, TRUE); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1166 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1167 | |
| 1168 | // Set RGB values for text and shadow |
| 1169 | $rgba = imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp); |
| 1170 | $alpha = ($rgba & 0x7F000000) >> 24; |
| 1171 | |
| 1172 | // make a best guess as to whether we're dealing with an image with alpha transparency or no/binary transparency |
| 1173 | if ($alpha > 0) |
| 1174 | { |
| 1175 | // copy the image directly, the image's alpha transparency being the sole determinant of blending |
| 1176 | imagecopy($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height); |
| 1177 | } |
| 1178 | else |
| 1179 | { |
| 1180 | // set our RGB value from above to be transparent and merge the images with the specified opacity |
| 1181 | imagecolortransparent($wm_img, imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp)); |
| 1182 | imagecopymerge($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height, $this->wm_opacity); |
| 1183 | } |
| 1184 | |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 1185 | // Output the image |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1186 | if ($this->dynamic_output == TRUE) |
| 1187 | { |
| 1188 | $this->image_display_gd($src_img); |
| 1189 | } |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 1190 | elseif ( ! $this->image_save_gd($src_img)) // ... or save it |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1191 | { |
Andrey Andreev | a92b903 | 2011-12-24 19:05:58 +0200 | [diff] [blame] | 1192 | return FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1193 | } |
| 1194 | |
| 1195 | imagedestroy($src_img); |
| 1196 | imagedestroy($wm_img); |
| 1197 | |
| 1198 | return TRUE; |
| 1199 | } |
| 1200 | |
| 1201 | // -------------------------------------------------------------------- |
| 1202 | |
| 1203 | /** |
| 1204 | * Watermark - Text Version |
| 1205 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1206 | * @return bool |
| 1207 | */ |
Andrey Andreev | 4eea989 | 2011-12-19 12:05:41 +0200 | [diff] [blame] | 1208 | public function text_watermark() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1209 | { |
| 1210 | if ( ! ($src_img = $this->image_create_gd())) |
| 1211 | { |
| 1212 | return FALSE; |
| 1213 | } |
| 1214 | |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 1215 | if ($this->wm_use_truetype == TRUE && ! file_exists($this->wm_font_path)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1216 | { |
| 1217 | $this->set_error('imglib_missing_font'); |
| 1218 | return FALSE; |
| 1219 | } |
| 1220 | |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 1221 | // Fetch source image properties |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1222 | $this->get_image_properties(); |
| 1223 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1224 | // Reverse the vertical offset |
| 1225 | // When the image is positioned at the bottom |
| 1226 | // we don't want the vertical offset to push it |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 1227 | // further down. We want the reverse, so we'll |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 1228 | // invert the offset. Note: The horizontal |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1229 | // offset flips itself automatically |
| 1230 | |
| 1231 | if ($this->wm_vrt_alignment == 'B') |
| 1232 | $this->wm_vrt_offset = $this->wm_vrt_offset * -1; |
| 1233 | |
| 1234 | if ($this->wm_hor_alignment == 'R') |
| 1235 | $this->wm_hor_offset = $this->wm_hor_offset * -1; |
| 1236 | |
| 1237 | // Set font width and height |
| 1238 | // These are calculated differently depending on |
| 1239 | // whether we are using the true type font or not |
| 1240 | if ($this->wm_use_truetype == TRUE) |
| 1241 | { |
| 1242 | if ($this->wm_font_size == '') |
Andrey Andreev | a92b903 | 2011-12-24 19:05:58 +0200 | [diff] [blame] | 1243 | { |
| 1244 | $this->wm_font_size = 17; |
| 1245 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1246 | |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 1247 | $fontwidth = $this->wm_font_size-($this->wm_font_size/4); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1248 | $fontheight = $this->wm_font_size; |
| 1249 | $this->wm_vrt_offset += $this->wm_font_size; |
| 1250 | } |
| 1251 | else |
| 1252 | { |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 1253 | $fontwidth = imagefontwidth($this->wm_font_size); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1254 | $fontheight = imagefontheight($this->wm_font_size); |
| 1255 | } |
| 1256 | |
| 1257 | // Set base X and Y axis values |
| 1258 | $x_axis = $this->wm_hor_offset + $this->wm_padding; |
| 1259 | $y_axis = $this->wm_vrt_offset + $this->wm_padding; |
| 1260 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1261 | if ($this->wm_use_drop_shadow == FALSE) |
| 1262 | $this->wm_shadow_distance = 0; |
| 1263 | |
| 1264 | $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1)); |
| 1265 | $this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1)); |
| 1266 | |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 1267 | // Set verticle alignment |
| 1268 | if ($this->wm_vrt_alignment === 'M') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1269 | { |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 1270 | $y_axis += ($this->orig_height / 2) + ($fontheight / 2); |
| 1271 | } |
| 1272 | elseif ($this->wm_vrt_alignment === 'B') |
| 1273 | { |
| 1274 | $y_axis += $this->orig_height - $fontheight - $this->wm_shadow_distance - ($fontheight / 2); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1275 | } |
| 1276 | |
| 1277 | $x_shad = $x_axis + $this->wm_shadow_distance; |
| 1278 | $y_shad = $y_axis + $this->wm_shadow_distance; |
| 1279 | |
Andrey Andreev | 64dbdfb | 2011-12-30 14:14:07 +0200 | [diff] [blame] | 1280 | if ($this->wm_use_drop_shadow) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1281 | { |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 1282 | // Set horizontal alignment |
| 1283 | if ($this->wm_hor_alignment === 'R') |
| 1284 | { |
| 1285 | $x_shad += $this->orig_width - ($fontwidth * strlen($this->wm_text)); |
| 1286 | $x_axis += $this->orig_width - ($fontwidth * strlen($this->wm_text)); |
| 1287 | } |
| 1288 | elseif ($this->wm_hor_alignment === 'C') |
| 1289 | { |
| 1290 | $x_shad += floor(($this->orig_width - ($fontwidth * strlen($this->wm_text))) / 2); |
| 1291 | $x_axis += floor(($this->orig_width - ($fontwidth * strlen($this->wm_text))) / 2); |
| 1292 | } |
| 1293 | |
Andrey Andreev | 8323ae6 | 2011-12-31 18:39:10 +0200 | [diff] [blame] | 1294 | /* Set RGB values for text and shadow |
| 1295 | * |
| 1296 | * First character is #, so we don't really need it. |
| 1297 | * Get the rest of the string and split it into 2-length |
| 1298 | * hex values: |
| 1299 | */ |
| 1300 | $txt_color = str_split(substr($this->wm_font_color, 1, 6), 2); |
Andrey Andreev | 64dbdfb | 2011-12-30 14:14:07 +0200 | [diff] [blame] | 1301 | $txt_color = imagecolorclosest($src_img, hexdec($txt_color[0]), hexdec($txt_color[1]), hexdec($txt_color[2])); |
Andrey Andreev | 8323ae6 | 2011-12-31 18:39:10 +0200 | [diff] [blame] | 1302 | $drp_color = str_split(substr($this->wm_shadow_color, 1, 6), 2); |
Ronald Beilsma | 8f80bc4 | 2012-01-12 16:41:49 +0100 | [diff] [blame] | 1303 | $drp_color = imagecolorclosest($src_img, hexdec($drp_color[0]), hexdec($drp_color[1]), hexdec($drp_color[2])); |
Andrey Andreev | 64dbdfb | 2011-12-30 14:14:07 +0200 | [diff] [blame] | 1304 | |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 1305 | // Add the text to the source image |
Andrey Andreev | 64dbdfb | 2011-12-30 14:14:07 +0200 | [diff] [blame] | 1306 | if ($this->wm_use_truetype) |
| 1307 | { |
| 1308 | imagettftext($src_img, $this->wm_font_size, 0, $x_shad, $y_shad, $drp_color, $this->wm_font_path, $this->wm_text); |
| 1309 | imagettftext($src_img, $this->wm_font_size, 0, $x_axis, $y_axis, $txt_color, $this->wm_font_path, $this->wm_text); |
| 1310 | } |
| 1311 | else |
| 1312 | { |
| 1313 | imagestring($src_img, $this->wm_font_size, $x_shad, $y_shad, $this->wm_text, $drp_color); |
| 1314 | imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color); |
| 1315 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1316 | } |
| 1317 | |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 1318 | // Output the final image |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1319 | if ($this->dynamic_output == TRUE) |
| 1320 | { |
| 1321 | $this->image_display_gd($src_img); |
| 1322 | } |
| 1323 | else |
| 1324 | { |
| 1325 | $this->image_save_gd($src_img); |
| 1326 | } |
| 1327 | |
| 1328 | imagedestroy($src_img); |
| 1329 | |
| 1330 | return TRUE; |
| 1331 | } |
| 1332 | |
| 1333 | // -------------------------------------------------------------------- |
| 1334 | |
| 1335 | /** |
| 1336 | * Create Image - GD |
| 1337 | * |
| 1338 | * This simply creates an image resource handle |
| 1339 | * based on the type of image being processed |
| 1340 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1341 | * @param string |
Timothy Warren | b82bc3a | 2012-04-27 09:12:58 -0400 | [diff] [blame] | 1342 | * @param string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1343 | * @return resource |
| 1344 | */ |
Andrey Andreev | 4eea989 | 2011-12-19 12:05:41 +0200 | [diff] [blame] | 1345 | public function image_create_gd($path = '', $image_type = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1346 | { |
| 1347 | if ($path == '') |
| 1348 | $path = $this->full_src_path; |
| 1349 | |
| 1350 | if ($image_type == '') |
| 1351 | $image_type = $this->image_type; |
| 1352 | |
| 1353 | |
| 1354 | switch ($image_type) |
| 1355 | { |
| 1356 | case 1 : |
| 1357 | if ( ! function_exists('imagecreatefromgif')) |
| 1358 | { |
| 1359 | $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); |
| 1360 | return FALSE; |
| 1361 | } |
| 1362 | |
| 1363 | return imagecreatefromgif($path); |
| 1364 | break; |
| 1365 | case 2 : |
| 1366 | if ( ! function_exists('imagecreatefromjpeg')) |
| 1367 | { |
| 1368 | $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); |
| 1369 | return FALSE; |
| 1370 | } |
| 1371 | |
| 1372 | return imagecreatefromjpeg($path); |
| 1373 | break; |
| 1374 | case 3 : |
| 1375 | if ( ! function_exists('imagecreatefrompng')) |
| 1376 | { |
| 1377 | $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); |
| 1378 | return FALSE; |
| 1379 | } |
| 1380 | |
| 1381 | return imagecreatefrompng($path); |
| 1382 | break; |
| 1383 | |
| 1384 | } |
| 1385 | |
| 1386 | $this->set_error(array('imglib_unsupported_imagecreate')); |
| 1387 | return FALSE; |
| 1388 | } |
| 1389 | |
| 1390 | // -------------------------------------------------------------------- |
| 1391 | |
| 1392 | /** |
| 1393 | * Write image file to disk - GD |
| 1394 | * |
| 1395 | * Takes an image resource as input and writes the file |
| 1396 | * to the specified destination |
| 1397 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1398 | * @param resource |
| 1399 | * @return bool |
| 1400 | */ |
Andrey Andreev | 4eea989 | 2011-12-19 12:05:41 +0200 | [diff] [blame] | 1401 | public function image_save_gd($resource) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1402 | { |
| 1403 | switch ($this->image_type) |
| 1404 | { |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 1405 | case 1: |
| 1406 | if ( ! function_exists('imagegif')) |
| 1407 | { |
| 1408 | $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); |
| 1409 | return FALSE; |
| 1410 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1411 | |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 1412 | if ( ! @imagegif($resource, $this->full_dst_path)) |
| 1413 | { |
| 1414 | $this->set_error('imglib_save_failed'); |
| 1415 | return FALSE; |
| 1416 | } |
| 1417 | break; |
| 1418 | case 2: |
| 1419 | if ( ! function_exists('imagejpeg')) |
| 1420 | { |
| 1421 | $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); |
| 1422 | return FALSE; |
| 1423 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1424 | |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 1425 | if ( ! @imagejpeg($resource, $this->full_dst_path, $this->quality)) |
| 1426 | { |
| 1427 | $this->set_error('imglib_save_failed'); |
| 1428 | return FALSE; |
| 1429 | } |
| 1430 | break; |
| 1431 | case 3: |
| 1432 | if ( ! function_exists('imagepng')) |
| 1433 | { |
| 1434 | $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); |
| 1435 | return FALSE; |
| 1436 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1437 | |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 1438 | if ( ! @imagepng($resource, $this->full_dst_path)) |
| 1439 | { |
| 1440 | $this->set_error('imglib_save_failed'); |
| 1441 | return FALSE; |
| 1442 | } |
| 1443 | break; |
| 1444 | default: |
| 1445 | $this->set_error(array('imglib_unsupported_imagecreate')); |
| 1446 | return FALSE; |
| 1447 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1448 | } |
| 1449 | |
| 1450 | return TRUE; |
| 1451 | } |
| 1452 | |
| 1453 | // -------------------------------------------------------------------- |
| 1454 | |
| 1455 | /** |
| 1456 | * Dynamically outputs an image |
| 1457 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1458 | * @param resource |
| 1459 | * @return void |
| 1460 | */ |
Andrey Andreev | 4eea989 | 2011-12-19 12:05:41 +0200 | [diff] [blame] | 1461 | public function image_display_gd($resource) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1462 | { |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 1463 | header('Content-Disposition: filename='.$this->source_image.';'); |
| 1464 | header('Content-Type: '.$this->mime_type); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1465 | header('Content-Transfer-Encoding: binary'); |
| 1466 | header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT'); |
| 1467 | |
| 1468 | switch ($this->image_type) |
| 1469 | { |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 1470 | case 1 : imagegif($resource); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1471 | break; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 1472 | case 2 : imagejpeg($resource, '', $this->quality); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1473 | break; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 1474 | case 3 : imagepng($resource); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1475 | break; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 1476 | default: echo 'Unable to display the image'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1477 | break; |
| 1478 | } |
| 1479 | } |
| 1480 | |
| 1481 | // -------------------------------------------------------------------- |
| 1482 | |
| 1483 | /** |
| 1484 | * Re-proportion Image Width/Height |
| 1485 | * |
| 1486 | * When creating thumbs, the desired width/height |
| 1487 | * can end up warping the image due to an incorrect |
| 1488 | * ratio between the full-sized image and the thumb. |
| 1489 | * |
| 1490 | * This function lets us re-proportion the width/height |
| 1491 | * if users choose to maintain the aspect ratio when resizing. |
| 1492 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1493 | * @return void |
| 1494 | */ |
Andrey Andreev | 4eea989 | 2011-12-19 12:05:41 +0200 | [diff] [blame] | 1495 | public function image_reproportion() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1496 | { |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 1497 | if (($this->width == 0 && $this->height == 0) OR $this->orig_width == 0 OR $this->orig_height == 0 |
| 1498 | OR ( ! preg_match('/^[0-9]+$/', $this->width) && ! preg_match('/^[0-9]+$/', $this->height)) |
| 1499 | OR ! preg_match('/^[0-9]+$/', $this->orig_width) OR ! preg_match('/^[0-9]+$/', $this->orig_height)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1500 | { |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 1501 | return; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1502 | } |
| 1503 | |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 1504 | // Sanitize so we don't call preg_match() anymore |
| 1505 | $this->width = (int) $this->width; |
| 1506 | $this->height = (int) $this->height; |
| 1507 | |
| 1508 | if ($this->master_dim !== 'width' && $this->master_dim !== 'height') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1509 | { |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 1510 | if ($this->width > 0 && $this->height > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1511 | { |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 1512 | $this->master_dim = ((($this->orig_height/$this->orig_width) - ($this->height/$this->width)) < 0) |
| 1513 | ? 'width' : 'height'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1514 | } |
| 1515 | else |
| 1516 | { |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 1517 | $this->master_dim = ($this->height === 0) ? 'width' : 'height'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1518 | } |
| 1519 | } |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 1520 | elseif (($this->master_dim === 'width' && $this->width === 0) |
| 1521 | OR ($this->master_dim === 'height' && $this->height === 0)) |
| 1522 | { |
| 1523 | return; |
| 1524 | } |
| 1525 | |
| 1526 | if ($this->master_dim === 'width') |
| 1527 | { |
| 1528 | $this->height = (int) ceil($this->width*$this->orig_height/$this->orig_width); |
| 1529 | } |
| 1530 | else |
| 1531 | { |
| 1532 | $this->width = (int) ceil($this->orig_width*$this->height/$this->orig_height); |
| 1533 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1534 | } |
| 1535 | |
| 1536 | // -------------------------------------------------------------------- |
| 1537 | |
| 1538 | /** |
| 1539 | * Get image properties |
| 1540 | * |
| 1541 | * A helper function that gets info about the file |
| 1542 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1543 | * @param string |
Timothy Warren | b82bc3a | 2012-04-27 09:12:58 -0400 | [diff] [blame] | 1544 | * @param bool |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1545 | * @return mixed |
| 1546 | */ |
Andrey Andreev | 4eea989 | 2011-12-19 12:05:41 +0200 | [diff] [blame] | 1547 | public function get_image_properties($path = '', $return = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1548 | { |
| 1549 | // For now we require GD but we should |
| 1550 | // find a way to determine this using IM or NetPBM |
| 1551 | |
| 1552 | if ($path == '') |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 1553 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1554 | $path = $this->full_src_path; |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 1555 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1556 | |
| 1557 | if ( ! file_exists($path)) |
| 1558 | { |
| 1559 | $this->set_error('imglib_invalid_path'); |
| 1560 | return FALSE; |
| 1561 | } |
| 1562 | |
Phil Sturgeon | 901998a | 2011-08-26 10:03:33 +0100 | [diff] [blame] | 1563 | $vals = getimagesize($path); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1564 | $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); |
Andrey Andreev | a92b903 | 2011-12-24 19:05:58 +0200 | [diff] [blame] | 1565 | $mime = (isset($types[$vals[2]])) ? 'image/'.$types[$vals[2]] : 'image/jpg'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1566 | |
| 1567 | if ($return == TRUE) |
| 1568 | { |
Andrey Andreev | a92b903 | 2011-12-24 19:05:58 +0200 | [diff] [blame] | 1569 | return array( |
| 1570 | 'width' => $vals[0], |
| 1571 | 'height' => $vals[1], |
| 1572 | 'image_type' => $vals[2], |
| 1573 | 'size_str' => $vals[3], |
| 1574 | 'mime_type' => $mime |
| 1575 | ); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1576 | } |
| 1577 | |
Andrey Andreev | a92b903 | 2011-12-24 19:05:58 +0200 | [diff] [blame] | 1578 | $this->orig_width = $vals[0]; |
| 1579 | $this->orig_height = $vals[1]; |
| 1580 | $this->image_type = $vals[2]; |
| 1581 | $this->size_str = $vals[3]; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1582 | $this->mime_type = $mime; |
| 1583 | |
| 1584 | return TRUE; |
| 1585 | } |
| 1586 | |
| 1587 | // -------------------------------------------------------------------- |
| 1588 | |
| 1589 | /** |
| 1590 | * Size calculator |
| 1591 | * |
| 1592 | * This function takes a known width x height and |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 1593 | * recalculates it to a new size. Only one |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1594 | * new variable needs to be known |
| 1595 | * |
| 1596 | * $props = array( |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 1597 | * 'width' => $width, |
| 1598 | * 'height' => $height, |
| 1599 | * 'new_width' => 40, |
| 1600 | * 'new_height' => '' |
| 1601 | * ); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1602 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1603 | * @param array |
| 1604 | * @return array |
| 1605 | */ |
Andrey Andreev | 4eea989 | 2011-12-19 12:05:41 +0200 | [diff] [blame] | 1606 | public function size_calculator($vals) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1607 | { |
| 1608 | if ( ! is_array($vals)) |
| 1609 | { |
| 1610 | return; |
| 1611 | } |
| 1612 | |
| 1613 | $allowed = array('new_width', 'new_height', 'width', 'height'); |
| 1614 | |
| 1615 | foreach ($allowed as $item) |
| 1616 | { |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 1617 | if (empty($vals[$item])) |
| 1618 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1619 | $vals[$item] = 0; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame^] | 1620 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1621 | } |
| 1622 | |
| 1623 | if ($vals['width'] == 0 OR $vals['height'] == 0) |
| 1624 | { |
| 1625 | return $vals; |
| 1626 | } |
| 1627 | |
| 1628 | if ($vals['new_width'] == 0) |
| 1629 | { |
| 1630 | $vals['new_width'] = ceil($vals['width']*$vals['new_height']/$vals['height']); |
| 1631 | } |
| 1632 | elseif ($vals['new_height'] == 0) |
| 1633 | { |
| 1634 | $vals['new_height'] = ceil($vals['new_width']*$vals['height']/$vals['width']); |
| 1635 | } |
| 1636 | |
| 1637 | return $vals; |
| 1638 | } |
| 1639 | |
| 1640 | // -------------------------------------------------------------------- |
| 1641 | |
| 1642 | /** |
| 1643 | * Explode source_image |
| 1644 | * |
| 1645 | * This is a helper function that extracts the extension |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 1646 | * from the source_image. This function lets us deal with |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 1647 | * source_images with multiple periods, like: my.cool.jpg |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1648 | * It returns an associative array with two elements: |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 1649 | * $array['ext'] = '.jpg'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1650 | * $array['name'] = 'my.cool'; |
| 1651 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1652 | * @param array |
| 1653 | * @return array |
| 1654 | */ |
Andrey Andreev | 4eea989 | 2011-12-19 12:05:41 +0200 | [diff] [blame] | 1655 | public function explode_name($source_image) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1656 | { |
Derek Jones | 08cae63 | 2009-02-10 20:03:29 +0000 | [diff] [blame] | 1657 | $ext = strrchr($source_image, '.'); |
| 1658 | $name = ($ext === FALSE) ? $source_image : substr($source_image, 0, -strlen($ext)); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1659 | |
Derek Jones | 08cae63 | 2009-02-10 20:03:29 +0000 | [diff] [blame] | 1660 | return array('ext' => $ext, 'name' => $name); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1661 | } |
| 1662 | |
| 1663 | // -------------------------------------------------------------------- |
| 1664 | |
| 1665 | /** |
| 1666 | * Is GD Installed? |
| 1667 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1668 | * @return bool |
| 1669 | */ |
Andrey Andreev | 4eea989 | 2011-12-19 12:05:41 +0200 | [diff] [blame] | 1670 | public function gd_loaded() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1671 | { |
| 1672 | if ( ! extension_loaded('gd')) |
| 1673 | { |
Andrey Andreev | a92b903 | 2011-12-24 19:05:58 +0200 | [diff] [blame] | 1674 | /* As it is stated in the PHP manual, dl() is not always available |
| 1675 | * and even if so - it could generate an E_WARNING message on failure |
| 1676 | */ |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 1677 | return (function_exists('dl') && @dl('gd.so')); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1678 | } |
| 1679 | |
| 1680 | return TRUE; |
| 1681 | } |
| 1682 | |
| 1683 | // -------------------------------------------------------------------- |
| 1684 | |
| 1685 | /** |
| 1686 | * Get GD version |
| 1687 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1688 | * @return mixed |
| 1689 | */ |
Andrey Andreev | 4eea989 | 2011-12-19 12:05:41 +0200 | [diff] [blame] | 1690 | public function gd_version() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1691 | { |
| 1692 | if (function_exists('gd_info')) |
| 1693 | { |
| 1694 | $gd_version = @gd_info(); |
Andrey Andreev | 8e70b79 | 2012-01-12 20:19:24 +0200 | [diff] [blame] | 1695 | return preg_replace('/\D/', '', $gd_version['GD Version']); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1696 | } |
| 1697 | |
| 1698 | return FALSE; |
| 1699 | } |
| 1700 | |
| 1701 | // -------------------------------------------------------------------- |
| 1702 | |
| 1703 | /** |
| 1704 | * Set error message |
| 1705 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1706 | * @param string |
| 1707 | * @return void |
| 1708 | */ |
Andrey Andreev | 4eea989 | 2011-12-19 12:05:41 +0200 | [diff] [blame] | 1709 | public function set_error($msg) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1710 | { |
| 1711 | $CI =& get_instance(); |
| 1712 | $CI->lang->load('imglib'); |
| 1713 | |
| 1714 | if (is_array($msg)) |
| 1715 | { |
| 1716 | foreach ($msg as $val) |
| 1717 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1718 | $msg = ($CI->lang->line($val) == FALSE) ? $val : $CI->lang->line($val); |
| 1719 | $this->error_msg[] = $msg; |
| 1720 | log_message('error', $msg); |
| 1721 | } |
| 1722 | } |
| 1723 | else |
| 1724 | { |
| 1725 | $msg = ($CI->lang->line($msg) == FALSE) ? $msg : $CI->lang->line($msg); |
| 1726 | $this->error_msg[] = $msg; |
| 1727 | log_message('error', $msg); |
| 1728 | } |
| 1729 | } |
| 1730 | |
| 1731 | // -------------------------------------------------------------------- |
| 1732 | |
| 1733 | /** |
| 1734 | * Show error messages |
| 1735 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1736 | * @param string |
Timothy Warren | b82bc3a | 2012-04-27 09:12:58 -0400 | [diff] [blame] | 1737 | * @param string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1738 | * @return string |
| 1739 | */ |
Andrey Andreev | 4eea989 | 2011-12-19 12:05:41 +0200 | [diff] [blame] | 1740 | public function display_errors($open = '<p>', $close = '</p>') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1741 | { |
Andrey Andreev | 2c8baeb | 2012-01-19 15:45:28 +0200 | [diff] [blame] | 1742 | return (count($this->error_msg) > 0) ? $open.implode($close.$open, $this->error_msg).$close : ''; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1743 | } |
| 1744 | |
| 1745 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1746 | |
| 1747 | /* End of file Image_lib.php */ |
Andrey Andreev | 1b81553 | 2012-04-03 16:06:03 +0300 | [diff] [blame] | 1748 | /* Location: ./system/libraries/Image_lib.php */ |