Changeset 22094 for trunk/wp-admin/includes/image.php
- Timestamp:
- 10/01/2012 08:59:06 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/image.php
r21956 r22094 23 23 * @return string|WP_Error|false New filepath on success, WP_Error or false on failure. 24 24 */ 25 function wp_crop_image( $src , $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false ) {26 if ( is_numeric( $src ) ) { // Handle int as attachment ID27 $src_file = get_attached_file( $src );25 function wp_crop_image( $src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false ) { 26 if ( is_numeric( $src_file ) ) { // Handle int as attachment ID 27 $src_file = get_attached_file( $src_file ); 28 28 if ( ! file_exists( $src_file ) ) { 29 29 // If the file doesn't exist, attempt a url fopen on the src link. 30 30 // This can occur with certain file replication plugins. 31 $post = get_post( $src ); 32 $image_type = $post->post_mime_type; 33 $src = load_image_to_edit( $src, $post->post_mime_type, 'full' ); 34 } else { 35 $size = @getimagesize( $src_file ); 36 $image_type = ( $size ) ? $size['mime'] : ''; 37 $src = wp_load_image( $src_file ); 38 } 39 } else { 40 $size = @getimagesize( $src ); 41 $image_type = ( $size ) ? $size['mime'] : ''; 42 $src = wp_load_image( $src ); 43 } 44 45 if ( ! is_resource( $src ) ) 46 return new WP_Error( 'error_loading_image', $src, $src_file ); 47 48 $dst = wp_imagecreatetruecolor( $dst_w, $dst_h ); 49 50 if ( $src_abs ) { 51 $src_w -= $src_x; 52 $src_h -= $src_y; 53 } 54 55 if ( function_exists( 'imageantialias' ) ) 56 imageantialias( $dst, true ); 57 58 imagecopyresampled( $dst, $src, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ); 59 60 imagedestroy( $src ); // Free up memory 31 $src_file = _load_image_to_edit_path( $src_file, 'full' ); 32 } 33 } 34 35 $editor = WP_Image_Editor::get_instance( $src_file ); 36 $src = $editor->crop( $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs ); 37 38 if ( is_wp_error( $src ) ) 39 return $src; 61 40 62 41 if ( ! $dst_file ) 63 42 $dst_file = str_replace( basename( $src_file ), 'cropped-' . basename( $src_file ), $src_file ); 64 65 if ( 'image/png' != $image_type )66 $dst_file = preg_replace( '/\\.[^\\.]+$/', '.jpg', $dst_file );67 43 68 44 // The directory containing the original file may no longer exist when … … 72 48 $dst_file = dirname( $dst_file ) . '/' . wp_unique_filename( dirname( $dst_file ), basename( $dst_file ) ); 73 49 74 if ( 'image/png' == $image_type && imagepng( $dst, $dst_file ) ) 75 return $dst_file; 76 elseif ( imagejpeg( $dst, $dst_file, apply_filters( 'jpeg_quality', 90, 'wp_crop_image' ) ) ) 77 return $dst_file; 78 else 79 return false; 50 $result = $editor->save( $dst_file ); 51 return $dst_file; 80 52 } 81 53 … … 122 94 $sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes ); 123 95 124 foreach ($sizes as $size => $size_data ) { 125 $resized = image_make_intermediate_size( $file, $size_data['width'], $size_data['height'], $size_data['crop'] ); 126 if ( $resized ) 127 $metadata['sizes'][$size] = $resized; 128 } 96 $editor = WP_Image_Editor::get_instance( $file ); 97 $metadata['sizes'] = $editor->multi_resize( $sizes ); 129 98 130 99 // fetch additional metadata from exif/iptc
Note: See TracChangeset
for help on using the changeset viewer.