Ticket #18543: gd-imagejpeg-wrapper-tempnam.diff
File gd-imagejpeg-wrapper-tempnam.diff, 5.5 KB (added by , 13 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 if ( !function_exists('wp_tempnam') ) 1035 include ABSPATH . '/wp-admin/includes/file.php'; 1036 1037 $filename = wp_tempnam('imageany'); 1038 } 1039 1040 $result = call_user_func( $function, $image, $filename, $quality, $filters ); 1041 1042 if( $stream ) { 1043 if( $result ) 1044 $fp = copy( $filename, $dst_file ); 1045 1046 unlink( $filename ); 1047 } 1048 1049 return $result; 1050 } 1051 1052 /** 1053 * Stream resource-aware wrapper for imagejpeg. 1054 * 1055 * @uses _wp_imageany 1056 * @link http://www.php.net/manual/en/function.imagejpeg.php 1057 * 1058 * @param resource $image The image resource to write to a file 1059 * @param string $filename The destinaion file, which may be a stream URL 1060 * @param int $quality Image quality 1061 * @return bool True if the image write operation succeeded. 1062 */ 1063 function wp_imagejpeg( $image, $filename, $quality = -1 ) { 1064 return _wp_imageany( 'imagejpeg', $image, $filename, $quality ); 1065 } 1066 1067 /** 1068 * Stream resource-aware wrapper for imagepng. 1069 * 1070 * @uses _wp_imageany 1071 * @link http://www.php.net/manual/en/function.imagejpeg.php 1072 * 1073 * @param resource $image The image resource to write to a file 1074 * @param string $filename The destinaion file, which may be a stream URL 1075 * @param int $quality Image quality 1076 * @param int $filters Filters to apply to image 1077 */ 1078 function wp_imagepng( $image, $filename, $quality = -1, $filters = null ) { 1079 return _wp_imageany( 'imagepng', $image, $filename, $quality, $filters ); 1080 } 1081 1082 /** 1083 * Stream resource-aware wrapper for imagegif. 1084 * 1085 * @uses _wp_imageany 1086 * @link http://www.php.net/manual/en/function.imagejpeg.php 1087 * 1088 * @param resource $image The image resource to write to a file 1089 * @param string $filename The destinaion file, which may be a stream URL 1090 */ 1091 function wp_imagegif( $image, $filename ) { 1092 return _wp_imageany( 'imagegif', $image, $filename ); 1093 } 1094 1095 /** 1015 1096 * API for easily embedding rich media such as videos and images into content. 1016 1097 * 1017 1098 * @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;