Ticket #18543: gd-imagejpeg-wrapper-ob.diff
File gd-imagejpeg-wrapper-ob.diff, 5.5 KB (added by , 14 years ago) |
---|
-
wp-includes/functions.php
4549 4561 @header( 'X-Frame-Options: SAMEORIGIN' ); 4550 4562 } 4551 4563 4564 /** 4565 * Test if a given path is a stream URL 4566 * 4567 * @param string $path The resource path or URL 4568 * @return bool True if the path is a stream URL 4569 */ 4570 function wp_is_stream( $path ) { 4571 $wrappers = stream_get_wrappers(); 4572 $wrappers_re = '(' . join('|', $wrappers) . ')'; 4573 4574 return preg_match( "!^$wrappers_re://!", $path ) === 1; 4575 } 4576 4552 4577 ?> -
wp-includes/media.php
444 444 $destfilename = "{$dir}/{$name}-{$suffix}.{$ext}"; 445 445 446 446 if ( IMAGETYPE_GIF == $orig_type ) { 447 if ( ! imagegif( $newimage, $destfilename ) )447 if ( !wp_imagegif( $newimage, $destfilename ) ) 448 448 return new WP_Error('resize_path_invalid', __( 'Resize path invalid' )); 449 449 } elseif ( IMAGETYPE_PNG == $orig_type ) { 450 if ( ! imagepng( $newimage, $destfilename ) )450 if ( !wp_imagepng( $newimage, $destfilename ) ) 451 451 return new WP_Error('resize_path_invalid', __( 'Resize path invalid' )); 452 452 } else { 453 453 // all other formats are converted to jpg 454 454 $destfilename = "{$dir}/{$name}-{$suffix}.jpg"; 455 if ( ! imagejpeg( $newimage, $destfilename, apply_filters( 'jpeg_quality', $jpeg_quality, 'image_resize' ) ) )455 if ( !wp_imagejpeg( $newimage, $destfilename, apply_filters( 'jpeg_quality', $jpeg_quality, 'image_resize' ) ) ) 456 456 return new WP_Error('resize_path_invalid', __( 'Resize path invalid' )); 457 457 } 458 458 … … 1012 1012 } 1013 1013 1014 1014 /** 1015 * Wrap the GD image* functions (imagejpeg, imagepng, imagegif) so that images can be 1016 * written to stream wrappers. 1017 * 1018 * @uses wp_is_stream() 1019 * @see imagejpeg 1020 * @see imagepng 1021 * @see imagegif 1022 * 1023 * @param string $function The GD function to call 1024 * @param resource $image The image resource to write to a file 1025 * @param string $filename The destinaion file, which may be a stream URL 1026 * @param int $quality Image quality (imagejpeg, imagepng) 1027 * @param int $filters Image filters (imagepng) 1028 * @return bool True if the image write operation succeeded. 1029 */ 1030 function _wp_imageany( $function, $image, $filename, $quality = -1, $filters = null ) { 1031 $dst_file = $filename; 1032 1033 if ( $stream = wp_is_stream($filename) ) { 1034 $filename = null; 1035 ob_start(); 1036 } 1037 1038 $result = call_user_func( $function, $image, $filename, $quality, $filters ); 1039 1040 if( $result && $stream ) { 1041 $contents = ob_get_contents(); 1042 1043 $fp = fopen( $dst_file, 'w' ); 1044 1045 if( ! $fp ) 1046 return false; 1047 1048 fwrite( $fp, $contents ); 1049 fclose( $fp ); 1050 1051 ob_end_clean(); 1052 } 1053 1054 return $result; 1055 } 1056 1057 /** 1058 * Stream resource-aware wrapper for imagejpeg. 1059 * 1060 * @uses _wp_imageany 1061 * @link http://www.php.net/manual/en/function.imagejpeg.php 1062 * 1063 * @param resource $image The image resource to write to a file 1064 * @param string $filename The destinaion file, which may be a stream URL 1065 * @param int $quality Image quality 1066 * @return bool True if the image write operation succeeded. 1067 */ 1068 function wp_imagejpeg( $image, $filename, $quality = -1 ) { 1069 return _wp_imageany( 'imagejpeg', $image, $filename, $quality ); 1070 } 1071 1072 /** 1073 * Stream resource-aware wrapper for imagepng. 1074 * 1075 * @uses _wp_imageany 1076 * @link http://www.php.net/manual/en/function.imagejpeg.php 1077 * 1078 * @param resource $image The image resource to write to a file 1079 * @param string $filename The destinaion file, which may be a stream URL 1080 * @param int $quality Image quality 1081 * @param int $filters Filters to apply to image 1082 */ 1083 function wp_imagepng( $image, $filename, $quality = -1, $filters = null ) { 1084 return _wp_imageany( 'imagepng', $image, $filename, $quality, $filters ); 1085 } 1086 1087 /** 1088 * Stream resource-aware wrapper for imagegif. 1089 * 1090 * @uses _wp_imageany 1091 * @link http://www.php.net/manual/en/function.imagejpeg.php 1092 * 1093 * @param resource $image The image resource to write to a file 1094 * @param string $filename The destinaion file, which may be a stream URL 1095 */ 1096 function wp_imagegif( $image, $filename ) { 1097 return _wp_imageany( 'imagegif', $image, $filename ); 1098 } 1099 1100 /** 1015 1101 * API for easily embedding rich media such as videos and images into content. 1016 1102 * 1017 1103 * @package WordPress -
wp-admin/includes/image-edit.php
262 262 263 263 switch ( $mime_type ) { 264 264 case 'image/jpeg': 265 return imagejpeg( $image, $filename, apply_filters( 'jpeg_quality', 90, 'edit_image' ) );265 return wp_imagejpeg( $image, $filename, apply_filters( 'jpeg_quality', 90, 'edit_image' ) ); 266 266 case 'image/png': 267 return imagepng($image, $filename);267 return wp_imagepng($image, $filename); 268 268 case 'image/gif': 269 return imagegif($image, $filename);269 return wp_imagegif($image, $filename); 270 270 default: 271 271 return false; 272 272 } -
wp-admin/includes/image.php
71 71 72 72 $dst_file = preg_replace( '/\\.[^\\.]+$/', '.jpg', $dst_file ); 73 73 74 if ( imagejpeg( $dst, $dst_file, apply_filters( 'jpeg_quality', 90, 'wp_crop_image' ) ) )74 if ( wp_imagejpeg( $dst, $dst_file, apply_filters( 'jpeg_quality', 90, 'wp_crop_image' ) ) ) 75 75 return $dst_file; 76 76 else 77 77 return false;