| | 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 | /** |