def test_get_images_from_pdf(): from lembrar import image from StringIO import StringIO test_file_stream = resource_stream(__name__, 'test.pdf') images = image.get_images_from_stream(test_file_stream) assert len(images) == 2 # abuse the fact that get_images_from_stream would fail # if it's own returned images aren't jpeg assert len(image.get_images_from_stream(StringIO(images[0]))) == 1 assert len(image.get_images_from_stream(StringIO(images[1]))) == 1
def test_get_images_from_image(): from lembrar import image test_file_stream = resource_stream(__name__, 'test.jpg') images = image.get_images_from_stream(test_file_stream) test_file_stream.seek(0) assert len(images) == 1 assert images[0] == test_file_stream.read()
def add(request): title = request.params['title'] created = request.params.get('created', datetime.utcnow()) or \ datetime.utcnow() description = request.params.get('description', '') force_detection = request.params.get("force_detection", 'true').lower() == 'true' accepted_languages = request.registry.settings['accepted_languages'] imgstream = request.params['file'].file doc_list = request.db.docs for image in get_images_from_stream(imgstream): try: lang, img, text = recognize(image, accepted_languages, force_detection) except TypeError, e: err_msg = "Error: " + str(e) request.session.flash(err_msg, 'failure') return HTTPServerError(explanation=err_msg, detail='Go back, unselect force '\ 'detection, and try again') text += " " + description + " " + title if text: search_terms = list(index(text, [lang])) else: search_terms = '' thumb = get_thumbnail(image) doc_list.insert({ 'img': Binary(image), 'thumb': Binary(thumb), 'created': created, 'version': 4, 'forced_detection': force_detection, 'language': lang, 'keywords': [], 'search_terms': search_terms, 'title': title })
def add(request): title = request.params['title'] created = request.params.get('created', datetime.utcnow()) or \ datetime.utcnow() description = request.params.get('description', '') force_detection = request.params.get("force_detection", 'true').lower() == 'true' accepted_languages = request.registry.settings['accepted_languages'] imgstream = request.params['file'].file doc_list = request.db.docs for image in get_images_from_stream(imgstream): try: lang, img, text = recognize(image, accepted_languages, force_detection) except TypeError, e: err_msg = "Error: " + str(e) request.session.flash(err_msg, 'failure') return HTTPServerError(explanation=err_msg, detail='Go back, unselect force '\ 'detection, and try again') text += " " + description + " " + title if text: search_terms = list(index(text, [lang])) else: search_terms = '' thumb = get_thumbnail(image) doc_list.insert({'img': Binary(image), 'thumb': Binary(thumb), 'created': created, 'version': 4, 'forced_detection': force_detection, 'language': lang, 'keywords': [], 'search_terms': search_terms, 'title': title})
def test_get_images_from_bad(): from lembrar import image test_file_stream = resource_stream(__name__, 'test_image.py') images = image.get_images_from_stream(test_file_stream)