Skip to content

Instantly share code, notes, and snippets.

@thiagoferreiraw
Last active November 25, 2021 19:16
Show Gist options
  • Save thiagoferreiraw/43f2f03e0d4cbd15149f0cc2f0425a27 to your computer and use it in GitHub Desktop.
Save thiagoferreiraw/43f2f03e0d4cbd15149f0cc2f0425a27 to your computer and use it in GitHub Desktop.
create_promotional_image
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