Index: image_science.rb
===================================================================
--- image_science.rb	(revision 618)
+++ image_science.rb	(working copy)
@@ -20,6 +20,11 @@
   end
 
   ##
+  #  Loads and yields image from +buffer+
+  def self.with_buffer(buffer, length) # :yields: image
+  end
+
+  ##
   # Crops an image to +left+, +top+, +right+, and +bottom+ and then
   # yields the new image.
 
@@ -157,7 +162,29 @@
         rb_raise(rb_eTypeError, "Unknown file format");
       }
     END
+    
+    
+    builder.c_singleton <<-"END"
+      VALUE with_buffer(char *buffer, unsigned long length) {
+        VALUE result = Qnil;
+        
+        FIMEMORY *mem_stream = FreeImage_OpenMemory(buffer, length);
+        FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromMemory(mem_stream, 0);
+        if( fif != FIF_UNKNOWN ) {
+          FIBITMAP *bitmap = FreeImage_LoadFromMemory(fif, mem_stream, 0);
+          result = wrap_and_yield(bitmap, self, fif);
+        }
+        FreeImage_CloseMemory(mem_stream);
+        
+        if( result == Qnil ) {
+          rb_raise(rb_eTypeError, "Unknown file format");
+        }
 
+        return result;
+      }
+    END
+    
+
     builder.c <<-"END"
       VALUE with_crop(int l, int t, int r, int b) {
         FIBITMAP *copy;
