memory = FreeImage::Memory.new
image = FreeImage::Bitmap.open(...)
memory.save(image, :jpeg)
memory.memory.bytes
# => "\xFF\xD8\xFF\xE0"
memory.memory.count
# => 1017134
memory.memory.size
# => 9223372036854775807
This returns a memory object that contains 4 bytes, but has what appears to be the correct bytes count.
If I try image.save(memory, :jpeg) I get the same result.