I'm looking for a solution to create food labels as images for my web application. The labels need to be dynamically generated with custom information like calorie counts and vitamin details, depending on the user-selected products. I'm currently using the Canvas API, but it's been quite limiting. I'm thinking it might be overkill to try to build everything myself when there are likely existing APIs or frameworks that could help.
Ideally, I'd like something like a visual editor, where I can set up a template and define placeholders for the text, and then just call an API to generate the label. I've heard Canva offers something like this, but it's on their paid plan. I'm curious if there are other alternatives out there.
Alternatively, I could move away from the Canvas API and use a framework, but I'm unsure which one to select. I've heard Konva.js is popular and works well with React, but it seems a bit bloated for my simple needs. Another possibility is html2canvas, which acts more like a screenshot tool. I'm not sure if that's the best approach either. Before I dive into these options, I'd love to hear any advice on the simplest and most straightforward method to create these labels.
3 Answers
If you want the simplest route, consider template-based APIs like Bannerbear or Canva. They let you set placeholders for text and numbers, and generate images dynamically—super easy! But if you're going browser-based, Fabric.js is a great option that’s less complex than Konva, and it's better for handling text layouts without too much hassle.
A good way to go might be to create SVG files on-demand. This gives you full control over every detail, since you'd be designing the label from scratch to meet your needs. You can easily adjust rows based on the content you generate, making this a pretty solid choice for flexibility in the future. Just keep in mind if you need raster images integrated later on, that could complicate things a bit. But overall, SVGs are straightforward if you decide to learn.
I haven't worked with SVG before. Is it intuitive to build them? Would you recommend using a framework for that, or can I manage it natively? I might need to combine it with images later, so I want to ensure I'm choosing a future-proof option.
You could also try using Fabric.js or Konva.js. Both frameworks have features like positional objects and layers similar to Photoshop. Plus, they’ll allow you to convert your canvas into an image format, which is handy. Fabric.js might be a bit simpler for your template needs, and you can even save your design as JSON, which could be useful if you're generating labels for multiple products.

I think some of those are paid services, right? For a higher traffic site, I'd want to avoid unexpected costs. Generating on the client-side could be a safer bet, but I'm definitely leaning towards a template-based approach!