fixed recipe sage import and image procssing with pillow 10

This commit is contained in:
vabene1111 2023-10-07 08:11:50 +02:00
parent 2c8e029811
commit 221c466c18
2 changed files with 4 additions and 4 deletions

View File

@ -10,7 +10,7 @@ def rescale_image_jpeg(image_object, base_width=1020):
width_percent = (base_width / float(img.size[0])) width_percent = (base_width / float(img.size[0]))
height = int((float(img.size[1]) * float(width_percent))) height = int((float(img.size[1]) * float(width_percent)))
img = img.resize((base_width, height), Image.ANTIALIAS) img = img.resize((base_width, height), Image.LANCZOS)
img_bytes = BytesIO() img_bytes = BytesIO()
img.save(img_bytes, 'JPEG', quality=90, optimize=True, icc_profile=icc_profile) img.save(img_bytes, 'JPEG', quality=90, optimize=True, icc_profile=icc_profile)
@ -21,7 +21,7 @@ def rescale_image_png(image_object, base_width=1020):
image_object = Image.open(image_object) image_object = Image.open(image_object)
wpercent = (base_width / float(image_object.size[0])) wpercent = (base_width / float(image_object.size[0]))
hsize = int((float(image_object.size[1]) * float(wpercent))) hsize = int((float(image_object.size[1]) * float(wpercent)))
img = image_object.resize((base_width, hsize), Image.ANTIALIAS) img = image_object.resize((base_width, hsize), Image.LANCZOS)
im_io = BytesIO() im_io = BytesIO()
img.save(im_io, 'PNG', quality=90) img.save(im_io, 'PNG', quality=90)

View File

@ -39,7 +39,7 @@ class RecipeSage(Integration):
ingredients_added = False ingredients_added = False
for s in file['recipeInstructions']: for s in file['recipeInstructions']:
step = Step.objects.create( step = Step.objects.create(
instruction=s['text'], space=self.request.space, instruction=s['text'], space=self.request.space, show_ingredients_table=self.request.user.userpreference.show_step_ingredients,
) )
if not ingredients_added: if not ingredients_added:
ingredients_added = True ingredients_added = True
@ -49,7 +49,7 @@ class RecipeSage(Integration):
f = ingredient_parser.get_food(food) f = ingredient_parser.get_food(food)
u = ingredient_parser.get_unit(unit) u = ingredient_parser.get_unit(unit)
step.ingredients.add(Ingredient.objects.create( step.ingredients.add(Ingredient.objects.create(
food=f, unit=u, amount=amount, note=note, original_text=ingredient, space=self.request.space, show_ingredients_table=self.request.user.userpreference.show_step_ingredients, food=f, unit=u, amount=amount, note=note, original_text=ingredient, space=self.request.space,
)) ))
recipe.steps.add(step) recipe.steps.add(step)