WordPress.org

Make WordPress Core

Ticket #17242: 17242.diff

File 17242.diff, 7.2 KB (added by aaroncampbell, 6 years ago)
  • wp-admin/custom-header.php

     
    438438                jQuery('img#upload').imgAreaSelect({
    439439                        handles: true,
    440440                        keys: true,
    441                         aspectRatio: xinit + ':' + yinit,
    442441                        show: true,
    443442                        x1: 0,
    444443                        y1: 0,
    445444                        x2: xinit,
    446445                        y2: yinit,
    447                         maxHeight: <?php echo HEADER_IMAGE_HEIGHT; ?>,
    448446                        maxWidth: <?php echo HEADER_IMAGE_WIDTH; ?>,
    449447                        onInit: function () {
    450448                                jQuery('#width').val(xinit);
     
    510508<th scope="row"><?php _e( 'Upload Image' ); ?></th>
    511509<td>
    512510        <p><?php _e( 'You can upload a custom header image to be shown at the top of your site instead of the default one. On the next screen you will be able to crop the image.' ); ?><br />
    513         <?php printf( __( 'Images of exactly <strong>%1$d &times; %2$d pixels</strong> will be used as-is.' ), HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT ); ?></p>
     511        <?php
     512        $header_support = get_theme_support( 'custom-header' );
     513        if ( ! isset( $header_support[ 0 ] ) || empty( $header_support[ 0 ][ 'flex-height' ] ) || !$header_support[ 0 ][ 'flex-height' ] ) {
     514                printf( __( 'Images of exactly <strong>%1$d &times; %2$d pixels</strong> will be used as-is.' ), HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT );
     515        } else {
     516                printf( __( 'Images should be at least <strong>%1$d pixels</strong> wide.' ), HEADER_IMAGE_WIDTH );
     517                if ( !empty( $header_support[ 0 ][ 'suggested-height' ] ) )
     518                        printf( __( ' Suggested height is <strong>%1$d pixels</strong>.' ), absint( $header_support[ 0 ][ 'suggested-height' ] ) );
     519        }
     520        ?></p>
    514521        <form enctype="multipart/form-data" id="upload-form" method="post" action="<?php echo esc_attr( add_query_arg( 'step', 2 ) ) ?>">
    515522        <p>
    516523                <label for="upload"><?php _e( 'Choose an image from your computer:' ); ?></label><br />
     
    662669
    663670                list($width, $height, $type, $attr) = getimagesize( $file );
    664671
    665                 if ( $width == HEADER_IMAGE_WIDTH && $height == HEADER_IMAGE_HEIGHT ) {
     672                $header_support = get_theme_support( 'custom-header' );
     673                // If flexible height isn't supported and the image is the exact right size
     674                if ( ( !isset( $header_support[ 0 ] ) || empty( $header_support[ 0 ][ 'flex-height' ] ) || !empty( $header_support[ 0 ][ 'flex-height' ] ) ) && $width == HEADER_IMAGE_WIDTH && $height == HEADER_IMAGE_HEIGHT ) {
    666675                        // Add the meta-data
    667676                        wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
    668677                        update_post_meta( $id, '_wp_attachment_is_custom_header', get_option('stylesheet' ) );
     
    733742                $attachment_id = absint( $_POST['attachment_id'] );
    734743                $original = get_attached_file($attachment_id);
    735744
    736                 $cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT );
     745                $header_support = get_theme_support( 'custom-header' );
     746                if ( isset( $header_support[ 0 ] ) && !empty( $header_support[ 0 ][ 'flex-height' ] ) )
     747                        $dst_height = (int) $_POST['height'] * ( HEADER_IMAGE_WIDTH / $_POST['width'] );
     748                else
     749                        $dst_height = HEADER_IMAGE_HEIGHT;
     750
     751                $cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], HEADER_IMAGE_WIDTH, $dst_height );
    737752                if ( is_wp_error( $cropped ) )
    738753                        wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
    739754
  • wp-includes/js/imgareaselect/jquery.imgareaselect.dev.js

     
    11/*
    22 * imgAreaSelect jQuery plugin
    3  * version 0.9.6
     3 * version 0.9.8
    44 *
    55 * Copyright (c) 2008-2011 Michal Wojciechowski (odyniec.net)
    66 *
     
    5555
    5656        scaleX, scaleY,
    5757
    58         resizeMargin = 10,
    59 
    6058        resize,
    6159
    6260        minWidth, minHeight, maxWidth, maxHeight,
     
    134132        imgOfs.top += ($img.outerHeight() - imgHeight) >> 1;
    135133        imgOfs.left += ($img.outerWidth() - imgWidth) >> 1;
    136134
    137         minWidth = options.minWidth || 0;
    138         minHeight = options.minHeight || 0;
    139         maxWidth = min(options.maxWidth || 1<<24, imgWidth);
    140         maxHeight = min(options.maxHeight || 1<<24, imgHeight);
     135        minWidth = round(options.minWidth / scaleX) || 0;
     136        minHeight = round(options.minHeight / scaleY) || 0;
     137        maxWidth = round(min(options.maxWidth / scaleX || 1<<24, imgWidth));
     138        maxHeight = round(min(options.maxHeight / scaleY || 1<<24, imgHeight));
    141139
    142140        if ($().jquery == '1.3.2' && position == 'fixed' &&
    143141            !docElem['getBoundingClientRect'])
     
    146144            imgOfs.left += max(document.body.scrollLeft, docElem.scrollLeft);
    147145        }
    148146
    149         parOfs = $.inArray($parent.css('position'), ['absolute', 'relative']) + 1 ?
     147        parOfs = /absolute|relative/.test($parent.css('position')) ?
    150148            { left: round($parent.offset().left) - $parent.scrollLeft(),
    151149                top: round($parent.offset().top) - $parent.scrollTop() } :
    152150            position == 'fixed' ?
     
    365363    }
    366364
    367365    function selectingMouseMove(event) {
    368         x2 = resize == '' || /w|e/.test(resize) || aspectRatio ? evX(event) : viewX(selection.x2);
    369         y2 = resize == '' || /n|s/.test(resize) || aspectRatio ? evY(event) : viewY(selection.y2);
     366        x2 = /w|e|^$/.test(resize) || aspectRatio ? evX(event) : viewX(selection.x2);
     367        y2 = /n|s|^$/.test(resize) || aspectRatio ? evY(event) : viewY(selection.y2);
    370368
    371369        doResize();
    372370
     
    408406
    409407        resize = '';
    410408
    411         if ($outer.is(':not(:visible)'))
     409        if (!$outer.is(':visible'))
    412410            $box.add($outer).hide().fadeIn(options.fadeSpeed||0);
    413411
    414412        shown = true;
     
    427425
    428426        setSelection(selX(x1), selY(y1), selX(x1), selY(y1));
    429427
    430         options.onSelectChange(img, getSelection());
    431         options.onSelectEnd(img, getSelection());
     428        if (!this instanceof $.imgAreaSelect) {
     429            options.onSelectChange(img, getSelection());
     430            options.onSelectEnd(img, getSelection());
     431        }
    432432    }
    433433
    434434    function imgMouseDown(event) {
     
    606606        $box.append($area.add($border).add($areaOpera).add($handles));
    607607
    608608        if ($.browser.msie) {
    609             if (o = $outer.css('filter').match(/opacity=([0-9]+)/))
     609            if (o = $outer.css('filter').match(/opacity=(\d+)/))
    610610                $outer.css('opacity', o[1]/100);
    611             if (o = $border.css('filter').match(/opacity=([0-9]+)/))
     611            if (o = $border.css('filter').match(/opacity=(\d+)/))
    612612                $border.css('opacity', o[1]/100);
    613613        }
    614614
     
    656656
    657657    this.setSelection = setSelection;
    658658
     659    this.cancelSelection = cancelSelection;
     660
    659661    this.update = doUpdate;
    660662
    661663    $p = $img;
     
    689691    img.complete || img.readyState == 'complete' || !$img.is('img') ?
    690692        imgLoad() : $img.one('load', imgLoad);
    691693
    692     if ($.browser.msie && $.browser.version >= 9)
     694   if ($.browser.msie && $.browser.version >= 7)
    693695        img.src = img.src;
    694696};
    695697