Make WordPress Core

Ticket #20657: 20657.4.patch

File 20657.4.patch, 2.6 KB (added by SergeyBiryukov, 13 years ago)
  • wp-admin/includes/image.php

     
    4444 * @return string|WP_Error|false New filepath on success, WP_Error or false on failure.
    4545 */
    4646function wp_crop_image( $src, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false ) {
    47         if ( 0 == $src_x && 0 == $src_y && $src_w == $dst_w && $src_h == $dst_h )
    48                 return ( is_numeric( $src ) ) ? get_attached_file( $src ) : $src;
     47        if ( 0 == $src_x && 0 == $src_y && $src_w == $dst_w && $src_h == $dst_h ) {
     48                // No cropping, just copy the file
     49                if ( is_numeric( $src ) ) {
     50                        $src_file = get_attached_file( $src );
     51                        if ( ! file_exists( $src_file ) )
     52                                $src_file = _load_image_file( $src );
     53                } else {
     54                        $src_file = $src;
     55                }
    4956
     57                $dst_file = str_replace( basename( $src_file ), 'cropped-' . basename( $src_file ), $src_file );
     58                if ( $src_file && copy( $src_file, $dst_file ) )
     59                        return $dst_file;
     60                else
     61                        return false;
     62        }
     63
    5064        if ( is_numeric( $src ) ) { // Handle int as attachment ID
    5165                $src_file = get_attached_file( $src );
    5266                if ( ! file_exists( $src_file ) ) {
     
    364378        return apply_filters('file_is_displayable_image', $result, $path);
    365379}
    366380
    367 function load_image_to_edit($post_id, $mime_type, $size = 'full') {
     381/**
     382 * Attempt to load an attachment from URL (for replication plugins).
     383 *
     384 * @since 3.4.0
     385 * @access private
     386 *
     387 * @param string $post_id Attachment post ID.
     388 * @param string $size Optional. Image size, defaults to 'full'.
     389 * @return string|false Local file path on success, false on failure.
     390 */
     391function _load_image_file( $post_id, $size = 'full' ) {
    368392        $filepath = get_attached_file($post_id);
    369393
    370394        if ( $filepath && file_exists($filepath) ) {
     
    376400        }
    377401
    378402        $filepath = apply_filters('load_image_to_edit_path', $filepath, $post_id, $size);
    379         if ( empty($filepath) )
     403        if ( empty( $filepath ) )
    380404                return false;
     405}
    381406
     407/**
     408 * Load an image resource for editing.
     409 *
     410 * @since 2.9.0
     411 *
     412 * @param string $post_id Attachment post ID.
     413 * @param string $mime_type Image mime type.
     414 * @param string $size Optional. Image size, defaults to 'full'.
     415 * @return resource|false The resulting image resource on success, false on failure.
     416 */
     417function load_image_to_edit( $post_id, $mime_type, $size = 'full' ) {
     418        $filepath = _load_image_file( $post_id, $size );
     419        if ( empty( $filepath ) )
     420                return false;
     421
    382422        switch ( $mime_type ) {
    383423                case 'image/jpeg':
    384424                        $image = imagecreatefromjpeg($filepath);