def extract_upload(self,ch, method, properties, body): """ JSON Payload should look like {'user_id':1234, 'picture':'http://foo.bar', 'id':'facebook_image_id'} """ self.logger.info('Processing Record') body = json.loads(body) image_url, user, photo_id = body['source'], body['user_id'], body['id'] normalized = image_manipulation.grayscale( image_manipulation.resize_image(get_image(image_url))) #find roi's roi = image_manipulation.find_faces(normalized) self.logger.debug('found %d regions of interest', len(roi)) #crop images to get faces cropped = [] for face in roi: image_buffer= cStringIO.StringIO() cropped_image = image_manipulation.crop_face(normalized, face) cropped_image.save(image_buffer, format='JPEG') cropped.append(image_buffer) #find the bucket to upload to user_bucket = s3_tools.get_or_create_bucket(self.s3_connection, 'robj.findme') #the created keys created_keys = [] #upload each cropped image to s3 for index, extracted in enumerate(cropped): created_keys.append(s3_tools.upload_string_to_bucket(user_bucket, 'user_images/{}_{}_{}'.format(user,photo_id,index), extracted.getvalue())) for key in created_keys: #post the body back to the image_creation_queue self.rmq_channel.basic_publish(exchange='', routing_key=self.creation_queue_name, body = json.JSONEncoder().encode({ "key": key.name, "user_id": user, "original_image_url": image_url }), properties=pika.BasicProperties( delivery_mode = 2, # make message persistent ) ) self.logger.info('Published image to image creation queue') #we're done, so acknowledge the message self.rmq_channel.basic_ack(delivery_tag = method.delivery_tag)
def test_grayscale(self): """ Test conversion to grayscale """ grayscaled = image_manipulation.grayscale(self.image) self.assertEqual(grayscaled.mode, "L")