Changeset 11984 for trunk/wp-admin/includes/image-edit.php
- Timestamp:
- 09/30/2009 08:38:32 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/image-edit.php
r11973 r11984 11 11 $meta = wp_get_attachment_metadata($post_id); 12 12 $thumb = image_get_intermediate_size($post_id, 'thumbnail'); 13 $sub_sizes = isset($meta['sizes']) && is_array($meta['sizes']); 13 14 $note = ''; 14 15 … … 16 17 $big = max( $meta['width'], $meta['height'] ); 17 18 else 18 wp_die( __('Image data does not exist. Please re-upload the image.') );19 die( __('Image data does not exist. Please re-upload the image.') ); 19 20 20 21 $sizer = $big > 400 ? 400 / $big : 1; 21 22 22 23 $backup_sizes = get_post_meta( $post_id, '_wp_attachment_backup_sizes', true ); 23 $can_restore = !empty($backup_sizes) && isset($backup_sizes['full-orig']); 24 $can_restore = !empty($backup_sizes) && isset($backup_sizes['full-orig']) 25 && $backup_sizes['full-orig']['file'] != basename($meta['file']); 24 26 25 27 26 28 // temp convert backup sizes 27 if ( isset($meta['sizes']) && is_array($meta['sizes'])) {29 if ( $sub_sizes ) { 28 30 $update = false; 29 31 foreach ( $meta['sizes'] as $name => $val ) { … … 46 48 } 47 49 // end temp 48 49 50 50 51 if ( $msg ) { … … 169 170 </div> 170 171 171 <?php if ( $thumb ) {172 <?php if ( $thumb && $sub_sizes ) { 172 173 $thumb_img = wp_constrain_dimensions( $thumb['width'], $thumb['height'], 160, 120 ); 173 174 ?> … … 212 213 } 213 214 214 function load_image_to_edit($post, $size = 'full') { 215 $filename = get_attached_file($post->ID); 216 217 if ( 'full' != $size && ( $data = image_get_intermediate_size($post->ID, $size) ) ) 218 $filename = path_join( dirname($filename), $data['file'] ); 219 220 switch ( $post->post_mime_type ) { 215 function load_image_to_edit($post_id, $mime_type, $size = 'full') { 216 $filepath = get_attached_file($post_id); 217 218 if ( $filepath && file_exists($filepath) ) { 219 if ( 'full' != $size && ( $data = image_get_intermediate_size($post_id, $size) ) ) 220 $filepath = path_join( dirname($filepath), $data['file'] ); 221 } elseif ( function_exists('fopen') ) { 222 $filepath = wp_get_attachment_url($post_id); 223 } 224 225 $filepath = apply_filters('load_image_to_edit_path', $filepath, $post_id, $size); 226 if ( empty($filepath) ) 227 return false; 228 229 switch ( $mime_type ) { 221 230 case 'image/jpeg': 222 $image = imagecreatefromjpeg($file name);231 $image = imagecreatefromjpeg($filepath); 223 232 break; 224 233 case 'image/png': 225 $image = imagecreatefrompng($file name);234 $image = imagecreatefrompng($filepath); 226 235 break; 227 236 case 'image/gif': 228 $image = imagecreatefromgif($file name);237 $image = imagecreatefromgif($filepath); 229 238 break; 230 239 default: … … 233 242 } 234 243 if ( is_resource($image) ) { 235 $image = apply_filters('load_image_to_edit', $image, $post ->ID, $size);244 $image = apply_filters('load_image_to_edit', $image, $post_id, $size); 236 245 if ( function_exists('imagealphablending') && function_exists('imagesavealpha') ) { 237 246 imagealphablending($image, false); … … 242 251 } 243 252 244 function wp_stream_image($image, $mime_type, $post_id = 0, $intermediate_size = '') {245 $image = apply_filters('image_save_pre', $image, $post ->ID, $intermediate_size);253 function wp_stream_image($image, $mime_type, $post_id) { 254 $image = apply_filters('image_save_pre', $image, $post_id); 246 255 247 256 switch ( $mime_type ) { … … 260 269 } 261 270 262 function wp_save_image_file($filename, $image, $mime_type, $post_id = 0, $intermediate_size = '') { 263 $image = apply_filters('image_save_pre', $image, $post->ID, $intermediate_size); 271 function wp_save_image_file($filename, $image, $mime_type, $post_id) { 272 $image = apply_filters('image_save_pre', $image, $post_id); 273 $saved = apply_filters('wp_save_image_file', null, $filename, $image, $mime_type, $post_id); 274 if ( null !== $saved ) 275 return $saved; 264 276 265 277 switch ( $mime_type ) { … … 395 407 $post = get_post($post_id); 396 408 @ini_set('memory_limit', '256M'); 397 $img = load_image_to_edit( $post , array(400, 400) );409 $img = load_image_to_edit( $post_id, $post->post_mime_type, array(400, 400) ); 398 410 399 411 if ( !is_resource($img) ) … … 440 452 $data = $backup_sizes["$default_size-orig"]; 441 453 if ( 'full' == $default_size ) { 442 $backup_sizes["full-$suffix"] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $parts['basename']); 454 if ( $parts['basename'] != $data['file'] ) 455 $backup_sizes["full-$suffix"] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $parts['basename']); 443 456 444 457 $meta['file'] = path_join($parts['dirname'], $data['file']); … … 450 463 $restored = update_attached_file($post_id, $meta['file']); 451 464 } else { 452 if ( isset($meta['sizes'][$default_size]) )465 if ( isset($meta['sizes'][$default_size]) && $meta['sizes'][$default_size]['file'] != $data['file'] ) 453 466 $backup_sizes["$default_size-{$suffix}"] = $meta['sizes'][$default_size]; 454 467 455 468 $meta['sizes'][$default_size] = $data; 456 469 } 470 } else { 471 unset($meta['sizes'][$default_size]); 457 472 } 458 473 } … … 476 491 $post = get_post($post_id); 477 492 @ini_set('memory_limit', '256M'); 478 $img = load_image_to_edit($post );493 $img = load_image_to_edit($post_id, $post->post_mime_type); 479 494 480 495 if ( !is_resource($img) ) { … … 550 565 } 551 566 552 if ( 'nothumb' == $target || 'all' == $target || $scaled ) { 553 $tag = !isset($backup_sizes['full-orig']) ? 'full-orig' : "full-$suffix"; 554 $backup_sizes[$tag] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $path_parts['basename']); 567 if ( 'nothumb' == $target || 'all' == $target || 'full' == $target || $scaled ) { 568 $tag = false; 569 if ( isset($backup_sizes['full-orig']) ) { 570 if ( $backup_sizes['full-orig']['file'] != $path_parts['basename'] ) 571 $tag = "full-$suffix"; 572 } else { 573 $tag = 'full-orig'; 574 } 575 576 if ( $tag ) 577 $backup_sizes[$tag] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $path_parts['basename']); 555 578 556 579 $success = update_attached_file($post_id, $new_path); … … 577 600 if ( isset($sizes) ) { 578 601 foreach ( $sizes as $size ) { 602 $tag = false; 579 603 if ( isset($meta['sizes'][$size]) ) { 580 $tag = !isset($backup_sizes["$size-orig"]) ? "$size-orig" : "$size-$suffix"; 581 $backup_sizes[$tag] = $meta['sizes'][$size]; 604 if ( isset($backup_sizes["$size-orig"]) ) { 605 if ( $backup_sizes["$size-orig"]['file'] != $meta['sizes'][$size]['file'] ) 606 $tag = "$size-$suffix"; 607 } else { 608 $tag = "$size-orig"; 609 } 610 611 if ( $tag ) 612 $backup_sizes[$tag] = $meta['sizes'][$size]; 582 613 } 583 614 … … 596 627 update_post_meta( $post_id, '_wp_attachment_backup_sizes', $backup_sizes); 597 628 598 if ( $target == 'thumbnail' || $target == 'all' ) {629 if ( $target == 'thumbnail' || $target == 'all' || $target == 'full' ) { 599 630 if ( $thumb = $meta['sizes']['thumbnail'] ) { 600 631 $file_url = wp_get_attachment_url($post_id);
Note: See TracChangeset
for help on using the changeset viewer.