Building an Image-to-Sticker Generator Using Stable Diffusion, Shopify, and Printify

Building an Image-to-Sticker Generator Using Stable Diffusion, Shopify, and Printify

It’s been a while since my last post! I have to applaud people who consistently blog—it’s much harder than I expected, even with assistance from tools like ChatGPT. For this post, I’m sharing a project I’ve been working on that integrates Stable Diffusion 2.1 with Shopify and Printify APIs to create a custom image-to-sticker generator. There’s still a lot of work to be done, but it’s exciting to see the progress, and I’d love feedback from developers out there!


Overview of the Project

This project allows users to visit my website, Put A Cat On It, and generate custom cat stickers. Users can enter a description of a cat (e.g., “a cat surfing on a wave”) into a text box, and an image is generated using Stable Diffusion 2.1. The generated image is then uploaded to Printify to create a sticker product, which is automatically published on Shopify and available for purchase.

Here’s how it works:

  1. Visit the Website: Users access the site and click the “Try it here!” button, which directs them to the image generation tool.
  2. Enter a Description: Users input text describing their cat sticker idea.
  3. Generate and Publish: The app creates the image, uploads it to Printify, and publishes it as a new Shopify product.

The theme revolves entirely around cats, and I used Shopify’s built-in theme for the front-end.

Current Challenges

While the process works end-to-end, there is a significant issue I’ve encountered:

  • The Redirect Issue: After the product is created and published, the generated URL does not immediately redirect to the newly created product. The product appears in Shopify after about 2:30–3:00 minutes due to processing delays, but the link generated by the app doesn’t account for this delay.

I’ve identified that the problem likely lies in the JavaScript code, where the URL is generated before Shopify has fully published the product.

Debugging the Process

Here’s a snippet of my Flask server logs showing the process flow:

The issue lies between product creation and product URL availability. The link is provided before Shopify has fully processed the product, which causes a “404 – Page Not Found” error when clicked immediately.

Current Workaround

For now, if the redirect fails, users can click the “Continue Shopping” button on the error page. This takes them to the storefront collection, where all generated stickers are listed and available for purchase. While this works, it’s not ideal, and I aim to fix the root cause.

Proposed Solution

To address this issue, I’m planning to implement a polling mechanism in JavaScript. Here’s how it will work:

  1. After creating the product, the app will periodically check Shopify to see if the product URL is available.
  2. Once Shopify confirms the product has been published, the app will dynamically update the link in the feedback message.

I’ve already started building this polling mechanism using ChatGPT, and I’ll share updates on how it works once implemented.

Please let me know your thoughts! I’ll include the code below as well as a reminder it’s on my GitHub.

Here’s the code for the Flask server. Let me know your feedback. Remember all of this code was generate by ChatGPT-4o with Canvas.

Now, here’s the HTML code for the Shopify Liquid section.

And finally, here’s the JavaScript code that is saved as an asset file in the Code Editor section of the Shopify theme editor.

I think I know the error is being caused by the the JavaScript code providing the hyperlink when the product is published and not when the URL is provided. That will be my next focus using ChatGPT. I hope you enjoyed this blog post. It’s amazing how far we’ve come with Generative AI.

Conclusion

This project has been a fantastic learning experience. From integrating Stable Diffusion to automating Shopify product creation, I’ve tackled many challenges and gained a deeper understanding of APIs and webhooks.

That said, I’m still very much a beginner and welcome feedback or suggestions for improvement—especially on the JavaScript polling mechanism. Feel free to check out the full code on my GitHub and leave your comments!

Thank you for reading, and I hope to post more consistently in the future!


Comments

Leave a comment