Index: wp-includes/functions.php
===================================================================
--- wp-includes/functions.php	(revision 18615)
+++ wp-includes/functions.php	(working copy)
@@ -4549,4 +4549,17 @@
 	@header( 'X-Frame-Options: SAMEORIGIN' );
 }
 
+/**
+ * Test if a given path is a stream URL
+ * 
+ * @param string $path The resource path or URL
+ * @return bool True if the path is a stream URL
+ */
+function wp_is_stream( $path ) {
+	$wrappers = stream_get_wrappers();
+	$wrappers_re = '(' . join('|', $wrappers) . ')';
+
+	return preg_match( "!^$wrappers_re://!", $path ) === 1;
+}
+
 ?>
Index: wp-includes/media.php
===================================================================
--- wp-includes/media.php	(revision 18615)
+++ wp-includes/media.php	(working copy)
@@ -444,15 +444,15 @@
 	$destfilename = "{$dir}/{$name}-{$suffix}.{$ext}";
 
 	if ( IMAGETYPE_GIF == $orig_type ) {
-		if ( !imagegif( $newimage, $destfilename ) )
+		if ( !wp_imagegif( $newimage, $destfilename ) )
 			return new WP_Error('resize_path_invalid', __( 'Resize path invalid' ));
 	} elseif ( IMAGETYPE_PNG == $orig_type ) {
-		if ( !imagepng( $newimage, $destfilename ) )
+		if ( !wp_imagepng( $newimage, $destfilename ) )
 			return new WP_Error('resize_path_invalid', __( 'Resize path invalid' ));
 	} else {
 		// all other formats are converted to jpg
 		$destfilename = "{$dir}/{$name}-{$suffix}.jpg";
-		if ( !imagejpeg( $newimage, $destfilename, apply_filters( 'jpeg_quality', $jpeg_quality, 'image_resize' ) ) )
+		if ( !wp_imagejpeg( $newimage, $destfilename, apply_filters( 'jpeg_quality', $jpeg_quality, 'image_resize' ) ) )
 			return new WP_Error('resize_path_invalid', __( 'Resize path invalid' ));
 	}
 
@@ -1012,6 +1012,94 @@
 }
 
 /**
+ * Wrap the GD image* functions (imagejpeg, imagepng, imagegif) so that images can be
+ * written to stream wrappers.
+ *
+ * @uses wp_is_stream()
+ * @see imagejpeg
+ * @see imagepng
+ * @see imagegif
+ *
+ * @param string $function The GD function to call
+ * @param resource $image The image resource to write to a file
+ * @param string $filename The destinaion file, which may be a stream URL
+ * @param int $quality Image quality (imagejpeg, imagepng)
+ * @param int $filters Image filters (imagepng)
+ * @return bool True if the image write operation succeeded.
+ */
+function _wp_imageany( $function, $image, $filename, $quality = -1, $filters = null ) {
+	$dst_file = $filename;
+
+	if ( $stream = wp_is_stream($filename) ) {
+		$filename = null;
+		ob_start();
+	}
+
+	$result = call_user_func( $function, $image, $filename, $quality, $filters );
+
+	if( $result && $stream ) {
+		$contents = ob_get_contents();
+
+		$fp = fopen( $dst_file, 'w' );
+
+		if( ! $fp )
+			return false;
+
+		fwrite( $fp, $contents );
+		fclose( $fp );
+	}
+
+	if( $stream ) {
+		ob_end_clean();
+	}
+
+	return $result;
+}
+
+/**
+ * Stream resource-aware wrapper for imagejpeg.
+ *
+ * @uses _wp_imageany
+ * @link http://www.php.net/manual/en/function.imagejpeg.php
+ *
+ * @param resource $image The image resource to write to a file
+ * @param string $filename The destinaion file, which may be a stream URL
+ * @param int $quality Image quality
+ * @return bool True if the image write operation succeeded.
+ */
+function wp_imagejpeg( $image, $filename, $quality = -1 ) {
+	return _wp_imageany( 'imagejpeg', $image, $filename, $quality );
+}
+
+/**
+ * Stream resource-aware wrapper for imagepng.
+ *
+ * @uses _wp_imageany
+ * @link http://www.php.net/manual/en/function.imagejpeg.php
+ *
+ * @param resource $image The image resource to write to a file
+ * @param string $filename The destinaion file, which may be a stream URL
+ * @param int $quality Image quality
+ * @param int $filters Filters to apply to image
+ */
+function wp_imagepng( $image, $filename, $quality = -1, $filters = null ) {
+	return _wp_imageany( 'imagepng', $image, $filename, $quality, $filters );
+}
+
+/**
+ * Stream resource-aware wrapper for imagegif.
+ *
+ * @uses _wp_imageany
+ * @link http://www.php.net/manual/en/function.imagejpeg.php
+ *
+ * @param resource $image The image resource to write to a file
+ * @param string $filename The destinaion file, which may be a stream URL
+ */
+function wp_imagegif( $image, $filename ) {
+	return _wp_imageany( 'imagegif', $image, $filename );
+}
+
+/**
  * API for easily embedding rich media such as videos and images into content.
  *
  * @package WordPress
Index: wp-admin/includes/image-edit.php
===================================================================
--- wp-admin/includes/image-edit.php	(revision 18615)
+++ wp-admin/includes/image-edit.php	(working copy)
@@ -262,11 +262,11 @@
 
 	switch ( $mime_type ) {
 		case 'image/jpeg':
-			return imagejpeg( $image, $filename, apply_filters( 'jpeg_quality', 90, 'edit_image' ) );
+			return wp_imagejpeg( $image, $filename, apply_filters( 'jpeg_quality', 90, 'edit_image' ) );
 		case 'image/png':
-			return imagepng($image, $filename);
+			return wp_imagepng($image, $filename);
 		case 'image/gif':
-			return imagegif($image, $filename);
+			return wp_imagegif($image, $filename);
 		default:
 			return false;
 	}
Index: wp-admin/includes/image.php
===================================================================
--- wp-admin/includes/image.php	(revision 18615)
+++ wp-admin/includes/image.php	(working copy)
@@ -71,7 +71,7 @@
 
 	$dst_file = preg_replace( '/\\.[^\\.]+$/', '.jpg', $dst_file );
 
-	if ( imagejpeg( $dst, $dst_file, apply_filters( 'jpeg_quality', 90, 'wp_crop_image' ) ) )
+	if ( wp_imagejpeg( $dst, $dst_file, apply_filters( 'jpeg_quality', 90, 'wp_crop_image' ) ) )
 		return $dst_file;
 	else
 		return false;
