How I've made my own image manipulation CDN for 3€/month

How I've made my own image manipulation CDN for 3€/month

Gummibeer

Astroneer
Moderator
Local time
12:02
Joined
Oct 5, 2019
Messages
1,169
Pronouns
he/him

Hey all,

because of a downtime of Image cache & resize service today I've checked alternatives (except paying thousands of dollars for Cloudinary, Imgix ...).
After some research I've found h2non/imaginary which does everything I want.

So I've booted a 3€/month VPS on Truly thrifty cloud hosting - Hetzner Online GmbH and installed it - result: works like a charm.

So I started playing around, added a list of allowed URLs, configured Cloudflare CDN via page rules and now I have a blazing fast image manipulation CDN which has a whitelist of domains, uses signed URLs to prevent user manipulation and the worlds best (free) CDN infront of it - which also adds SSL without any letsencrypt or whatever.

Conclusion:
Hetzner Cloud is super easy to setup, the servers are pretty fast and the price is unbeatable.
Imaginary has a not perfect HTTP API, but I will build a PHP fluent URL builder like my Astrotomic/php-weserv-images before. Except of this the library is outstanding. The support of URL retrieving and all the security features are perfect to setup a public image CDN service limited to a set of domains.

The major benefit for me: I have a single service which will handle all my pages and every page can use it's own CDN url. All my pages are on Cloudflare already - so I only have to add an A-record and a page rule:

Code:
https://imaginary.example.com/*
SSL: Flexible
Browser Cache TTL: a month
Cache Level: Cache Everything
Edge Cache TTL: a month

And because Cloudflare does all the CDN and caching stuff I don't have to care about it - don't have to provide/pay for any storage to cache.

 

Gummibeer

Astroneer
Moderator
Local time
12:02
Joined
Oct 5, 2019
Messages
1,169
Pronouns
he/him

And after I've told it @tom he destroyed my dream and gifted me an unicorn:


Is there anything Cloudflare doesn't offer?^^

Okay - it only applies to business and enterprise, so 200$+

Image Resizing is available today for Business and Enterprise Customers.

 
Last edited:

Adam

Mr. Webwide
Administrator
Local time
11:02
Joined
Sep 24, 2019
Messages
1,257
Pronouns
he/him

This is awesome! Could use something like this to open up image uploads to all on here.

 

Gummibeer

Astroneer
Moderator
Local time
12:02
Joined
Oct 5, 2019
Messages
1,169
Pronouns
he/him

This is awesome! Could use something like this to open up image uploads to all on here.
Don't get me wrong: you still need anywhere to store the images. But this one could be the slowest VM in the world, but this setup allows you to resize them on the fly and have the resizes cached in a CDN.
So if storage is the problem: this isn't the solution. If only traffic is the problem: here you go! 😉

Imaginary can also load from a local directory. So if you find a cheap server with lots of storage you can use relative paths instead of full URLs.

 

tom

Creator of StickerRun®
Community Team
Local time
12:02
Joined
Oct 13, 2019
Messages
258

And after I've told it @tom he destroyed my dream and gifted me an unicorn

I am so so so so so sorry for this. Didn't know you hadn't seen it yet 😅 I love how you handled this and the overall solution. Really awesome stuff!

 

Mike Rees

Member
Local time
11:02
Joined
Feb 3, 2020
Messages
71

Depending on the traffic you're expecting, this AWS Serverless solution might work out cheaper. Of course you lose the added benefits you mention, but I thought I'd chip in with this one as it's proven invaluable to me in the past.

 

Gummibeer

Astroneer
Moderator
Local time
12:02
Joined
Oct 5, 2019
Messages
1,169
Pronouns
he/him

Depending on the traffic you're expecting, this AWS Serverless solution might work out cheaper. Of course you lose the added benefits you mention, but I thought I'd chip in with this one as it's proven invaluable to me in the past.
My problem with all serverless solutions is that I have to handle really large images (100-150MB PNGs). All FaaS I've found limit file inputs with 100MB or the RAM isn't enough.

And I like the 3€ fixed over a flexible pricing.
But I agree that for most simple web images cases FaaS would be a good solution.

And at least for me AWS isn't as easy to setup as a simple VM.

 
Last edited:
Top