Home Backend Development PHP Tutorial Automatically generate web page screenshots using the web page screenshot API interface

Automatically generate web page screenshots using the web page screenshot API interface

Sep 28, 2017 am 10:03 AM
api interface Automatic generated

Background

Recently I am developing a small program, which has a help module, the content is a list of help articles, and the article content is rich text edited by the website background Format. In view of the particularity of the applet, its support for rich text in HTML format is not friendly.

At first someone developed the wxparse plug-in, and later WeChat provided the rich-text component, but there were some problems with both.

Thoughts

After the article styles edited in the background are displayed through wxparse or richtext components, there are some compatibility issues. If we make the article content into a picture and then use the image to display it, we should be able to achieve a more ideal effect.

But for every article, it is time-consuming and laborious to go to the art area to design a picture, and it is also laborious to modify.

It would be perfect if the article we edited in the background could automatically generate a picture.

Plan

After querying, we found that the foreign website thumb.io provides a similar service. You can use the API interface to save the specified address as an image. However, after testing, it was found that the picture was not clear and the access speed was very slow. Then I installed phantomjs myself and tested it, and the effect was ideal.

Screenshot of Baidu homepage saved with phantomjs

In order to achieve automation, I also made a web api. Screenshots can be automatically generated (asynchronously) by sending the URL of the corresponding article to the specified API. The specific method is to save the request to the database when there is a screenshot request, then run a program on the server to perform screenshot operations one by one, and modify the status of the corresponding request after taking the screenshot.

----------------------------------------------- --------

API interface (the content in {} is the parameter value)

Usage: A screenshot will be required The URL is passed to the screenshot request interface. After a period of time (10 seconds is recommended), the query interface is queried. If the returned code=0, status=1, just save the thumbbush locally.

Generate screenshot request: http://thumb.loxn.cn/?url={URL}

Description: URL parameters must be specified urlencode, otherwise errors may occur

Example: http://thumb.loxn.cn/?url=http%3a%2f%2fwww.cnblogs.com%2fdragondean%2f

Return: JSON Format

     code  0 Success,    URL format error,                                              

#                                                                           ' The URL format

already exists

It is needed when querying the secret key (when the code is 0 or 2)

If it exists, this status will be returned. -1 means failure, 0 means processing, 1 means completed

     Thumb  Screenshot address, you can directly download this image to the local (when code is 2 and status is 1)

     err_msg Error message, only exists when status=-1

Query task status: http://thumb.loxn.cn/?a=query&task_id={TASK_ID} &key={KEY}

                             cessure in the task_id and key are returned when generating a request, required

                                        cessure in >> Task_id and key are returned when generating a request, required

EB8578633E5CB22377EE85641204494F

Return: json

# Code Return status, 0 success, 3 tasks do not exist, 4 query secrets

Status codes are 0, status = -1 means indicating Failed, status=0 means processing, status=1 means completed

  thumb When the code bit is 0 and status is 1, screenshot address, you can directly download this picture to the local

   err_msg Error Information, only exists when status=-1


---------------------------------- ------------------

###

The above is the detailed content of Automatically generate web page screenshots using the web page screenshot API interface. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the internal interfaces of a computer motherboard? Recommended introduction to the internal interfaces of a computer motherboard What are the internal interfaces of a computer motherboard? Recommended introduction to the internal interfaces of a computer motherboard Mar 12, 2024 pm 04:34 PM

When we assemble the computer, although the installation process is simple, we often encounter problems in the wiring. Often, users mistakenly plug the power supply line of the CPU radiator into the SYS_FAN. Although the fan can rotate, it may not work when the computer is turned on. There will be an F1 error "CPUFanError", which also causes the CPU cooler to be unable to adjust the speed intelligently. Let's share the common knowledge about the CPU_FAN, SYS_FAN, CHA_FAN, and CPU_OPT interfaces on the computer motherboard. Popular science on the CPU_FAN, SYS_FAN, CHA_FAN, and CPU_OPT interfaces on the computer motherboard 1. CPU_FANCPU_FAN is a dedicated interface for the CPU radiator and works at 12V

Common programming paradigms and design patterns in Go language Common programming paradigms and design patterns in Go language Mar 04, 2024 pm 06:06 PM

As a modern and efficient programming language, Go language has rich programming paradigms and design patterns that can help developers write high-quality, maintainable code. This article will introduce common programming paradigms and design patterns in the Go language and provide specific code examples. 1. Object-oriented programming In the Go language, you can use structures and methods to implement object-oriented programming. By defining a structure and binding methods to the structure, the object-oriented features of data encapsulation and behavior binding can be achieved. packagemaini

How to deal with Laravel API error problems How to deal with Laravel API error problems Mar 06, 2024 pm 05:18 PM

Title: How to deal with Laravel API error problems, specific code examples are needed. When developing Laravel, API errors are often encountered. These errors may come from various reasons such as program code logic errors, database query problems, or external API request failures. How to handle these error reports is a key issue. This article will use specific code examples to demonstrate how to effectively handle Laravel API error reports. 1. Error handling in Laravel

Introduction to PHP interfaces and how to define them Introduction to PHP interfaces and how to define them Mar 23, 2024 am 09:00 AM

Introduction to PHP interface and how it is defined. PHP is an open source scripting language widely used in Web development. It is flexible, simple, and powerful. In PHP, an interface is a tool that defines common methods between multiple classes, achieving polymorphism and making code more flexible and reusable. This article will introduce the concept of PHP interfaces and how to define them, and provide specific code examples to demonstrate their usage. 1. PHP interface concept Interface plays an important role in object-oriented programming, defining the class application

Oracle API Usage Guide: Exploring Data Interface Technology Oracle API Usage Guide: Exploring Data Interface Technology Mar 07, 2024 am 11:12 AM

Oracle is a world-renowned database management system provider, and its API (Application Programming Interface) is a powerful tool that helps developers easily interact and integrate with Oracle databases. In this article, we will delve into the Oracle API usage guide, show readers how to utilize data interface technology during the development process, and provide specific code examples. 1.Oracle

How to automatically generate directory page numbers for wps directory How to automatically generate directory page numbers for wps directory Feb 27, 2024 pm 04:01 PM

WPS is a powerful office software that can help us complete various office tasks efficiently. Among them, automatically generating table of contents page numbers is a very practical function. It can greatly improve the work efficiency of users, so the editor of this website will bring you this article to introduce in detail how to use WPS to automatically generate directory page numbers. I hope it can help everyone in need. How to automatically generate table of contents page numbers for a wps directory. First, open the wps group document, enter the content of the table of contents to be generated in the blank space, and then select the styles of title 1, title 2, and title 3 in the start menu bar. 2. Then after setting it up, we click the [Reference] function. After clicking, in the reference toolbar, here we click [Directory]; 3. Finally click

Oracle API integration strategy analysis: achieving seamless communication between systems Oracle API integration strategy analysis: achieving seamless communication between systems Mar 07, 2024 pm 10:09 PM

OracleAPI integration strategy analysis: To achieve seamless communication between systems, specific code examples are required. In today's digital era, internal enterprise systems need to communicate with each other and share data, and OracleAPI is one of the important tools to help achieve seamless communication between systems. This article will start with the basic concepts and principles of OracleAPI, explore API integration strategies, and finally give specific code examples to help readers better understand and apply OracleAPI. 1. Basic Oracle API

Solution to NotImplementedError() Solution to NotImplementedError() Mar 01, 2024 pm 03:10 PM

The reason for the error is in python. The reason why NotImplementedError() is thrown in Tornado may be because an abstract method or interface is not implemented. These methods or interfaces are declared in the parent class but not implemented in the child class. Subclasses need to implement these methods or interfaces to work properly. How to solve this problem is to implement the abstract method or interface declared by the parent class in the child class. If you are using a class to inherit from another class and you see this error, you should implement all the abstract methods declared in the parent class in the child class. If you are using an interface and you see this error, you should implement all methods declared in the interface in the class that implements the interface. If you are not sure which

See all articles