Changes in trunk/wp-admin/includes/image.php [18632:21039]
- File:
-
- 1 edited
-
trunk/wp-admin/includes/image.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/image.php
r18632 r21039 33 33 * @since 2.1.0 34 34 * 35 * @param string|int $src _fileThe source file or Attachment ID.35 * @param string|int $src The source file or Attachment ID. 36 36 * @param int $src_x The start x position to crop from. 37 37 * @param int $src_y The start y position to crop from. … … 44 44 * @return string|WP_Error|false New filepath on success, WP_Error or false on failure. 45 45 */ 46 function wp_crop_image( $src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false ) { 47 if ( is_numeric( $src_file ) ) // Handle int as attachment ID 48 $src_file = get_attached_file( $src_file ); 49 50 $src = wp_load_image( $src_file ); 51 52 if ( !is_resource( $src ) ) 46 function wp_crop_image( $src, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false ) { 47 if ( is_numeric( $src ) ) { // Handle int as attachment ID 48 $src_file = get_attached_file( $src ); 49 if ( ! file_exists( $src_file ) ) { 50 // If the file doesn't exist, attempt a url fopen on the src link. 51 // This can occur with certain file replication plugins. 52 $post = get_post( $src ); 53 $image_type = $post->post_mime_type; 54 $src = load_image_to_edit( $src, $post->post_mime_type, 'full' ); 55 } else { 56 $size = @getimagesize( $src_file ); 57 $image_type = ( $size ) ? $size['mime'] : ''; 58 $src = wp_load_image( $src_file ); 59 } 60 } else { 61 $size = @getimagesize( $src ); 62 $image_type = ( $size ) ? $size['mime'] : ''; 63 $src = wp_load_image( $src ); 64 } 65 66 if ( ! is_resource( $src ) ) 53 67 return new WP_Error( 'error_loading_image', $src, $src_file ); 54 68 … … 60 74 } 61 75 62 if ( function_exists('imageantialias'))76 if ( function_exists( 'imageantialias' ) ) 63 77 imageantialias( $dst, true ); 64 78 … … 70 84 $dst_file = str_replace( basename( $src_file ), 'cropped-' . basename( $src_file ), $src_file ); 71 85 72 $dst_file = preg_replace( '/\\.[^\\.]+$/', '.jpg', $dst_file ); 73 74 if ( imagejpeg( $dst, $dst_file, apply_filters( 'jpeg_quality', 90, 'wp_crop_image' ) ) ) 86 if ( 'image/png' != $image_type ) 87 $dst_file = preg_replace( '/\\.[^\\.]+$/', '.jpg', $dst_file ); 88 89 // The directory containing the original file may no longer exist when 90 // using a replication plugin. 91 wp_mkdir_p( dirname( $dst_file ) ); 92 93 $dst_file = dirname( $dst_file ) . '/' . wp_unique_filename( dirname( $dst_file ), basename( $dst_file ) ); 94 95 if ( 'image/png' == $image_type && imagepng( $dst, $dst_file ) ) 96 return $dst_file; 97 elseif ( imagejpeg( $dst, $dst_file, apply_filters( 'jpeg_quality', 90, 'wp_crop_image' ) ) ) 75 98 return $dst_file; 76 99 else … … 105 128 106 129 foreach ( get_intermediate_image_sizes() as $s ) { 107 $sizes[$s] = array( 'width' => '', 'height' => '', 'crop' => FALSE);130 $sizes[$s] = array( 'width' => '', 'height' => '', 'crop' => false ); 108 131 if ( isset( $_wp_additional_image_sizes[$s]['width'] ) ) 109 132 $sizes[$s]['width'] = intval( $_wp_additional_image_sizes[$s]['width'] ); // For theme-added sizes … … 206 229 // exif contains a bunch of data we'll probably never need formatted in ways 207 230 // that are difficult to use. We'll normalize it and just extract the fields 208 // that are likely to be useful. Fractions and numbers are converted to231 // that are likely to be useful. Fractions and numbers are converted to 209 232 // floats, dates to unix timestamps, and everything else to strings. 210 233 $meta = array( … … 297 320 if ( ! empty($exif['FocalLength'] ) ) 298 321 $meta['focal_length'] = wp_exif_frac2dec( $exif['FocalLength'] ); 299 if ( ! empty($exif['ISOSpeedRatings'] ) ) 300 $meta['iso'] = utf8_encode( trim( $exif['ISOSpeedRatings'] ) ); 322 if ( ! empty($exif['ISOSpeedRatings'] ) ) { 323 $meta['iso'] = is_array( $exif['ISOSpeedRatings'] ) ? reset( $exif['ISOSpeedRatings'] ) : $exif['ISOSpeedRatings']; 324 $meta['iso'] = utf8_encode( trim( $meta['iso'] ) ); 325 } 301 326 if ( ! empty($exif['ExposureTime'] ) ) 302 327 $meta['shutter_speed'] = wp_exif_frac2dec( $exif['ExposureTime'] ); … … 340 365 return apply_filters('file_is_displayable_image', $result, $path); 341 366 } 367 368 /** 369 * Load an image resource for editing. 370 * 371 * @since 2.9.0 372 * 373 * @param string $attachment_id Attachment ID. 374 * @param string $mime_type Image mime type. 375 * @param string $size Optional. Image size, defaults to 'full'. 376 * @return resource|false The resulting image resource on success, false on failure. 377 */ 378 function load_image_to_edit( $attachment_id, $mime_type, $size = 'full' ) { 379 $filepath = _load_image_to_edit_path( $attachment_id, $size ); 380 if ( empty( $filepath ) ) 381 return false; 382 383 switch ( $mime_type ) { 384 case 'image/jpeg': 385 $image = imagecreatefromjpeg($filepath); 386 break; 387 case 'image/png': 388 $image = imagecreatefrompng($filepath); 389 break; 390 case 'image/gif': 391 $image = imagecreatefromgif($filepath); 392 break; 393 default: 394 $image = false; 395 break; 396 } 397 if ( is_resource($image) ) { 398 $image = apply_filters('load_image_to_edit', $image, $attachment_id, $size); 399 if ( function_exists('imagealphablending') && function_exists('imagesavealpha') ) { 400 imagealphablending($image, false); 401 imagesavealpha($image, true); 402 } 403 } 404 return $image; 405 } 406 407 /** 408 * Retrieve the path or url of an attachment's attached file. 409 * 410 * If the attached file is not present on the local filesystem (usually due to replication plugins), 411 * then the url of the file is returned if url fopen is supported. 412 * 413 * @since 3.4.0 414 * @access private 415 * 416 * @param string $attachment_id Attachment ID. 417 * @param string $size Optional. Image size, defaults to 'full'. 418 * @return string|false File path or url on success, false on failure. 419 */ 420 function _load_image_to_edit_path( $attachment_id, $size = 'full' ) { 421 $filepath = get_attached_file( $attachment_id ); 422 423 if ( $filepath && file_exists( $filepath ) ) { 424 if ( 'full' != $size && ( $data = image_get_intermediate_size( $attachment_id, $size ) ) ) { 425 $filepath = apply_filters( 'load_image_to_edit_filesystempath', path_join( dirname( $filepath ), $data['file'] ), $attachment_id, $size ); 426 } 427 } elseif ( function_exists( 'fopen' ) && function_exists( 'ini_get' ) && true == ini_get( 'allow_url_fopen' ) ) { 428 $filepath = apply_filters( 'load_image_to_edit_attachmenturl', wp_get_attachment_url( $attachment_id ), $attachment_id, $size ); 429 } 430 431 return apply_filters( 'load_image_to_edit_path', $filepath, $attachment_id, $size ); 432 } 433 434 /** 435 * Copy an existing image file. 436 * 437 * @since 3.4.0 438 * @access private 439 * 440 * @param string $attachment_id Attachment ID. 441 * @return string|false New file path on success, false on failure. 442 */ 443 function _copy_image_file( $attachment_id ) { 444 $dst_file = $src_file = get_attached_file( $attachment_id ); 445 if ( ! file_exists( $src_file ) ) 446 $src_file = _load_image_to_edit_path( $attachment_id ); 447 448 if ( $src_file ) { 449 $dst_file = str_replace( basename( $dst_file ), 'copy-' . basename( $dst_file ), $dst_file ); 450 $dst_file = dirname( $dst_file ) . '/' . wp_unique_filename( dirname( $dst_file ), basename( $dst_file ) ); 451 452 // The directory containing the original file may no longer exist when 453 // using a replication plugin. 454 wp_mkdir_p( dirname( $dst_file ) ); 455 456 if ( ! @copy( $src_file, $dst_file ) ) 457 $dst_file = false; 458 } else { 459 $dst_file = false; 460 } 461 462 return $dst_file; 463 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)