Last active
November 25, 2021 19:16
-
-
Save thiagoferreiraw/43f2f03e0d4cbd15149f0cc2f0425a27 to your computer and use it in GitHub Desktop.
create_promotional_image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io | |
from .models import Coupon | |
from .utils import create_png_from_svg_template | |
def create_promotional_image(coupon_id): | |
coupon = Coupon.objects.get(id=coupon_id) | |
with io.BytesIO() as output_file: | |
create_png_from_svg_template( | |
"coupon/templates/promotional-template.svg", | |
{"_WIDTH": 400, "_HEIGHT": 200, "_PROMO_CODE": "ABCD1234"}, | |
output_file, | |
) | |
coupon.marketing_image.save(f"coupon-{coupon.code}.png", output_file) | |
coupon.save() | |
return coupon.marketing_image.url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment