👋🏽 Hi, everyone! Over the past 3 days, I worked on EP - a platform that lets you upload photos from events. I got the inspiration to build this from Vercel's Next.js Conf 2022 site & Canva's dashboard card.
😍 Demo
🏚 Platform Primitives
I used Netlify Image CDN to ensure seamless resizing, format conversion, and quality optimization, all tailored to fit specific dimensions. I created helper functions to help me generate src sets for images.
Unfortunately, I didn't end up using it because it didn't work as I expected. I expected a blurred out version of an image with the blurhash format but I got a visible version. This made me opt to use a Netlify function to generate the blurhashes myself. Learn more about blurhash.
constsharp=require('sharp');const{encode}=require('blurhash');const{PrismaClient}=require('@prisma/client');constprisma=newPrismaClient();exports.handler=async (event,context)=>{try{constrequestBody=JSON.parse(event.body);const{url}=requestBody;// Convert image to buffer...constloadedImage=awaitfetch(url).then(response=>response.blob()).then(blob=>blob.arrayBuffer());const{data,info}=awaitsharp(Buffer.from(loadedImage)).ensureAlpha().raw().toBuffer({resolveWithObject:true});constblurhash=encode(newUint8ClampedArray(data),info.width,info.height,4,4);awaitprisma.photo.update({where:{url:url},data:{blurhash:blurhash}});return{statusCode:200,body:JSON.stringify({message:'Blurhash updated successfully'})};}catch (error){console.log('Netlify Function Error :>>',error);return{statusCode:500,body:JSON.stringify({message:'Internal Server Error',error})};}finally{awaitprisma.$disconnect();}};
This worked pretty well until I another issue came up - timeout 😪. The function took about 30 seconds every time it ran, depending on the size of the image. As you may well know, functions on Netlify's free tier times out after 10 seconds. I then came up with a client-side alternative using Web Workers.
With this, it took about 15-20 seconds. I had to settle for this as it was the best option I had. Still haven't figured out why it took so long on a lambda function ;(.
The site was hosted on Netlify & I added a custom subdomain (https://ep.omzi.dev).
Visit here to login. Please be considerate of others & be careful what you upload there 🙏🏽. Daalu!
✨ Conclusion
Whew! This was shorter than I expected 👀. Thanks for making it this far! Feel free to give EP a try & let me know in the comment section below 😎.
I'm grateful to Netlify for organizing this hackathon. I learnt a couple of new stuff while working on EP 😁.
Have any constructive feedback for me? I’d love to know in the comments section below or via a Twitter DM (I’d prefer this). Connect with me on Twitter (@0xOmzi).
Nice work!