Generate a color palette from an image using JavaScript