![How To Capture Highly Customizable Snapshots of Any Website in Delphi | Embarcadero RAD Studio Delphi C++Builder Blogs how to capture highly customizable snapshots of any website in delphi](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/07/How-To-Capture-Highly-Customizable-Snapshots-of-Any-Website-in-Delphi-3329234-4373731.jpg?resize=1140%2C675&ssl=1)
Screenshotlayer is a lightweight REST API built to deliver high-quality PNG, JPEG & GIF visual website snapshots through a simple and easy-to-use interface. We’re going to make use of that API to create a really powerful website snapshot app.
Table of Contents
Website snapshots, in Delphi, using the Screenshotlayer API
The Screenshotlayer API is easy to integrate and works without requiring a queue. With the Screenshotlayer API, you can create a reliable web snapshot automation service. You can capture daily, weekly or monthly, and create an archive if you need.
In this post, we will use the Delphi FireMonkey Low-Code Wizard to integrate Screenshotlayer API into a cross-platform desktop and mobile application with Windows Apps Studio.
What is the Screenshotlayer API?
The Screenshotlayer API is a world-class RESTful web service to capture highly customizable snapshots of any website in seconds. Just give the website URL, and the web service returns you a screenshot of the website.
It offers advanced options, for instance:
- Set preferred thumbnail dimensions and viewport
- Inject your CSS
- Specify a capturing delay
- Export to AWS S3, FTP
- and more
How to use Screenshotlayer API?
Capturing a snapshot using the Screenshotlayer API is simple. Each API request is based on the following URL and can be configured with different parameters.
![img11529896 | Embarcadero RAD Studio Delphi C++Builder Blogs How To Capture Highly Customizable Website Snapshots capture API end point](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/07/img-1-1529896.jpg?resize=750%2C100&ssl=1)
To make a simple request, you should pass the API access key and URL of the website that you want to take a screenshot of. Moreover, based on how you wish to configure your screenshot, you can choose from several optional parameters:
- fullpage – take a full height of the target website
- width – specify your preferred thumbnail width in pixels
- viewport – specify your preferred viewport dimensions in pixels
- format – screenshot output format
- secret_key – your secret key, an MD5 hash of the target & secret word (optional)
- delay – specify a delay before a screenshot is captured (in seconds)
- export – export snapshot via custom FTP path or using your AWS S3 user details
Let’s see an example of a request
![img2screenshotlayerapidelphifiremonkeyintegration2787002 | Embarcadero RAD Studio Delphi C++Builder Blogs How To Capture Highly Customizable Website Snapshots API usage screen shot](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/07/img-2-screenshotlayer-api-delphi-firemonkey-integration-2787002.jpg?resize=750%2C287&ssl=1)
Depending on your subscription plan, you can have more secure data streams and features or limits. For instance, higher-level subscription plan users can establish a secure connection. You can have maximum API performance, and the request limit is higher.
URL Encryption – If you need a more secure connection, you can utilize the secret key for every API request. First, you need to specify the secret key on the dashboard. My secret key, of course, is the word “delphi”.
Then we need to combine the URL and secret keyword into one string and create an MD5 hash out of the string. After that, you can give that value in the query.
The Screenshotlayer API Features
By default, screenshots are rendered based on the height of the selected viewport. You can alternatively request the full height of the target website with the parameters that we talked about above.
CSS Injection – The Screenshotlayer API enables you to inject a custom CSS stylesheet into the target website by appending an existing CSS file URL to the API’s css_url parameter.
TTL (Caching Time) – By default, website snapshots are cached for 30 days. Using the ttl parameter, you can specify a custom caching time lower than the default setting.
Furthermore, you can have a fresh screenshot of the target website by using the force parameter, which refreshes the target website.
How to export website snapshots to AWS S3 or FTP?
Based on your subscription level, you can save your snapshots to an AWS S3 bucket or an FTP server to which you have access. The configuration can be done like this:
![img3screenshotlayerapidelphiexporttoawss3bucketorftp4316883 | Embarcadero RAD Studio Delphi C++Builder Blogs How To Capture Highly Customizable Website Snapshots Amazon settings](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/07/img-3-screenshotlayer-api-delphi-export-to-aws-s3-bucket-or-ftp-4316883.jpg?resize=750%2C112&ssl=1)
How to build a website snapshot app which runs on Windows, macOS, Android, and iOS and works with the Screenshotlayer API?
We have explored the fantastic capabilities of the FireMonkey App Low Code Wizard before on this blog. It’s an outstanding tool to turn a great idea into a fully-working cross-platform app with little or no code. In this demonstration will use the Low Code Wizard to make our cross-platform application with Delphi.
With the FireMonkey App Low Code Wizard you can create a fully functional Delphi cross-platform application with multiple screens. Even better, unlike some other “low code” development platforms, you can do as much modification and customization with your code, and it’s easy to use too.
How do I start Delphi FireMonkey Low Code development?
Open your Delphi IDE and go to Tools->GetIt Package Manager and search for “low code”! There you can install Low Code Wizard for FireMonkey. You can also learn more in depth-information about this great addition to the power of Delphi here: https://getitnow.embarcadero.com/firemonkey-app-low-code-wizard/
![mailboxlayerapifiremonkeyapplowcodewizardGetIt1058739 | Embarcadero RAD Studio Delphi C++Builder Blogs How To Capture Highly Customizable Website Snapshots low code wizard](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/07/mailbox-layer-api-firemonkey-app-low-code-wizard-GetIt-1058739.png?resize=750%2C422&ssl=1)
After installation, you can open File->New->Other and select Multi-Device->FireMonkey Template App. It shows you a wizard and you can select which type of screens you need.
![lowcodewizardpicturenewemptyfiremonkeyformDelphi1349801 | Embarcadero RAD Studio Delphi C++Builder Blogs How To Capture Highly Customizable Website Snapshots choosing options for hte low code wizard](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/07/low-code-wizard-picture-new-empty-firemonkey-form-Delphi-1349801.png?resize=750%2C453&ssl=1)
How do I connect REST endpoint with Delphi?
RAD Studio’s toolset is generous and gives you dozens of different tools and components to make your development time productive.
Since this API is just a simple response that gives the only image, we will use one of the Internet Direct components. From the component palette, drop a TIdHTTP component and create the OnClick event on the Request button. For more complicated REST interactions it can be faster (and requires less code) to use the RAD Studio REST Debugger.
![programstructure7872487 | Embarcadero RAD Studio Delphi C++Builder Blogs How To Capture Highly Customizable Website Snapshots final screen layout](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/07/program-structure-7872487.jpg?resize=672%2C697&ssl=1)
Here is our code that creates a required query and loads the image response to the memory stream. Then shows it to a user and saves it to a physical file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
procedure TNewFormFrame.BtnSendRequestClick(Sender: TObject); begin inherited; var MS := TMemoryStream.Create; var BM := TBitmap.Create; var HashMD5 := THashMD5.Create; try var IsFullPage := '0'; // default value: not full page if ChkBFullPage.IsChecked then IsFullPage := '1'; // generate a hash string: url+secret_keyword var SecretHash := HashMD5.GetHashString(EdtURL.Text + EdtSecretKey.Text); var Query := Format('http://api.screenshotlayer.com/api/capture?access_key=%s&url=%s&viewport=%s&fullpage=%s&secret_key=%s', [EdtAccKey.Text, EdtURL.Text, EdtViewPort.Text, IsFullPage, SecretHash]); IdHTTP1.Get(Query, MS); MS.Seek(0, soFromBeginning); BM.LoadFromStream(MS); // load image from stream // show in control and save img1.Bitmap := BM; img1.Bitmap.SaveToFile('Snapshot.png'); finally FreeAndNil(MS); FreeAndNil(BM); end; end; |
Here is the result of calling the Screenshotlayer API
![screenshotlayerapiintegrationwithDelphiFiremonkey6268713 | Embarcadero RAD Studio Delphi C++Builder Blogs How To Capture Highly Customizable Website Snapshots screenshot app in action](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/07/screenshotlayer-api-integration-with-Delphi-Firemonkey-6268713.jpg?resize=438%2C708&ssl=1)
As you can see, it only takes a few short minutes to get a real, fully functional application with Delphi and the FireMonkey FMX Low Code Wizard.
Be sure to check out the full source code for this project: https://github.com/checkdigits/Capture_Web_Snapshots_Delphi_example
RAD Studio Delphi can make difficult tasks easier and with minimal code and effort from you. Why not download a trial copy today and see how fast you can turn your ideas into applications your users will love?
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition