changed to pass image as a buffer instead of reading the file from disk