I know how to make and sell software online, and I can share my tips
with you.
Email
|
Twitter
|
LinkedIn
|
Comics
|
All articles
Make a web page screenshot service
Posted 25 days ago
I'll take you step by step into how to make a service that takes screenshots of webpages and returns them as an image.
First, let's assume you have google-chrome or chromium-browser installed. Both should work the same way. These browsers have command line options that let you capture a screenshot in headless mode.
chromium-browser --headless
--disable-gpu
--no-sandbox
--screenshot=out.png
--window-size=1280,900
--virtual-time-budget=1000
--user-agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"
https://cbc.ca/news
Explanation of parameters
--headless | Put it in headless mode |
--disable-gpu | Using GPU in the background sometimes gives us problems, so we disable it |
--no-sandbox | The sandbox often gives problems with headless execution as well. |
--screenshot="<filename>" | You can tell it to capture the screenshot to this file. |
--window-size=width,height | Set the width and height of the window |
--virtual-time-budget=<ms> | Wait this many milliseconds before taking the screenshot, to give the site time to execute frontend frameworks. |
--useragent="<user agent>" | Set a custom user agent, since many sites will not work with the default one used in headless mode. |
url | Url of the site to screenshot |
Making a service
Let's make it into a docker image that we can use. I won't go into the details, since I merely asked AI to do it for me. Synchronize the repo it made here:
git clone github.com/smhanov/screenshot-service
cd screenshot-service
make build
make run
This will build and create your screenshotting service.Then you can get the screenshot of any web site by going to the url:
http://localhost:5000/screenshot?url=https://cbc.ca/news
It also accepts other parameters for the various arguments.
Coding tips they don't teach you in school
Some time-saving shortcuts for C code that will make your coworkers scream. In Awe.
Why are all my lines fuzzy in cairo?
Make sure your lines are sharp using this simple trick.
5 Ways PowToon Made Me Want to Buy Their Software
Even though I saw through their tricks at every step along the way, I am now a customer and proud of it. It is worthwhile to look at what they did, because these are simple things that you can do to improve your software business.
cairo blur image surface
This really should have been included in cairo. Instead, everyone that wants to have shadows has to roll their own blur function. Here's my take on it. I'll even release this into the public domain.
Keeping Abreast of Pornographic Research in Computer Science
Burgeoning numbers of Ph.D's and grad students are choosing to study pornography. Techniques for the analysis of "objectionable images" are gaining increased attention (and grant money) from governments and research institutions around the world, as well as Google. But what, exactly, does computer science have to do with porn? In the name of academic persuit, let's roll up our sleeves and plunge deeply into this often hidden area that lies between the covers of top-shelf research journals.
How to run a linux based home web server
Sometimes you need complete control over the server, and don't want to pay $20 to $40 a month for a VPS. In this article, I'll describe step by step how to set up a home web server using Ubuntu, capable of handling modest spikes in traffic.
The PenIsland Problem: Text-to-speech for domain names
Recently, I was contracted to run a list of domain names through the custom-built pronunciation engine that powers my rhyming web site. On the first attempt, I found that the results were embarrassingly bad. A quick inspection revealed the problem: most domain names are severalwordsstucktogether.
Zero load time file formats
When your app needs to be fast, you can't afford to load things fro disk. In this toy example, an on-disk data structure helps you instantly look up lists of related words.
Zwibbler: A simple drawing program using Javascript and Canvas
Now it's a commercial product, but
Zwibbler was once a fun side-project, and here's some details on its implementation.