~canonical-sysadmins/wordpress/4.8.1

« back to all changes in this revision

Viewing changes to wp-admin/includes/image-edit.php

  • Committer: Barry Price
  • Date: 2016-08-17 04:49:28 UTC
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: barry.price@canonical.com-20160817044928-viijiwb4tl8jwzmp
new upstream release 4.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
                <legend><?php _e( 'New dimensions:' ); ?></legend>
61
61
                <div class="nowrap">
62
62
                <label><span class="screen-reader-text"><?php _e( 'scale width' ); ?></span>
63
 
                <input type="text" id="imgedit-scale-width-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleChanged(<?php echo $post_id; ?>, 1)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 1)" value="<?php echo isset( $meta['width'] ) ? $meta['width'] : 0; ?>" />
 
63
                <input type="text" id="imgedit-scale-width-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleChanged(<?php echo $post_id; ?>, 1, this)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 1, this)" value="<?php echo isset( $meta['width'] ) ? $meta['width'] : 0; ?>" />
64
64
                </label>
65
65
                <span class="imgedit-separator">&times;</span>
66
66
                <label><span class="screen-reader-text"><?php _e( 'scale height' ); ?></span>
67
 
                <input type="text" id="imgedit-scale-height-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleChanged(<?php echo $post_id; ?>, 0)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 0)" value="<?php echo isset( $meta['height'] ) ? $meta['height'] : 0; ?>" />
 
67
                <input type="text" id="imgedit-scale-height-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleChanged(<?php echo $post_id; ?>, 0, this)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 0, this)" value="<?php echo isset( $meta['height'] ) ? $meta['height'] : 0; ?>" />
68
68
                </label>
69
69
                <span class="imgedit-scale-warn" id="imgedit-scale-warn-<?php echo $post_id; ?>">!</span>
70
70
                <input id="imgedit-scale-button" type="button" onclick="imageEdit.action(<?php echo "$post_id, '$nonce'"; ?>, 'scale')" class="button button-primary" value="<?php esc_attr_e( 'Scale' ); ?>" />
116
116
                <legend><?php _e( 'Aspect ratio:' ); ?></legend>
117
117
                <div class="nowrap">
118
118
                <label><span class="screen-reader-text"><?php _e( 'crop ratio width' ); ?></span>
119
 
                <input type="text" id="imgedit-crop-width-<?php echo $post_id; ?>" onkeyup="imageEdit.setRatioSelection(<?php echo $post_id; ?>, 0, this)" />
 
119
                <input type="text" id="imgedit-crop-width-<?php echo $post_id; ?>" onkeyup="imageEdit.setRatioSelection(<?php echo $post_id; ?>, 0, this)" onblur="imageEdit.setRatioSelection(<?php echo $post_id; ?>, 0, this)" />
120
120
                </label>
121
121
                <span class="imgedit-separator">:</span>
122
122
                <label><span class="screen-reader-text"><?php _e( 'crop ratio height' ); ?></span>
123
 
                <input type="text" id="imgedit-crop-height-<?php echo $post_id; ?>" onkeyup="imageEdit.setRatioSelection(<?php echo $post_id; ?>, 1, this)" />
 
123
                <input type="text" id="imgedit-crop-height-<?php echo $post_id; ?>" onkeyup="imageEdit.setRatioSelection(<?php echo $post_id; ?>, 1, this)" onblur="imageEdit.setRatioSelection(<?php echo $post_id; ?>, 1, this)" />
124
124
                </label>
125
125
                </div>
126
126
        </fieldset>
129
129
                <legend><?php _e( 'Selection:' ); ?></legend>
130
130
                <div class="nowrap">
131
131
                <label><span class="screen-reader-text"><?php _e( 'selection width' ); ?></span>
132
 
                <input type="text" id="imgedit-sel-width-<?php echo $post_id; ?>" onkeyup="imageEdit.setNumSelection(<?php echo $post_id; ?>)" />
 
132
                <input type="text" id="imgedit-sel-width-<?php echo $post_id; ?>" onkeyup="imageEdit.setNumSelection(<?php echo $post_id; ?>, this)" onblur="imageEdit.setNumSelection(<?php echo $post_id; ?>, this)" />
133
133
                </label>
134
134
                <span class="imgedit-separator">&times;</span>
135
135
                <label><span class="screen-reader-text"><?php _e( 'selection height' ); ?></span>
136
 
                <input type="text" id="imgedit-sel-height-<?php echo $post_id; ?>" onkeyup="imageEdit.setNumSelection(<?php echo $post_id; ?>)" />
 
136
                <input type="text" id="imgedit-sel-height-<?php echo $post_id; ?>" onkeyup="imageEdit.setNumSelection(<?php echo $post_id; ?>, this)" onblur="imageEdit.setNumSelection(<?php echo $post_id; ?>, this)" />
137
137
                </label>
138
138
                </div>
139
139
        </fieldset>
224
224
 
225
225
        </div>
226
226
        <div class="imgedit-wait" id="imgedit-wait-<?php echo $post_id; ?>"></div>
227
 
        <script type="text/javascript">jQuery( function() { imageEdit.init(<?php echo $post_id; ?>); });</script>
228
227
        <div class="hidden" id="imgedit-leaving-<?php echo $post_id; ?>"><?php _e("There are unsaved changes that will be lost. 'OK' to continue, 'Cancel' to return to the Image Editor."); ?></div>
229
228
        </div>
230
229
<?php
243
242
        if ( $image instanceof WP_Image_Editor ) {
244
243
 
245
244
                /**
246
 
                 * Filter the WP_Image_Editor instance for the image to be streamed to the browser.
 
245
                 * Filters the WP_Image_Editor instance for the image to be streamed to the browser.
247
246
                 *
248
247
                 * @since 3.5.0
249
248
                 *
257
256
 
258
257
                return true;
259
258
        } else {
260
 
                _deprecated_argument( __FUNCTION__, '3.5', __( '$image needs to be an WP_Image_Editor object' ) );
 
259
                _deprecated_argument( __FUNCTION__, '3.5.0', __( '$image needs to be an WP_Image_Editor object' ) );
261
260
 
262
261
                /**
263
 
                 * Filter the GD image resource to be streamed to the browser.
 
262
                 * Filters the GD image resource to be streamed to the browser.
264
263
                 *
265
264
                 * @since 2.9.0
266
265
                 * @deprecated 3.5.0 Use image_editor_save_pre instead.
302
301
                $image = apply_filters( 'image_editor_save_pre', $image, $post_id );
303
302
 
304
303
                /**
305
 
                 * Filter whether to skip saving the image file.
 
304
                 * Filters whether to skip saving the image file.
306
305
                 *
307
306
                 * Returning a non-null value will short-circuit the save method,
308
307
                 * returning that value instead.
322
321
 
323
322
                return $image->save( $filename, $mime_type );
324
323
        } else {
325
 
                _deprecated_argument( __FUNCTION__, '3.5', __( '$image needs to be an WP_Image_Editor object' ) );
 
324
                _deprecated_argument( __FUNCTION__, '3.5.0', __( '$image needs to be an WP_Image_Editor object' ) );
326
325
 
327
326
                /** This filter is documented in wp-admin/includes/image-edit.php */
328
327
                $image = apply_filters( 'image_save_pre', $image, $post_id );
329
328
 
330
329
                /**
331
 
                 * Filter whether to skip saving the image file.
 
330
                 * Filters whether to skip saving the image file.
332
331
                 *
333
332
                 * Returning a non-null value will short-circuit the save method,
334
333
                 * returning that value instead.
388
387
 * @return resource|false GD image resource, false otherwise.
389
388
 */
390
389
function _rotate_image_resource($img, $angle) {
391
 
        _deprecated_function( __FUNCTION__, '3.5', __( 'Use WP_Image_Editor::rotate' ) );
 
390
        _deprecated_function( __FUNCTION__, '3.5.0', __( 'Use WP_Image_Editor::rotate' ) );
392
391
        if ( function_exists('imagerotate') ) {
393
392
                $rotated = imagerotate($img, $angle, 0);
394
393
                if ( is_resource($rotated) ) {
411
410
 * @return resource (maybe) flipped image resource.
412
411
 */
413
412
function _flip_image_resource($img, $horz, $vert) {
414
 
        _deprecated_function( __FUNCTION__, '3.5', __( 'Use WP_Image_Editor::flip' ) );
 
413
        _deprecated_function( __FUNCTION__, '3.5.0', __( 'Use WP_Image_Editor::flip' ) );
415
414
        $w = imagesx($img);
416
415
        $h = imagesy($img);
417
416
        $dst = wp_imagecreatetruecolor($w, $h);
458
457
 *
459
458
 * @since 2.9.0
460
459
 *
461
 
 * @param WP_Image_Editor $image   {@see WP_Image_Editor} instance.
 
460
 * @param WP_Image_Editor $image   WP_Image_Editor instance.
462
461
 * @param array           $changes Array of change operations.
463
 
 * @return WP_Image_Editor {@see WP_Image_Editor} instance with changes applied.
 
462
 * @return WP_Image_Editor WP_Image_Editor instance with changes applied.
464
463
 */
465
464
function image_edit_apply_changes( $image, $changes ) {
466
465
        if ( is_resource( $image ) )
467
 
                _deprecated_argument( __FUNCTION__, '3.5', __( '$image needs to be an WP_Image_Editor object' ) );
 
466
                _deprecated_argument( __FUNCTION__, '3.5.0', __( '$image needs to be an WP_Image_Editor object' ) );
468
467
 
469
468
        if ( !is_array($changes) )
470
469
                return $image;
515
514
        if ( $image instanceof WP_Image_Editor ) {
516
515
 
517
516
                /**
518
 
                 * Filter the WP_Image_Editor instance before applying changes to the image.
 
517
                 * Filters the WP_Image_Editor instance before applying changes to the image.
519
518
                 *
520
519
                 * @since 3.5.0
521
520
                 *
526
525
        } elseif ( is_resource( $image ) ) {
527
526
 
528
527
                /**
529
 
                 * Filter the GD image resource before applying changes to the image.
 
528
                 * Filters the GD image resource before applying changes to the image.
530
529
                 *
531
530
                 * @since 2.9.0
532
531
                 * @deprecated 3.5.0 Use wp_image_editor_before_change instead.
586
585
function stream_preview_image( $post_id ) {
587
586
        $post = get_post( $post_id );
588
587
 
589
 
        /** This filter is documented in wp-admin/admin.php */
590
 
        @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) );
 
588
        wp_raise_memory_limit( 'admin' );
591
589
 
592
590
        $img = wp_get_image_editor( _load_image_to_edit_path( $post_id ) );
593
591
 
827
825
                $success = $delete = $nocrop = true;
828
826
        }
829
827
 
 
828
        /*
 
829
         * We need to remove any existing resized image files because
 
830
         * a new crop or rotate could generate different sizes (and hence, filenames),
 
831
         * keeping the new resized images from overwriting the existing image files.
 
832
         * https://core.trac.wordpress.org/ticket/32171
 
833
         */
 
834
        if ( defined( 'IMAGE_EDIT_OVERWRITE' ) && IMAGE_EDIT_OVERWRITE && ! empty( $meta['sizes'] ) ) {
 
835
                foreach ( $meta['sizes'] as $size ) {
 
836
                        if ( ! empty( $size['file'] ) && preg_match( '/-e[0-9]{13}-/', $size['file'] ) ) {
 
837
                                $delete_file = path_join( $path_parts['dirname'], $size['file'] );
 
838
                                wp_delete_file( $delete_file );
 
839
                        }
 
840
                }
 
841
        }
 
842
 
830
843
        if ( isset( $sizes ) ) {
831
844
                $_sizes = array();
832
845