Index: wp-includes/class-wp-image-editor-gd.php
===================================================================
--- wp-includes/class-wp-image-editor-gd.php	(revision 24502)
+++ wp-includes/class-wp-image-editor-gd.php	(working copy)
@@ -401,4 +401,22 @@
 				return imagejpeg( $this->image, null, $this->quality );
 		}
 	}
+
+	/**
+	 * Either calls editor's save function or handles file as a stream.
+	 *
+	 * @since 3.5.0
+	 * @access protected
+	 *
+	 * @param string|stream $filename
+	 * @param callable $function
+	 * @param array $arguments
+	 * @return boolean
+	 */
+	protected function make_image( $filename, $function, $arguments ) {
+		if ( wp_is_stream( $filename ) )
+			$arguments[1] = null;
+
+		return parent::make_image( $filename, $function, $arguments );
+	}
 }
Index: wp-includes/class-wp-image-editor.php
===================================================================
--- wp-includes/class-wp-image-editor.php	(revision 24502)
+++ wp-includes/class-wp-image-editor.php	(working copy)
@@ -327,14 +327,11 @@
 	 * @return boolean
 	 */
 	protected function make_image( $filename, $function, $arguments ) {
-		$dst_file = $filename;
-
-		// The directory containing the original file may no longer exist when using a replication plugin.
-		wp_mkdir_p( dirname( $dst_file ) );
-
 		if ( $stream = wp_is_stream( $filename ) ) {
-			$filename = null;
 			ob_start();
+		} else {
+			// The directory containing the original file may no longer exist when using a replication plugin. 
+			wp_mkdir_p( dirname( $filename ) ); 
 		}
 
 		$result = call_user_func_array( $function, $arguments );
@@ -342,7 +339,7 @@
 		if ( $result && $stream ) {
 			$contents = ob_get_contents();
 
-			$fp = fopen( $dst_file, 'w' );
+			$fp = fopen( $filename, 'w' );
 
 			if ( ! $fp )
 				return false;
