wp/wp-admin/includes/image-edit.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
    38 		elseif ( isset($msg->msg) )
    38 		elseif ( isset($msg->msg) )
    39 			$note = "<div class='updated'><p>$msg->msg</p></div>";
    39 			$note = "<div class='updated'><p>$msg->msg</p></div>";
    40 	}
    40 	}
    41 
    41 
    42 	?>
    42 	?>
    43 	<div class="imgedit-wrap">
    43 	<div class="imgedit-wrap wp-clearfix">
    44 	<div id="imgedit-panel-<?php echo $post_id; ?>">
    44 	<div id="imgedit-panel-<?php echo $post_id; ?>">
    45 
    45 
    46 	<div class="imgedit-settings">
    46 	<div class="imgedit-settings">
    47 	<div class="imgedit-group">
    47 	<div class="imgedit-group">
    48 	<div class="imgedit-group-top">
    48 	<div class="imgedit-group-top">
    49 		<h3><?php _e( 'Scale Image' ); ?> <a href="#" class="dashicons dashicons-editor-help imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);return false;"></a></h3>
    49 		<h2><?php _e( 'Scale Image' ); ?></h2>
       
    50 		<button type="button" class="dashicons dashicons-editor-help imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);return false;" aria-expanded="false"><span class="screen-reader-text"><?php esc_html_e( 'Scale Image Help' ); ?></span></button>
    50 		<div class="imgedit-help">
    51 		<div class="imgedit-help">
    51 		<p><?php _e('You can proportionally scale the original image. For best results, scaling should be done before you crop, flip, or rotate. Images can only be scaled down, not up.'); ?></p>
    52 		<p><?php _e('You can proportionally scale the original image. For best results, scaling should be done before you crop, flip, or rotate. Images can only be scaled down, not up.'); ?></p>
    52 		</div>
    53 		</div>
    53 		<?php if ( isset( $meta['width'], $meta['height'] ) ): ?>
    54 		<?php if ( isset( $meta['width'], $meta['height'] ) ): ?>
    54 		<p><?php printf( __('Original dimensions %s'), $meta['width'] . ' &times; ' . $meta['height'] ); ?></p>
    55 		<p><?php printf( __('Original dimensions %s'), $meta['width'] . ' &times; ' . $meta['height'] ); ?></p>
    55 		<?php endif ?>
    56 		<?php endif ?>
    56 		<div class="imgedit-submit">
    57 		<div class="imgedit-submit">
    57 		<span class="nowrap"><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)" style="width:4em;" value="<?php echo isset( $meta['width'] ) ? $meta['width'] : 0; ?>" /> &times; <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)" style="width:4em;" value="<?php echo isset( $meta['height'] ) ? $meta['height'] : 0; ?>" />
    58 
    58 		<span class="imgedit-scale-warn" id="imgedit-scale-warn-<?php echo $post_id; ?>">!</span></span>
    59 		<fieldset class="imgedit-scale">
    59 		<input type="button" onclick="imageEdit.action(<?php echo "$post_id, '$nonce'"; ?>, 'scale')" class="button button-primary" value="<?php esc_attr_e( 'Scale' ); ?>" />
    60 		<legend><?php _e( 'New dimensions:' ); ?></legend>
       
    61 		<div class="nowrap">
       
    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, this)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 1, this)" value="<?php echo isset( $meta['width'] ) ? $meta['width'] : 0; ?>" />
       
    64 		</label>
       
    65 		<span class="imgedit-separator">&times;</span>
       
    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, this)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 0, this)" value="<?php echo isset( $meta['height'] ) ? $meta['height'] : 0; ?>" />
       
    68 		</label>
       
    69 		<span class="imgedit-scale-warn" id="imgedit-scale-warn-<?php echo $post_id; ?>">!</span>
       
    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' ); ?>" />
       
    71  		</div>
       
    72 		</fieldset>
       
    73 
    60 		</div>
    74 		</div>
    61 	</div>
    75 	</div>
    62 	</div>
    76 	</div>
    63 
    77 
    64 <?php if ( $can_restore ) { ?>
    78 <?php if ( $can_restore ) { ?>
    65 
    79 
    66 	<div class="imgedit-group">
    80 	<div class="imgedit-group">
    67 	<div class="imgedit-group-top">
    81 	<div class="imgedit-group-top">
    68 		<h3><a onclick="imageEdit.toggleHelp(this);return false;" href="#"><?php _e('Restore Original Image'); ?> <span class="dashicons dashicons-arrow-down imgedit-help-toggle"></span></a></h3>
    82 		<h2><button type="button" onclick="imageEdit.toggleHelp(this);" class="button-link"><?php _e( 'Restore Original Image' ); ?> <span class="dashicons dashicons-arrow-down imgedit-help-toggle"></span></button></h2>
    69 		<div class="imgedit-help">
    83 		<div class="imgedit-help">
    70 		<p><?php _e('Discard any changes and restore the original image.');
    84 		<p><?php _e('Discard any changes and restore the original image.');
    71 
    85 
    72 		if ( !defined('IMAGE_EDIT_OVERWRITE') || !IMAGE_EDIT_OVERWRITE )
    86 		if ( !defined('IMAGE_EDIT_OVERWRITE') || !IMAGE_EDIT_OVERWRITE )
    73 			echo ' '.__('Previously edited copies of the image will not be deleted.');
    87 			echo ' '.__('Previously edited copies of the image will not be deleted.');
    82 
    96 
    83 <?php } ?>
    97 <?php } ?>
    84 
    98 
    85 	<div class="imgedit-group">
    99 	<div class="imgedit-group">
    86 	<div class="imgedit-group-top">
   100 	<div class="imgedit-group-top">
    87 		<h3><?php _e('Image Crop'); ?> <a href="#" class="dashicons dashicons-editor-help imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);return false;"></a></h3>
   101 		<h2><?php _e( 'Image Crop' ); ?></h2>
       
   102 		<button type="button" class="dashicons dashicons-editor-help imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);return false;" aria-expanded="false"><span class="screen-reader-text"><?php esc_html_e( 'Image Crop Help' ); ?></span></button>
    88 
   103 
    89 		<div class="imgedit-help">
   104 		<div class="imgedit-help">
    90 		<p><?php _e('To crop the image, click on it and drag to make your selection.'); ?></p>
   105 		<p><?php _e('To crop the image, click on it and drag to make your selection.'); ?></p>
    91 
   106 
    92 		<p><strong><?php _e('Crop Aspect Ratio'); ?></strong><br />
   107 		<p><strong><?php _e('Crop Aspect Ratio'); ?></strong><br />
    95 		<p><strong><?php _e('Crop Selection'); ?></strong><br />
   110 		<p><strong><?php _e('Crop Selection'); ?></strong><br />
    96 		<?php _e('Once you have made your selection, you can adjust it by entering the size in pixels. The minimum selection size is the thumbnail size as set in the Media settings.'); ?></p>
   111 		<?php _e('Once you have made your selection, you can adjust it by entering the size in pixels. The minimum selection size is the thumbnail size as set in the Media settings.'); ?></p>
    97 		</div>
   112 		</div>
    98 	</div>
   113 	</div>
    99 
   114 
   100 	<p>
   115 	<fieldset class="imgedit-crop-ratio">
   101 		<?php _e('Aspect ratio:'); ?>
   116 		<legend><?php _e( 'Aspect ratio:' ); ?></legend>
   102 		<span  class="nowrap">
   117 		<div class="nowrap">
   103 		<input type="text" id="imgedit-crop-width-<?php echo $post_id; ?>" onkeyup="imageEdit.setRatioSelection(<?php echo $post_id; ?>, 0, this)" style="width:3em;" />
   118 		<label><span class="screen-reader-text"><?php _e( 'crop ratio width' ); ?></span>
   104 		:
   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)" />
   105 		<input type="text" id="imgedit-crop-height-<?php echo $post_id; ?>" onkeyup="imageEdit.setRatioSelection(<?php echo $post_id; ?>, 1, this)" style="width:3em;" />
   120 		</label>
   106 		</span>
   121 		<span class="imgedit-separator">:</span>
   107 	</p>
   122 		<label><span class="screen-reader-text"><?php _e( 'crop ratio height' ); ?></span>
   108 
   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)" />
   109 	<p id="imgedit-crop-sel-<?php echo $post_id; ?>">
   124 		</label>
   110 		<?php _e('Selection:'); ?>
   125 		</div>
   111 		<span  class="nowrap">
   126 	</fieldset>
   112 		<input type="text" id="imgedit-sel-width-<?php echo $post_id; ?>" onkeyup="imageEdit.setNumSelection(<?php echo $post_id; ?>)" style="width:4em;" />
   127 
   113 		&times;
   128 	<fieldset id="imgedit-crop-sel-<?php echo $post_id; ?>" class="imgedit-crop-sel">
   114 		<input type="text" id="imgedit-sel-height-<?php echo $post_id; ?>" onkeyup="imageEdit.setNumSelection(<?php echo $post_id; ?>)" style="width:4em;" />
   129 		<legend><?php _e( 'Selection:' ); ?></legend>
   115 		</span>
   130 		<div class="nowrap">
   116 	</p>
   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; ?>, this)" onblur="imageEdit.setNumSelection(<?php echo $post_id; ?>, this)" />
       
   133 		</label>
       
   134 		<span class="imgedit-separator">&times;</span>
       
   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; ?>, this)" onblur="imageEdit.setNumSelection(<?php echo $post_id; ?>, this)" />
       
   137 		</label>
       
   138 		</div>
       
   139 	</fieldset>
       
   140 
   117 	</div>
   141 	</div>
   118 
   142 
   119 	<?php if ( $thumb && $sub_sizes ) {
   143 	<?php if ( $thumb && $sub_sizes ) {
   120 		$thumb_img = wp_constrain_dimensions( $thumb['width'], $thumb['height'], 160, 120 );
   144 		$thumb_img = wp_constrain_dimensions( $thumb['width'], $thumb['height'], 160, 120 );
   121 	?>
   145 	?>
   122 
   146 
   123 	<div class="imgedit-group imgedit-applyto">
   147 	<div class="imgedit-group imgedit-applyto">
   124 	<div class="imgedit-group-top">
   148 	<div class="imgedit-group-top">
   125 		<h3><?php _e('Thumbnail Settings'); ?> <a href="#" class="dashicons dashicons-editor-help imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);return false;"></a></h3>
   149 		<h2><?php _e( 'Thumbnail Settings' ); ?></h2>
       
   150 		<button type="button" class="dashicons dashicons-editor-help imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);return false;" aria-expanded="false"><span class="screen-reader-text"><?php esc_html_e( 'Thumbnail Settings Help' ); ?></span></button>
   126 		<p class="imgedit-help"><?php _e('You can edit the image while preserving the thumbnail. For example, you may wish to have a square thumbnail that displays just a section of the image.'); ?></p>
   151 		<p class="imgedit-help"><?php _e('You can edit the image while preserving the thumbnail. For example, you may wish to have a square thumbnail that displays just a section of the image.'); ?></p>
   127 	</div>
   152 	</div>
   128 
   153 
   129 	<p>
   154 	<figure class="imgedit-thumbnail-preview">
   130 		<img src="<?php echo $thumb['url']; ?>" width="<?php echo $thumb_img[0]; ?>" height="<?php echo $thumb_img[1]; ?>" class="imgedit-size-preview" alt="" draggable="false" />
   155 		<img src="<?php echo $thumb['url']; ?>" width="<?php echo $thumb_img[0]; ?>" height="<?php echo $thumb_img[1]; ?>" class="imgedit-size-preview" alt="" draggable="false" />
   131 		<br /><?php _e('Current thumbnail'); ?>
   156 		<figcaption class="imgedit-thumbnail-preview-caption"><?php _e( 'Current thumbnail' ); ?></figcaption>
   132 	</p>
   157 	</figure>
   133 
   158 
   134 	<p id="imgedit-save-target-<?php echo $post_id; ?>">
   159 	<div id="imgedit-save-target-<?php echo $post_id; ?>" class="imgedit-save-target">
   135 		<strong><?php _e('Apply changes to:'); ?></strong><br />
   160 	<fieldset>
       
   161 		<legend><strong><?php _e( 'Apply changes to:' ); ?></strong></legend>
   136 
   162 
   137 		<label class="imgedit-label">
   163 		<label class="imgedit-label">
   138 		<input type="radio" name="imgedit-target-<?php echo $post_id; ?>" value="all" checked="checked" />
   164 		<input type="radio" name="imgedit-target-<?php echo $post_id; ?>" value="all" checked="checked" />
   139 		<?php _e('All image sizes'); ?></label>
   165 		<?php _e('All image sizes'); ?></label>
   140 
   166 
   143 		<?php _e('Thumbnail'); ?></label>
   169 		<?php _e('Thumbnail'); ?></label>
   144 
   170 
   145 		<label class="imgedit-label">
   171 		<label class="imgedit-label">
   146 		<input type="radio" name="imgedit-target-<?php echo $post_id; ?>" value="nothumb" />
   172 		<input type="radio" name="imgedit-target-<?php echo $post_id; ?>" value="nothumb" />
   147 		<?php _e('All sizes except thumbnail'); ?></label>
   173 		<?php _e('All sizes except thumbnail'); ?></label>
   148 	</p>
   174 	</fieldset>
       
   175 	</div>
   149 	</div>
   176 	</div>
   150 
   177 
   151 	<?php } ?>
   178 	<?php } ?>
   152 
   179 
   153 	</div>
   180 	</div>
   154 
   181 
   155 	<div class="imgedit-panel-content">
   182 	<div class="imgedit-panel-content wp-clearfix">
   156 		<?php echo $note; ?>
   183 		<?php echo $note; ?>
   157 		<div class="imgedit-menu">
   184 		<div class="imgedit-menu wp-clearfix">
   158 			<div onclick="imageEdit.crop(<?php echo "$post_id, '$nonce'"; ?>, this)" class="imgedit-crop disabled" title="<?php esc_attr_e( 'Crop' ); ?>"></div><?php
   185 			<button type="button" onclick="imageEdit.crop(<?php echo "$post_id, '$nonce'"; ?>, this)" class="imgedit-crop button disabled" disabled><span class="screen-reader-text"><?php esc_html_e( 'Crop' ); ?></span></button><?php
   159 
   186 
   160 		// On some setups GD library does not provide imagerotate() - Ticket #11536
   187 		// On some setups GD library does not provide imagerotate() - Ticket #11536
   161 		if ( wp_image_editor_supports( array( 'mime_type' => get_post_mime_type( $post_id ), 'methods' => array( 'rotate' ) ) ) ) { ?>
   188 		if ( wp_image_editor_supports( array( 'mime_type' => get_post_mime_type( $post_id ), 'methods' => array( 'rotate' ) ) ) ) {
   162 			<div class="imgedit-rleft"  onclick="imageEdit.rotate( 90, <?php echo "$post_id, '$nonce'"; ?>, this)" title="<?php esc_attr_e( 'Rotate counter-clockwise' ); ?>"></div>
   189 			$note_no_rotate = '';
   163 			<div class="imgedit-rright" onclick="imageEdit.rotate(-90, <?php echo "$post_id, '$nonce'"; ?>, this)" title="<?php esc_attr_e( 'Rotate clockwise' ); ?>"></div>
   190 	?>
       
   191 			<button type="button" class="imgedit-rleft button" onclick="imageEdit.rotate( 90, <?php echo "$post_id, '$nonce'"; ?>, this)"><span class="screen-reader-text"><?php esc_html_e( 'Rotate counter-clockwise' ); ?></span></button>
       
   192 			<button type="button" class="imgedit-rright button" onclick="imageEdit.rotate(-90, <?php echo "$post_id, '$nonce'"; ?>, this)"><span class="screen-reader-text"><?php esc_html_e( 'Rotate clockwise' ); ?></span></button>
   164 	<?php } else {
   193 	<?php } else {
   165 			$note_no_rotate = esc_attr__('Image rotation is not supported by your web host.');
   194 			$note_no_rotate = '<p class="note-no-rotate"><em>' . __( 'Image rotation is not supported by your web host.' ) . '</em></p>';
   166 	?>
   195 	?>
   167 		    <div class="imgedit-rleft disabled"  title="<?php echo $note_no_rotate; ?>"></div>
   196 			<button type="button" class="imgedit-rleft button disabled" disabled></button>
   168 		    <div class="imgedit-rright disabled" title="<?php echo $note_no_rotate; ?>"></div>
   197 			<button type="button" class="imgedit-rright button disabled" disabled></button>
   169 	<?php } ?>
   198 	<?php } ?>
   170 
   199 
   171 			<div onclick="imageEdit.flip(1, <?php echo "$post_id, '$nonce'"; ?>, this)" class="imgedit-flipv" title="<?php esc_attr_e( 'Flip vertically' ); ?>"></div>
   200 			<button type="button" onclick="imageEdit.flip(1, <?php echo "$post_id, '$nonce'"; ?>, this)" class="imgedit-flipv button"><span class="screen-reader-text"><?php esc_html_e( 'Flip vertically' ); ?></span></button>
   172 			<div onclick="imageEdit.flip(2, <?php echo "$post_id, '$nonce'"; ?>, this)" class="imgedit-fliph" title="<?php esc_attr_e( 'Flip horizontally' ); ?>"></div>
   201 			<button type="button" onclick="imageEdit.flip(2, <?php echo "$post_id, '$nonce'"; ?>, this)" class="imgedit-fliph button"><span class="screen-reader-text"><?php esc_html_e( 'Flip horizontally' ); ?></span></button>
   173 
   202 
   174 			<div id="image-undo-<?php echo $post_id; ?>" onclick="imageEdit.undo(<?php echo "$post_id, '$nonce'"; ?>, this)" class="imgedit-undo disabled" title="<?php esc_attr_e( 'Undo' ); ?>"></div>
   203 			<button type="button" id="image-undo-<?php echo $post_id; ?>" onclick="imageEdit.undo(<?php echo "$post_id, '$nonce'"; ?>, this)" class="imgedit-undo button disabled" disabled><span class="screen-reader-text"><?php esc_html_e( 'Undo' ); ?></span></button>
   175 			<div id="image-redo-<?php echo $post_id; ?>" onclick="imageEdit.redo(<?php echo "$post_id, '$nonce'"; ?>, this)" class="imgedit-redo disabled" title="<?php esc_attr_e( 'Redo' ); ?>"></div>
   204 			<button type="button" id="image-redo-<?php echo $post_id; ?>" onclick="imageEdit.redo(<?php echo "$post_id, '$nonce'"; ?>, this)" class="imgedit-redo button disabled" disabled><span class="screen-reader-text"><?php esc_html_e( 'Redo' ); ?></span></button>
   176 			<br class="clear" />
   205 			<?php echo $note_no_rotate; ?>
   177 		</div>
   206 		</div>
   178 
   207 
   179 		<input type="hidden" id="imgedit-sizer-<?php echo $post_id; ?>" value="<?php echo $sizer; ?>" />
   208 		<input type="hidden" id="imgedit-sizer-<?php echo $post_id; ?>" value="<?php echo $sizer; ?>" />
   180 		<input type="hidden" id="imgedit-history-<?php echo $post_id; ?>" value="" />
   209 		<input type="hidden" id="imgedit-history-<?php echo $post_id; ?>" value="" />
   181 		<input type="hidden" id="imgedit-undone-<?php echo $post_id; ?>" value="0" />
   210 		<input type="hidden" id="imgedit-undone-<?php echo $post_id; ?>" value="0" />
   182 		<input type="hidden" id="imgedit-selection-<?php echo $post_id; ?>" value="" />
   211 		<input type="hidden" id="imgedit-selection-<?php echo $post_id; ?>" value="" />
   183 		<input type="hidden" id="imgedit-x-<?php echo $post_id; ?>" value="<?php echo isset( $meta['width'] ) ? $meta['width'] : 0; ?>" />
   212 		<input type="hidden" id="imgedit-x-<?php echo $post_id; ?>" value="<?php echo isset( $meta['width'] ) ? $meta['width'] : 0; ?>" />
   184 		<input type="hidden" id="imgedit-y-<?php echo $post_id; ?>" value="<?php echo isset( $meta['height'] ) ? $meta['height'] : 0; ?>" />
   213 		<input type="hidden" id="imgedit-y-<?php echo $post_id; ?>" value="<?php echo isset( $meta['height'] ) ? $meta['height'] : 0; ?>" />
   185 
   214 
   186 		<div id="imgedit-crop-<?php echo $post_id; ?>" class="imgedit-crop-wrap">
   215 		<div id="imgedit-crop-<?php echo $post_id; ?>" class="imgedit-crop-wrap">
   187 		<img id="image-preview-<?php echo $post_id; ?>" onload="imageEdit.imgLoaded('<?php echo $post_id; ?>')" src="<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>?action=imgedit-preview&amp;_ajax_nonce=<?php echo $nonce; ?>&amp;postid=<?php echo $post_id; ?>&amp;rand=<?php echo rand(1, 99999); ?>" />
   216 		<img id="image-preview-<?php echo $post_id; ?>" onload="imageEdit.imgLoaded('<?php echo $post_id; ?>')" src="<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>?action=imgedit-preview&amp;_ajax_nonce=<?php echo $nonce; ?>&amp;postid=<?php echo $post_id; ?>&amp;rand=<?php echo rand(1, 99999); ?>" alt="" />
   188 		</div>
   217 		</div>
   189 
   218 
   190 		<div class="imgedit-submit">
   219 		<div class="imgedit-submit">
   191 			<input type="button" onclick="imageEdit.close(<?php echo $post_id; ?>, 1)" class="button" value="<?php esc_attr_e( 'Cancel' ); ?>" />
   220 			<input type="button" onclick="imageEdit.close(<?php echo $post_id; ?>, 1)" class="button imgedit-cancel-btn" value="<?php esc_attr_e( 'Cancel' ); ?>" />
   192 			<input type="button" onclick="imageEdit.save(<?php echo "$post_id, '$nonce'"; ?>)" disabled="disabled" class="button button-primary imgedit-submit-btn" value="<?php esc_attr_e( 'Save' ); ?>" />
   221 			<input type="button" onclick="imageEdit.save(<?php echo "$post_id, '$nonce'"; ?>)" disabled="disabled" class="button button-primary imgedit-submit-btn" value="<?php esc_attr_e( 'Save' ); ?>" />
   193 		</div>
   222 		</div>
   194 	</div>
   223 	</div>
   195 
   224 
   196 	</div>
   225 	</div>
   197 	<div class="imgedit-wait" id="imgedit-wait-<?php echo $post_id; ?>"></div>
   226 	<div class="imgedit-wait" id="imgedit-wait-<?php echo $post_id; ?>"></div>
   198 	<script type="text/javascript">jQuery( function() { imageEdit.init(<?php echo $post_id; ?>); });</script>
       
   199 	<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>
   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>
   200 	</div>
   228 	</div>
   201 <?php
   229 <?php
   202 }
   230 }
   203 
   231 
   204 /**
   232 /**
   205  * Streams image in WP_Image_Editor to browser.
   233  * Streams image in WP_Image_Editor to browser.
   206  * Provided for backcompat reasons
   234  *
   207  *
   235  * @param WP_Image_Editor $image         The image editor instance.
   208  * @param WP_Image_Editor $image
   236  * @param string          $mime_type     The mime type of the image.
   209  * @param string $mime_type
   237  * @param int             $attachment_id The image's attachment post ID.
   210  * @param int $post_id
   238  * @return bool True on success, false on failure.
   211  * @return boolean
   239  */
   212  */
   240 function wp_stream_image( $image, $mime_type, $attachment_id ) {
   213 function wp_stream_image( $image, $mime_type, $post_id ) {
       
   214 	if ( $image instanceof WP_Image_Editor ) {
   241 	if ( $image instanceof WP_Image_Editor ) {
   215 
   242 
   216 		/**
   243 		/**
   217 		 * Filter the WP_Image_Editor instance for the image to be streamed to the browser.
   244 		 * Filters the WP_Image_Editor instance for the image to be streamed to the browser.
   218 		 *
   245 		 *
   219 		 * @since 3.5.0
   246 		 * @since 3.5.0
   220 		 *
   247 		 *
   221 		 * @param WP_Image_Editor $image   WP_Image_Editor instance.
   248 		 * @param WP_Image_Editor $image         The image editor instance.
   222 		 * @param int             $post_id Post ID.
   249 		 * @param int             $attachment_id The attachment post ID.
   223 		 */
   250 		 */
   224 		$image = apply_filters( 'image_editor_save_pre', $image, $post_id );
   251 		$image = apply_filters( 'image_editor_save_pre', $image, $attachment_id );
   225 
   252 
   226 		if ( is_wp_error( $image->stream( $mime_type ) ) )
   253 		if ( is_wp_error( $image->stream( $mime_type ) ) )
   227 			return false;
   254 			return false;
   228 
   255 
   229 		return true;
   256 		return true;
   230 	} else {
   257 	} else {
   231 		_deprecated_argument( __FUNCTION__, '3.5', __( '$image needs to be an WP_Image_Editor object' ) );
   258 		_deprecated_argument( __FUNCTION__, '3.5.0', __( '$image needs to be an WP_Image_Editor object' ) );
   232 
   259 
   233 		/**
   260 		/**
   234 		 * Filter the GD image resource to be streamed to the browser.
   261 		 * Filters the GD image resource to be streamed to the browser.
   235 		 *
   262 		 *
   236 		 * @since 2.9.0
   263 		 * @since 2.9.0
   237 		 * @deprecated 3.5.0 Use image_editor_save_pre instead.
   264 		 * @deprecated 3.5.0 Use image_editor_save_pre instead.
   238 		 *
   265 		 *
   239 		 * @param resource $image   Image resource to be streamed.
   266 		 * @param resource $image         Image resource to be streamed.
   240 		 * @param int      $post_id Post ID.
   267 		 * @param int      $attachment_id The attachment post ID.
   241 		 */
   268 		 */
   242 		$image = apply_filters( 'image_save_pre', $image, $post_id );
   269 		$image = apply_filters( 'image_save_pre', $image, $attachment_id );
   243 
   270 
   244 		switch ( $mime_type ) {
   271 		switch ( $mime_type ) {
   245 			case 'image/jpeg':
   272 			case 'image/jpeg':
   246 				header( 'Content-Type: image/jpeg' );
   273 				header( 'Content-Type: image/jpeg' );
   247 				return imagejpeg( $image, null, 90 );
   274 				return imagejpeg( $image, null, 90 );
   262  *
   289  *
   263  * @param string $filename
   290  * @param string $filename
   264  * @param WP_Image_Editor $image
   291  * @param WP_Image_Editor $image
   265  * @param string $mime_type
   292  * @param string $mime_type
   266  * @param int $post_id
   293  * @param int $post_id
   267  * @return boolean
   294  * @return bool
   268  */
   295  */
   269 function wp_save_image_file( $filename, $image, $mime_type, $post_id ) {
   296 function wp_save_image_file( $filename, $image, $mime_type, $post_id ) {
   270 	if ( $image instanceof WP_Image_Editor ) {
   297 	if ( $image instanceof WP_Image_Editor ) {
   271 
   298 
   272 		/** This filter is documented in wp-admin/includes/image-edit.php */
   299 		/** This filter is documented in wp-admin/includes/image-edit.php */
   273 		$image = apply_filters( 'image_editor_save_pre', $image, $post_id );
   300 		$image = apply_filters( 'image_editor_save_pre', $image, $post_id );
   274 
   301 
   275 		/**
   302 		/**
   276 		 * Filter whether to skip saving the image file.
   303 		 * Filters whether to skip saving the image file.
   277 		 *
   304 		 *
   278 		 * Returning a non-null value will short-circuit the save method,
   305 		 * Returning a non-null value will short-circuit the save method,
   279 		 * returning that value instead.
   306 		 * returning that value instead.
   280 		 *
   307 		 *
   281 		 * @since 3.5.0
   308 		 * @since 3.5.0
   291 		if ( null !== $saved )
   318 		if ( null !== $saved )
   292 			return $saved;
   319 			return $saved;
   293 
   320 
   294 		return $image->save( $filename, $mime_type );
   321 		return $image->save( $filename, $mime_type );
   295 	} else {
   322 	} else {
   296 		_deprecated_argument( __FUNCTION__, '3.5', __( '$image needs to be an WP_Image_Editor object' ) );
   323 		_deprecated_argument( __FUNCTION__, '3.5.0', __( '$image needs to be an WP_Image_Editor object' ) );
   297 
   324 
   298 		/** This filter is documented in wp-admin/includes/image-edit.php */
   325 		/** This filter is documented in wp-admin/includes/image-edit.php */
   299 		$image = apply_filters( 'image_save_pre', $image, $post_id );
   326 		$image = apply_filters( 'image_save_pre', $image, $post_id );
   300 
   327 
   301 		/**
   328 		/**
   302 		 * Filter whether to skip saving the image file.
   329 		 * Filters whether to skip saving the image file.
   303 		 *
   330 		 *
   304 		 * Returning a non-null value will short-circuit the save method,
   331 		 * Returning a non-null value will short-circuit the save method,
   305 		 * returning that value instead.
   332 		 * returning that value instead.
   306 		 *
   333 		 *
   307 		 * @since 2.9.0
   334 		 * @since 2.9.0
   350 
   377 
   351 /**
   378 /**
   352  * Returns an image resource. Internal use only.
   379  * Returns an image resource. Internal use only.
   353  *
   380  *
   354  * @since 2.9.0
   381  * @since 2.9.0
       
   382  * @deprecated 3.5.0 Use WP_Image_Editor::rotate()
       
   383  * @see WP_Image_Editor::rotate()
   355  *
   384  *
   356  * @ignore
   385  * @ignore
   357  * @param resource  $img   Image resource.
   386  * @param resource  $img   Image resource.
   358  * @param float|int $angle Image rotation angle, in degrees.
   387  * @param float|int $angle Image rotation angle, in degrees.
   359  * @return resource|false GD image resource, false otherwise.
   388  * @return resource|false GD image resource, false otherwise.
   360  */
   389  */
   361 function _rotate_image_resource($img, $angle) {
   390 function _rotate_image_resource($img, $angle) {
   362 	_deprecated_function( __FUNCTION__, '3.5', __( 'Use WP_Image_Editor::rotate' ) );
   391 	_deprecated_function( __FUNCTION__, '3.5.0', 'WP_Image_Editor::rotate()' );
   363 	if ( function_exists('imagerotate') ) {
   392 	if ( function_exists('imagerotate') ) {
   364 		$rotated = imagerotate($img, $angle, 0);
   393 		$rotated = imagerotate($img, $angle, 0);
   365 		if ( is_resource($rotated) ) {
   394 		if ( is_resource($rotated) ) {
   366 			imagedestroy($img);
   395 			imagedestroy($img);
   367 			$img = $rotated;
   396 			$img = $rotated;
   372 
   401 
   373 /**
   402 /**
   374  * Flips an image resource. Internal use only.
   403  * Flips an image resource. Internal use only.
   375  *
   404  *
   376  * @since 2.9.0
   405  * @since 2.9.0
       
   406  * @deprecated 3.5.0 Use WP_Image_Editor::flip()
       
   407  * @see WP_Image_Editor::flip()
   377  *
   408  *
   378  * @ignore
   409  * @ignore
   379  * @param resource $img  Image resource.
   410  * @param resource $img  Image resource.
   380  * @param bool     $horz Whether to flip horizontally.
   411  * @param bool     $horz Whether to flip horizontally.
   381  * @param bool     $vert Whether to flip vertically.
   412  * @param bool     $vert Whether to flip vertically.
   382  * @return resource (maybe) flipped image resource.
   413  * @return resource (maybe) flipped image resource.
   383  */
   414  */
   384 function _flip_image_resource($img, $horz, $vert) {
   415 function _flip_image_resource($img, $horz, $vert) {
   385 	_deprecated_function( __FUNCTION__, '3.5', __( 'Use WP_Image_Editor::flip' ) );
   416 	_deprecated_function( __FUNCTION__, '3.5.0', 'WP_Image_Editor::flip()' );
   386 	$w = imagesx($img);
   417 	$w = imagesx($img);
   387 	$h = imagesy($img);
   418 	$h = imagesy($img);
   388 	$dst = wp_imagecreatetruecolor($w, $h);
   419 	$dst = wp_imagecreatetruecolor($w, $h);
   389 	if ( is_resource($dst) ) {
   420 	if ( is_resource($dst) ) {
   390 		$sx = $vert ? ($w - 1) : 0;
   421 		$sx = $vert ? ($w - 1) : 0;
   427 /**
   458 /**
   428  * Performs group of changes on Editor specified.
   459  * Performs group of changes on Editor specified.
   429  *
   460  *
   430  * @since 2.9.0
   461  * @since 2.9.0
   431  *
   462  *
   432  * @param WP_Image_Editor $image   {@see WP_Image_Editor} instance.
   463  * @param WP_Image_Editor $image   WP_Image_Editor instance.
   433  * @param array           $changes Array of change operations.
   464  * @param array           $changes Array of change operations.
   434  * @return WP_Image_Editor {@see WP_Image_Editor} instance with changes applied.
   465  * @return WP_Image_Editor WP_Image_Editor instance with changes applied.
   435  */
   466  */
   436 function image_edit_apply_changes( $image, $changes ) {
   467 function image_edit_apply_changes( $image, $changes ) {
   437 	if ( is_resource( $image ) )
   468 	if ( is_resource( $image ) )
   438 		_deprecated_argument( __FUNCTION__, '3.5', __( '$image needs to be an WP_Image_Editor object' ) );
   469 		_deprecated_argument( __FUNCTION__, '3.5.0', __( '$image needs to be an WP_Image_Editor object' ) );
   439 
   470 
   440 	if ( !is_array($changes) )
   471 	if ( !is_array($changes) )
   441 		return $image;
   472 		return $image;
   442 
   473 
   443 	// Expand change operations.
   474 	// Expand change operations.
   484 
   515 
   485 	// Image resource before applying the changes.
   516 	// Image resource before applying the changes.
   486 	if ( $image instanceof WP_Image_Editor ) {
   517 	if ( $image instanceof WP_Image_Editor ) {
   487 
   518 
   488 		/**
   519 		/**
   489 		 * Filter the WP_Image_Editor instance before applying changes to the image.
   520 		 * Filters the WP_Image_Editor instance before applying changes to the image.
   490 		 *
   521 		 *
   491 		 * @since 3.5.0
   522 		 * @since 3.5.0
   492 		 *
   523 		 *
   493 		 * @param WP_Image_Editor $image   WP_Image_Editor instance.
   524 		 * @param WP_Image_Editor $image   WP_Image_Editor instance.
   494  		 * @param array           $changes Array of change operations.
   525  		 * @param array           $changes Array of change operations.
   495 		 */
   526 		 */
   496 		$image = apply_filters( 'wp_image_editor_before_change', $image, $changes );
   527 		$image = apply_filters( 'wp_image_editor_before_change', $image, $changes );
   497 	} elseif ( is_resource( $image ) ) {
   528 	} elseif ( is_resource( $image ) ) {
   498 
   529 
   499 		/**
   530 		/**
   500 		 * Filter the GD image resource before applying changes to the image.
   531 		 * Filters the GD image resource before applying changes to the image.
   501 		 *
   532 		 *
   502 		 * @since 2.9.0
   533 		 * @since 2.9.0
   503 		 * @deprecated 3.5.0 Use wp_image_editor_before_change instead.
   534 		 * @deprecated 3.5.0 Use wp_image_editor_before_change instead.
   504 		 *
   535 		 *
   505 		 * @param resource $image   GD image resource.
   536 		 * @param resource $image   GD image resource.
   550 /**
   581 /**
   551  * Streams image in post to browser, along with enqueued changes
   582  * Streams image in post to browser, along with enqueued changes
   552  * in $_REQUEST['history']
   583  * in $_REQUEST['history']
   553  *
   584  *
   554  * @param int $post_id
   585  * @param int $post_id
   555  * @return boolean
   586  * @return bool
   556  */
   587  */
   557 function stream_preview_image( $post_id ) {
   588 function stream_preview_image( $post_id ) {
   558 	$post = get_post( $post_id );
   589 	$post = get_post( $post_id );
   559 
   590 
   560 	/** This filter is documented in wp-admin/admin.php */
   591 	wp_raise_memory_limit( 'admin' );
   561 	@ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) );
       
   562 
   592 
   563 	$img = wp_get_image_editor( _load_image_to_edit_path( $post_id ) );
   593 	$img = wp_get_image_editor( _load_image_to_edit_path( $post_id ) );
   564 
   594 
   565     if ( is_wp_error( $img ) )
   595 	if ( is_wp_error( $img ) ) {
   566         return false;
   596 		return false;
       
   597 	}
   567 
   598 
   568 	$changes = !empty($_REQUEST['history']) ? json_decode( wp_unslash($_REQUEST['history']) ) : null;
   599 	$changes = !empty($_REQUEST['history']) ? json_decode( wp_unslash($_REQUEST['history']) ) : null;
   569 	if ( $changes )
   600 	if ( $changes )
   570 		$img = image_edit_apply_changes( $img, $changes );
   601 		$img = image_edit_apply_changes( $img, $changes );
   571 
   602 
   612 		$data = $backup_sizes['full-orig'];
   643 		$data = $backup_sizes['full-orig'];
   613 
   644 
   614 		if ( $parts['basename'] != $data['file'] ) {
   645 		if ( $parts['basename'] != $data['file'] ) {
   615 			if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE ) {
   646 			if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE ) {
   616 
   647 
   617 				// Delete only if it's edited image.
   648 				// Delete only if it's an edited image.
   618 				if ( preg_match('/-e[0-9]{13}\./', $parts['basename']) ) {
   649 				if ( preg_match('/-e[0-9]{13}\./', $parts['basename']) ) {
   619 					wp_delete_file( $file );
   650 					wp_delete_file( $file );
   620 				}
   651 				}
   621 			} elseif ( isset( $meta['width'], $meta['height'] ) ) {
   652 			} elseif ( isset( $meta['width'], $meta['height'] ) ) {
   622 				$backup_sizes["full-$suffix"] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $parts['basename']);
   653 				$backup_sizes["full-$suffix"] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $parts['basename']);
   635 		if ( isset($backup_sizes["$default_size-orig"]) ) {
   666 		if ( isset($backup_sizes["$default_size-orig"]) ) {
   636 			$data = $backup_sizes["$default_size-orig"];
   667 			$data = $backup_sizes["$default_size-orig"];
   637 			if ( isset($meta['sizes'][$default_size]) && $meta['sizes'][$default_size]['file'] != $data['file'] ) {
   668 			if ( isset($meta['sizes'][$default_size]) && $meta['sizes'][$default_size]['file'] != $data['file'] ) {
   638 				if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE ) {
   669 				if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE ) {
   639 
   670 
   640 					// Delete only if it's edited image
   671 					// Delete only if it's an edited image.
   641 					if ( preg_match('/-e[0-9]{13}-/', $meta['sizes'][$default_size]['file']) ) {
   672 					if ( preg_match('/-e[0-9]{13}-/', $meta['sizes'][$default_size]['file']) ) {
   642 						$delete_file = path_join( $parts['dirname'], $meta['sizes'][$default_size]['file'] );
   673 						$delete_file = path_join( $parts['dirname'], $meta['sizes'][$default_size]['file'] );
   643 						wp_delete_file( $delete_file );
   674 						wp_delete_file( $delete_file );
   644 					}
   675 					}
   645 				} else {
   676 				} else {
   674  *
   705  *
   675  * @param int $post_id
   706  * @param int $post_id
   676  * @return \stdClass
   707  * @return \stdClass
   677  */
   708  */
   678 function wp_save_image( $post_id ) {
   709 function wp_save_image( $post_id ) {
   679 	global $_wp_additional_image_sizes;
   710 	$_wp_additional_image_sizes = wp_get_additional_image_sizes();
   680 
   711 
   681 	$return = new stdClass;
   712 	$return = new stdClass;
   682 	$success = $delete = $scaled = $nocrop = false;
   713 	$success = $delete = $scaled = $nocrop = false;
   683 	$post = get_post( $post_id );
   714 	$post = get_post( $post_id );
   684 
   715 
   729 
   760 
   730 	if ( !is_array($backup_sizes) )
   761 	if ( !is_array($backup_sizes) )
   731 		$backup_sizes = array();
   762 		$backup_sizes = array();
   732 
   763 
   733 	// Generate new filename.
   764 	// Generate new filename.
   734 	$path = get_attached_file($post_id);
   765 	$path = get_attached_file( $post_id );
   735 	$path_parts = pathinfo( $path );
   766 
   736 	$filename = $path_parts['filename'];
   767 	$basename = pathinfo( $path, PATHINFO_BASENAME );
       
   768 	$dirname = pathinfo( $path, PATHINFO_DIRNAME );
       
   769 	$ext = pathinfo( $path, PATHINFO_EXTENSION );
       
   770 	$filename = pathinfo( $path, PATHINFO_FILENAME );
   737 	$suffix = time() . rand(100, 999);
   771 	$suffix = time() . rand(100, 999);
   738 
   772 
   739 	if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE &&
   773 	if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE &&
   740 		isset($backup_sizes['full-orig']) && $backup_sizes['full-orig']['file'] != $path_parts['basename'] ) {
   774 		isset($backup_sizes['full-orig']) && $backup_sizes['full-orig']['file'] != $basename ) {
   741 
   775 
   742 		if ( 'thumbnail' == $target )
   776 		if ( 'thumbnail' == $target ) {
   743 			$new_path = "{$path_parts['dirname']}/{$filename}-temp.{$path_parts['extension']}";
   777 			$new_path = "{$dirname}/{$filename}-temp.{$ext}";
   744 		else
   778 		} else {
   745 			$new_path = $path;
   779 			$new_path = $path;
       
   780 		}
   746 	} else {
   781 	} else {
   747 		while( true ) {
   782 		while ( true ) {
   748 			$filename = preg_replace( '/-e([0-9]+)$/', '', $filename );
   783 			$filename = preg_replace( '/-e([0-9]+)$/', '', $filename );
   749 			$filename .= "-e{$suffix}";
   784 			$filename .= "-e{$suffix}";
   750 			$new_filename = "{$filename}.{$path_parts['extension']}";
   785 			$new_filename = "{$filename}.{$ext}";
   751 			$new_path = "{$path_parts['dirname']}/$new_filename";
   786 			$new_path = "{$dirname}/$new_filename";
   752 			if ( file_exists($new_path) )
   787 			if ( file_exists($new_path) ) {
   753 				$suffix++;
   788 				$suffix++;
   754 			else
   789 			} else {
   755 				break;
   790 				break;
       
   791 			}
   756 		}
   792 		}
   757 	}
   793 	}
   758 
   794 
   759 	// Save the full-size file, also needed to create sub-sizes.
   795 	// Save the full-size file, also needed to create sub-sizes.
   760 	if ( !wp_save_image_file($new_path, $img, $post->post_mime_type, $post_id) ) {
   796 	if ( !wp_save_image_file($new_path, $img, $post->post_mime_type, $post_id) ) {
   761 		$return->error = esc_js( __('Unable to save the image.') );
   797 		$return->error = esc_js( __('Unable to save the image.') );
   762 		return $return;
   798 		return $return;
   763 	}
   799 	}
   764 
   800 
   765 	if ( 'nothumb' == $target || 'all' == $target || 'full' == $target || $scaled ) {
   801 	if ( 'nothumb' === $target || 'all' === $target || 'full' === $target || $scaled ) {
   766 		$tag = false;
   802 		$tag = false;
   767 		if ( isset($backup_sizes['full-orig']) ) {
   803 		if ( isset( $backup_sizes['full-orig'] ) ) {
   768 			if ( ( !defined('IMAGE_EDIT_OVERWRITE') || !IMAGE_EDIT_OVERWRITE ) && $backup_sizes['full-orig']['file'] != $path_parts['basename'] )
   804 			if ( ( ! defined( 'IMAGE_EDIT_OVERWRITE' ) || ! IMAGE_EDIT_OVERWRITE ) && $backup_sizes['full-orig']['file'] !== $basename ) {
   769 				$tag = "full-$suffix";
   805 				$tag = "full-$suffix";
       
   806 			}
   770 		} else {
   807 		} else {
   771 			$tag = 'full-orig';
   808 			$tag = 'full-orig';
   772 		}
   809 		}
   773 
   810 
   774 		if ( $tag )
   811 		if ( $tag ) {
   775 			$backup_sizes[$tag] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $path_parts['basename']);
   812 			$backup_sizes[$tag] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $basename );
   776 
   813 		}
   777 		$success = ( $path === $new_path ) || update_attached_file( $post_id, $new_path );
   814 		$success = ( $path === $new_path ) || update_attached_file( $post_id, $new_path );
   778 
   815 
   779 		$meta['file'] = _wp_relative_upload_path( $new_path );
   816 		$meta['file'] = _wp_relative_upload_path( $new_path );
   780 
   817 
   781 		$size = $img->get_size();
   818 		$size = $img->get_size();
   791 		$return->fw = $meta['width'];
   828 		$return->fw = $meta['width'];
   792 		$return->fh = $meta['height'];
   829 		$return->fh = $meta['height'];
   793 	} elseif ( 'thumbnail' == $target ) {
   830 	} elseif ( 'thumbnail' == $target ) {
   794 		$sizes = array( 'thumbnail' );
   831 		$sizes = array( 'thumbnail' );
   795 		$success = $delete = $nocrop = true;
   832 		$success = $delete = $nocrop = true;
       
   833 	}
       
   834 
       
   835 	/*
       
   836 	 * We need to remove any existing resized image files because
       
   837 	 * a new crop or rotate could generate different sizes (and hence, filenames),
       
   838 	 * keeping the new resized images from overwriting the existing image files.
       
   839 	 * https://core.trac.wordpress.org/ticket/32171
       
   840 	 */
       
   841 	if ( defined( 'IMAGE_EDIT_OVERWRITE' ) && IMAGE_EDIT_OVERWRITE && ! empty( $meta['sizes'] ) ) {
       
   842 		foreach ( $meta['sizes'] as $size ) {
       
   843 			if ( ! empty( $size['file'] ) && preg_match( '/-e[0-9]{13}-/', $size['file'] ) ) {
       
   844 				$delete_file = path_join( $dirname, $size['file'] );
       
   845 				wp_delete_file( $delete_file );
       
   846 			}
       
   847 		}
   796 	}
   848 	}
   797 
   849 
   798 	if ( isset( $sizes ) ) {
   850 	if ( isset( $sizes ) ) {
   799 		$_sizes = array();
   851 		$_sizes = array();
   800 
   852