Make WordPress Core

Ticket #20657: 20657.7.patch

File 20657.7.patch, 4.4 KB (added by SergeyBiryukov, 13 years ago)
  • wp-admin/custom-header.php

     
    788788        <?php } ?>
    789789        <?php wp_nonce_field( 'custom-header-crop-image' ) ?>
    790790
    791         <?php submit_button( __( 'Crop and Publish' ) ); ?>
     791        <p class="submit"><?php
     792        submit_button( __( 'Crop and Publish' ), 'primary', 'submit', false );
     793        if ( isset( $oitar ) && 1 == $oitar )
     794                submit_button( __( 'Skip Cropping, Use Image as Is' ), 'primary', 'skip-cropping', false );
     795        ?>
    792796        </p>
    793797</form>
    794798</div>
     
    867871                else
    868872                        $dst_width = get_theme_support( 'custom-header', 'width' );
    869873
    870                 $cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], $dst_width, $dst_height );
    871                 if ( ! $cropped || is_wp_error( $cropped ) )
    872                         wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
     874                if ( !isset( $_POST['skip-cropping'] ) ) {
     875                        $cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], $dst_width, $dst_height );
     876                        if ( ! $cropped || is_wp_error( $cropped ) )
     877                                wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
     878                } else {
     879                        $cropped = get_attached_file( $attachment_id );
     880                }
    873881
    874882                $cropped = apply_filters('wp_create_file_in_uploads', $cropped, $attachment_id); // For replication
    875                 $is_cropped = ( get_attached_file( $attachment_id ) != $cropped );
     883                $is_cropped = ( !isset( $_POST['skip-cropping'] ) && ( get_attached_file( $attachment_id ) != $cropped ) );
    876884
    877885                $parent = get_post($attachment_id);
    878886                $parent_url = $parent->guid;
  • wp-admin/includes/image.php

     
    4444 * @return string|WP_Error|false New filepath on success, WP_Error or false on failure.
    4545 */
    4646function wp_crop_image( $src, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false ) {
    47         if ( 0 == $src_x && 0 == $src_y && $src_w == $dst_w && $src_h == $dst_h )
    48                 return ( is_numeric( $src ) ) ? get_attached_file( $src ) : $src;
     47        if ( 0 == $src_x && 0 == $src_y && $src_w == $dst_w && $src_h == $dst_h ) {
     48                // No cropping, just copy the file
     49                if ( is_numeric( $src ) ) {
     50                        $src_file = get_attached_file( $src );
     51                        if ( ! file_exists( $src_file ) )
     52                                $src_file = _load_image_file( $src );
     53                } else {
     54                        $src_file = $src;
     55                }
    4956
     57                if ( $src_file ) {
     58                        $dst_file = str_replace( basename( $src_file ), 'cropped-' . basename( $src_file ), $src_file );
     59                        return ( copy( $src_file, $dst_file ) ) ? $dst_file : false;
     60                } else {
     61                        return false;
     62                }
     63        }
     64
    5065        if ( is_numeric( $src ) ) { // Handle int as attachment ID
    5166                $src_file = get_attached_file( $src );
    5267                if ( ! file_exists( $src_file ) ) {
     
    364379        return apply_filters('file_is_displayable_image', $result, $path);
    365380}
    366381
    367 function load_image_to_edit($post_id, $mime_type, $size = 'full') {
     382/**
     383 * Attempt to load an attachment from URL (for replication plugins).
     384 *
     385 * @since 3.4.0
     386 * @access private
     387 *
     388 * @param string $post_id Attachment post ID.
     389 * @param string $size Optional. Image size, defaults to 'full'.
     390 * @return string|false Local file path on success, false on failure.
     391 */
     392function _load_image_file( $post_id, $size = 'full' ) {
    368393        $filepath = get_attached_file($post_id);
    369394
    370395        if ( $filepath && file_exists($filepath) ) {
     
    376401        }
    377402
    378403        $filepath = apply_filters('load_image_to_edit_path', $filepath, $post_id, $size);
    379         if ( empty($filepath) )
     404        if ( empty( $filepath ) )
    380405                return false;
     406}
    381407
     408/**
     409 * Load an image resource for editing.
     410 *
     411 * @since 2.9.0
     412 *
     413 * @param string $post_id Attachment post ID.
     414 * @param string $mime_type Image mime type.
     415 * @param string $size Optional. Image size, defaults to 'full'.
     416 * @return resource|false The resulting image resource on success, false on failure.
     417 */
     418function load_image_to_edit( $post_id, $mime_type, $size = 'full' ) {
     419        $filepath = _load_image_file( $post_id, $size );
     420        if ( empty( $filepath ) )
     421                return false;
     422
    382423        switch ( $mime_type ) {
    383424                case 'image/jpeg':
    384425                        $image = imagecreatefromjpeg($filepath);