Ticket #5089: 5089.2.patch
| File 5089.2.patch, 3.3 KB (added by , 12 years ago) |
|---|
-
bp-core-avatars.php
572 572 if ( !apply_filters( 'bp_core_pre_avatar_handle_upload', true, $file, $upload_dir_filter ) ) 573 573 return true; 574 574 575 //read raw image data 576 $exif = @exif_read_data( $_FILES['file']['tmp_name'] ); 577 575 578 require_once( ABSPATH . '/wp-admin/includes/file.php' ); 576 579 577 580 $uploadErrors = array( … … 619 622 $size = @getimagesize( $bp->avatar_admin->original['file'] ); 620 623 $error = false; 621 624 622 // Check image size and shrink if too large 623 if ( $size[0] > bp_core_avatar_original_max_width() ) { 624 $editor = wp_get_image_editor( $bp->avatar_admin->original['file'] ); 625 $img_editor_args = array( 626 'methods' => array( 627 'resize', 628 'save', 629 'rotate' 630 ) 631 ); 625 632 626 if ( ! is_wp_error( $editor ) ) { 633 $img_editor_test = wp_image_editor_supports($img_editor_args); 634 635 if ( $img_editor_test !== false ) { 636 637 $editor = wp_get_image_editor( $bp->avatar_admin->original['file'] ); 638 639 if ( ! is_wp_error( $editor ) ) { 640 627 641 $editor->set_quality( 100 ); 628 629 $resized = $editor->resize( bp_core_avatar_original_max_width(), bp_core_avatar_original_max_width(), false ); 630 if ( ! is_wp_error( $resized ) ) { 642 643 $rotate_img = false; 644 $resize_img = false; 645 646 // Check image rotation and adjust if necessary 647 if( !empty( $exif['Orientation'] ) ) { 648 649 switch( $exif['Orientation'] ) { 650 case 3: 651 $editor->rotate( 180 ); 652 $rotate_img = true; 653 break; 654 case 6: 655 $editor->rotate( -90 ); 656 $rotate_img = true; 657 break; 658 case 8: 659 $editor->rotate( 90 ); 660 $rotate_img = true; 661 break; 662 } 663 } 664 665 // Check image size and shrink if too large 666 if ( $size[0] > bp_core_avatar_original_max_width() ) { 667 668 $resized = $editor->resize( bp_core_avatar_original_max_width(), bp_core_avatar_original_max_width(), false ); 669 670 if ( ! is_wp_error( $resized ) ) { 671 $resize_img = true; 672 } else { 673 674 $error = $resized; 675 } 676 677 } 678 679 // Save the image with changes to size and/or rotation 680 if( $rotate_img || $resize_img ) { 681 631 682 $thumb = $editor->save( $editor->generate_filename() ); 632 } else { 633 $error = $resized; 683 684 // Check for thumbnail creation errors 685 if ( false === $error && is_wp_error( $thumb ) ) { 686 $error = $thumb; 687 } 688 689 // Thumbnail is good so proceed 690 if ( false === $error ) { 691 $bp->avatar_admin->resized = $thumb; 692 } 634 693 } 635 694 636 // Check for thumbnail creation errors637 if ( false === $error && is_wp_error( $thumb ) ) {638 $error = $thumb;639 }640 641 // Thumbnail is good so proceed642 if ( false === $error ) {643 $bp->avatar_admin->resized = $thumb;644 }645 646 695 } else { 647 696 $error = $editor; 648 697 } 649 698 650 699 if ( false !== $error ) { 651 700 bp_core_add_message( sprintf( __( 'Upload Failed! Error was: %s', 'buddypress' ), $error->get_error_message() ), 'error' ); 652 701 return false; 653 } 702 } 654 703 } 704 else { 705 bp_core_add_message( 'Image editor not supported.' ); 706 } 655 707 656 708 if ( ! isset( $bp->avatar_admin->image ) ) 657 709 $bp->avatar_admin->image = new stdClass();