Ticket #44867: fullpatch-v6-44867-image-editor-save-modified-image-as-a-new-copy.patch
File fullpatch-v6-44867-image-editor-save-modified-image-as-a-new-copy.patch, 2.9 KB (added by , 2 years ago) |
---|
-
wp-admin/includes/image-edit.php
diff --git a/wp-admin/includes/image-edit.php b/wp-admin/includes/image-edit.php index 4cb0dc23d7..2eaf336673 100644
a b function wp_image_editor( $post_id, $msg = false ) { 243 243 <label for="imgedit-target-thumbnail"><?php _e( 'Thumbnail' ); ?></label> 244 244 </span> 245 245 246 247 <label class="imgedit-label"> 248 <input type="radio" name="imgedit-target-<?php echo $post_id; ?>" value="new" /> 249 <?php _e('A newly created image'); ?></label> 246 250 <span class="imgedit-label"> 247 251 <input type="radio" id="imgedit-target-nothumb" name="imgedit-target-<?php echo $post_id; ?>" value="nothumb" /> 248 252 <label for="imgedit-target-nothumb"><?php _e( 'All sizes except thumbnail' ); ?></label> … … function wp_save_image( $post_id ) { 902 906 } 903 907 } 904 908 909 if ( 'new' == $target ) { 910 $original_post_id = $post_id; 911 $post_id = NULL; 912 } 913 905 914 // Save the full-size file, also needed to create sub-sizes. 906 915 if ( ! wp_save_image_file( $new_path, $img, $post->post_mime_type, $post_id ) ) { 907 916 $return->error = esc_js( __( 'Unable to save the image.' ) ); … … function wp_save_image( $post_id ) { 947 956 $return->fw = $meta['width']; 948 957 $return->fh = $meta['height']; 949 958 } elseif ( 'thumbnail' === $target ) { 959 } elseif ( 'new' == $target ) { 960 $size = $img->get_size(); 961 $meta['width'] = $size['width']; // cropped and saved as a copy 962 $meta['height'] = $size['height']; 963 964 $new_post = (array)$post; 965 unset( $new_post['ID'], $new_post['post_date'], $new_post['post_date_gmt'], $new_post['post_modified'], $new_post['post_modified_gmt'] ); 966 $new_post['post_title'] = preg_match('/\.[a-z]{3}$/', $new_post['post_title']) ? preg_replace('/(\.[a-z]{3})/', '-media-copy\1', $new_post['post_title']) : $new_post['post_title'] . '-mediacopy'; 967 968 $wp_upload_dir = wp_upload_dir(); 969 $new_post['guid'] = $wp_upload_dir['url'] . '/' . basename( $new_path ); 970 $post_id = wp_insert_attachment( $new_post, $new_path, 0, TRUE ); 971 if ( is_wp_error( $post_id ) ) { 972 $return->error = esc_js( __('Unable to create a new atachment.') ); 973 return $return; 974 } 975 $return->refresh = TRUE; 976 $return->debug = sprintf( __( 'New attachment created: %d.'), $post_id ); 977 $success = true; 978 979 update_attached_file( $post_id, $new_path ); 980 update_post_meta( $post_id, '_wp_attachment_derive_from', $original_post_id ); 981 982 $sizes = get_intermediate_image_sizes(); 983 $delete = $nocrop = false; 950 984 $sizes = array( 'thumbnail' ); 951 985 $success = true; 952 986 $delete = true; -
wp-admin/js/image-edit.js
diff --git a/wp-admin/js/image-edit.js b/wp-admin/js/image-edit.js index 18d3099f62..4fc90544e3 100644
a b function( response ) { 561 561 } 562 562 563 563 if ( self._view ) { 564 if ( ret.refresh ) { /* ToDo: refresh media view when going back. */ } 564 565 self._view.save(); 565 566 } else { 566 567 imageEdit.close(postid);