Changeset 12879 for trunk/admin/include/functions_upload.inc.php
- Timestamp:
- 01/12/12 22:37:28 (4 months ago)
- Files:
-
- 1 modified
-
trunk/admin/include/functions_upload.inc.php (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/include/functions_upload.inc.php
r12831 r12879 33 33 // default configuration for upload 34 34 $upload_form_config = array( 35 'websize_resize' => array( 36 'default' => true, 37 'can_be_null' => false, 38 ), 39 40 'websize_maxwidth' => array( 41 'default' => 800, 42 'min' => 100, 43 'max' => 1600, 44 'pattern' => '/^\d+$/', 45 'can_be_null' => true, 46 'error_message' => l10n('The websize maximum width must be a number between %d and %d'), 47 ), 48 49 'websize_maxheight' => array( 50 'default' => 600, 51 'min' => 100, 52 'max' => 1200, 53 'pattern' => '/^\d+$/', 54 'can_be_null' => true, 55 'error_message' => l10n('The websize maximum height must be a number between %d and %d'), 56 ), 57 58 'websize_quality' => array( 59 'default' => 95, 60 'min' => 50, 61 'max' => 100, 62 'pattern' => '/^\d+$/', 63 'can_be_null' => false, 64 'error_message' => l10n('The websize image quality must be a number between %d and %d'), 65 ), 66 67 'thumb_maxwidth' => array( 68 'default' => 128, 69 'min' => 50, 70 'max' => 300, 71 'pattern' => '/^\d+$/', 72 'can_be_null' => false, 73 'error_message' => l10n('The thumbnail maximum width must be a number between %d and %d'), 74 ), 75 76 'thumb_maxheight' => array( 77 'default' => 96, 78 'min' => 50, 79 'max' => 300, 80 'pattern' => '/^\d+$/', 81 'can_be_null' => false, 82 'error_message' => l10n('The thumbnail maximum height must be a number between %d and %d'), 83 ), 84 85 'thumb_quality' => array( 86 'default' => 95, 87 'min' => 50, 88 'max' => 100, 89 'pattern' => '/^\d+$/', 90 'can_be_null' => false, 91 'error_message' => l10n('The thumbnail image quality must be a number between %d and %d'), 92 ), 93 94 'thumb_crop' => array( 35 'original_resize' => array( 95 36 'default' => false, 96 37 'can_be_null' => false, 97 38 ), 98 99 'thumb_follow_orientation' => array( 100 'default' => true, 101 'can_be_null' => false, 102 ), 103 104 'hd_keep' => array( 105 'default' => true, 106 'can_be_null' => false, 107 ), 108 109 'hd_resize' => array( 110 'default' => false, 111 'can_be_null' => false, 112 ), 113 114 'hd_maxwidth' => array( 39 40 'original_resize_maxwidth' => array( 115 41 'default' => 2000, 116 42 'min' => 500, … … 118 44 'pattern' => '/^\d+$/', 119 45 'can_be_null' => false, 120 'error_message' => l10n('The high definitionmaximum width must be a number between %d and %d'),46 'error_message' => l10n('The original maximum width must be a number between %d and %d'), 121 47 ), 122 48 123 ' hd_maxheight' => array(49 'original_resize_maxheight' => array( 124 50 'default' => 2000, 125 'min' => 500,51 'min' => 300, 126 52 'max' => 20000, 127 53 'pattern' => '/^\d+$/', 128 54 'can_be_null' => false, 129 'error_message' => l10n('The high definitionmaximum height must be a number between %d and %d'),55 'error_message' => l10n('The original maximum height must be a number between %d and %d'), 130 56 ), 131 57 132 ' hd_quality' => array(58 'original_resize_quality' => array( 133 59 'default' => 95, 134 60 'min' => 50, 135 'max' => 100,61 'max' => 98, 136 62 'pattern' => '/^\d+$/', 137 63 'can_be_null' => false, 138 'error_message' => l10n('The high definitionimage quality must be a number between %d and %d'),64 'error_message' => l10n('The original image quality must be a number between %d and %d'), 139 65 ), 140 66 ); … … 171 97 172 98 $updates[] = array( 173 'param' => 'upload_form_'.$field,99 'param' => $field, 174 100 'value' => boolean_to_string($value) 175 101 ); … … 178 104 { 179 105 $updates[] = array( 180 'param' => 'upload_form_'.$field,106 'param' => $field, 181 107 'value' => 'false' 182 108 ); … … 191 117 { 192 118 $updates[] = array( 193 'param' => 'upload_form_'.$field,119 'param' => $field, 194 120 'value' => $value 195 121 ); … … 227 153 function add_uploaded_file($source_filepath, $original_filename=null, $categories=null, $level=null, $image_id=null) 228 154 { 229 // Here is the plan230 //231 155 // 1) move uploaded file to upload/2010/01/22/20100122003814-449ada00.jpg 232 156 // 233 // 2) if taller than max_height or wider than max_width, move to pwg_high 234 // + web sized creation 157 // 2) keep/resize original 235 158 // 236 // 3) thumbnail creation from web sized 237 // 238 // 4) register in database 159 // 3) register in database 239 160 240 161 // TODO … … 248 169 if (isset($image_id)) 249 170 { 250 // we are performing an update171 // this photo already exists, we update it 251 172 $query = ' 252 173 SELECT … … 317 238 } 318 239 319 if ($conf['upload_form_websize_resize'] 320 and need_resize($file_path, $conf['upload_form_websize_maxwidth'], $conf['upload_form_websize_maxheight'])) 321 { 322 $high_path = file_path_for_type($file_path, 'high'); 323 $high_dir = dirname($high_path); 324 prepare_directory($high_dir); 325 326 rename($file_path, $high_path); 327 $high_infos = pwg_image_infos($high_path); 328 329 $img = new pwg_image($high_path); 330 331 $img->pwg_resize( 332 $file_path, 333 $conf['upload_form_websize_maxwidth'], 334 $conf['upload_form_websize_maxheight'], 335 $conf['upload_form_websize_quality'], 336 $conf['upload_form_automatic_rotation'], 337 false 338 ); 339 340 if ($img->library != 'gd') 341 { 342 if ($conf['upload_form_hd_keep']) 240 if (pwg_image::get_library() != 'gd') 241 { 242 if ($conf['original_resize']) 243 { 244 $need_resize = need_resize($file_path, $conf['original_resize_maxwidth'], $conf['original_resize_maxheight']); 245 246 if ($need_resize) 343 247 { 344 if ($conf['upload_form_hd_resize']) 345 { 346 $need_resize = need_resize($high_path, $conf['upload_form_hd_maxwidth'], $conf['upload_form_hd_maxheight']); 248 $img = new pwg_image($file_path); 249 250 $img->pwg_resize( 251 $file_path, 252 $conf['original_resize_maxwidth'], 253 $conf['original_resize_maxheight'], 254 $conf['original_resize_quality'], 255 $conf['upload_form_automatic_rotation'], 256 false 257 ); 347 258 348 if ($need_resize) 349 { 350 $img->pwg_resize( 351 $high_path, 352 $conf['upload_form_hd_maxwidth'], 353 $conf['upload_form_hd_maxheight'], 354 $conf['upload_form_hd_quality'], 355 $conf['upload_form_automatic_rotation'], 356 false 357 ); 358 $high_infos = pwg_image_infos($high_path); 359 } 360 } 259 $img->destroy(); 361 260 } 362 else 363 { 364 unlink($high_path); 365 $high_infos = null; 366 } 367 } 368 $img->destroy(); 261 } 369 262 } 370 263 371 264 $file_infos = pwg_image_infos($file_path); 372 265 373 $thumb_path = file_path_for_type($file_path, 'thumb');374 $thumb_dir = dirname($thumb_path);375 prepare_directory($thumb_dir);376 377 $img = new pwg_image($file_path);378 $img->pwg_resize(379 $thumb_path,380 $conf['upload_form_thumb_maxwidth'],381 $conf['upload_form_thumb_maxheight'],382 $conf['upload_form_thumb_quality'],383 false,384 true,385 $conf['upload_form_thumb_crop'],386 $conf['upload_form_thumb_follow_orientation']387 );388 $img->destroy();389 390 $thumb_infos = pwg_image_infos($thumb_path);391 392 266 if (isset($image_id)) 393 267 { 394 268 $update = array( 395 'id' => $image_id,396 269 'file' => pwg_db_real_escape_string(isset($original_filename) ? $original_filename : basename($file_path)), 397 270 'filesize' => $file_infos['filesize'], … … 402 275 ); 403 276 404 if (isset($high_infos))405 {406 $update['has_high'] = 'true';407 $update['high_filesize'] = $high_infos['filesize'];408 $update['high_width'] = $high_infos['width'];409 $update['high_height'] = $high_infos['height'];410 }411 else412 {413 $update['has_high'] = 'false';414 $update['high_filesize'] = null;415 $update['high_width'] = null;416 $update['high_height'] = null;417 }418 419 277 if (isset($level)) 420 278 { … … 422 280 } 423 281 424 mass_updates(282 single_update( 425 283 IMAGES_TABLE, 426 array( 427 'primary' => array('id'), 428 'update' => array_keys($update) 429 ), 430 array($update) 284 $update, 285 array('id' => $image_id) 431 286 ); 432 287 } … … 458 313 $insert['level'] = $level; 459 314 } 460 461 mass_inserts( 462 IMAGES_TABLE, 463 array_keys($insert), 464 array($insert) 465 ); 315 316 single_insert(IMAGES_TABLE, $insert); 466 317 467 318 $image_id = pwg_db_insert_id(IMAGES_TABLE);
![(please configure the [header_logo] section in trac.ini)](http://piwigo.org/screenshots/piwigo_logo_on_white.png)