def create(self, docs, **kwargs): ids = [] for doc in docs: item = doc.pop("item") crop = doc.pop("crop") orig = item["renditions"]["original"] size = get_crop_size(crop, orig.get("width", 800), orig.get("height", 600)) orig_file = get_file(orig, item) filename = get_random_string() ok, output = crop_image(orig_file, filename, crop, size) if ok: metadata = encode_metadata(process_image(orig_file)) metadata.update({"length": json.dumps(len(output.getvalue()))}) output = fix_orientation(output) media = app.media.put(output, filename=filename, content_type=orig["mimetype"], metadata=metadata) doc["href"] = app.media.url_for_media(media, orig["mimetype"]) doc["width"] = output.width doc["height"] = output.height doc["metadata"] = metadata ids.append(media) return ids
def create(self, docs, **kwargs): ids = [] for doc in docs: item = doc.pop('item') crop = doc.pop('crop') size = get_crop_size(crop) orig = item['renditions']['original'] orig_file = get_file(orig, item) filename = get_random_string() ok, output = crop_image(orig_file, filename, crop, size) if ok: metadata = encode_metadata(process_image(orig_file)) metadata.update({'length': json.dumps(len(output.getvalue()))}) output = fix_orientation(output) media = app.media.put(output, filename, orig['mimetype'], metadata=metadata) doc['href'] = app.media.url_for_media(media, orig['mimetype']) doc['width'] = output.width doc['height'] = output.height ids.append(media) return ids
def create(self, docs, **kwargs): ids = [] for doc in docs: item = doc.pop('item') crop = doc.pop('crop') orig = item['renditions']['original'] size = get_crop_size(crop, orig.get('width', 800), orig.get('height', 600)) orig_file = get_file(orig, item) filename = get_random_string() ok, output = crop_image(orig_file, filename, crop, size) if ok: metadata = encode_metadata(process_image(orig_file)) metadata.update({'length': json.dumps(len(output.getvalue()))}) output = fix_orientation(output) media = app.media.put(output, filename, orig['mimetype'], metadata=metadata) doc['href'] = app.media.url_for_media(media, orig['mimetype']) doc['width'] = output.width doc['height'] = output.height ids.append(media) return ids