logic to process images