Webpage watermark generation method and device, electronic equipment and computer storage medium
By using the GLSL shader language to generate and draw watermarks in the browser-side GPU, and combining encryption and obfuscation technology, the problems of low watermark generation performance and easy to be cracked in the existing technology are solved, achieving efficient and secure watermark protection.
Patent Information
- Application Number
- CN202410880650.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-02
- Publication Date
- 2024-11-22
AI Technical Summary
The prior art has low performance in generating watermarks in web pages, and the generated watermarks are easily debugged and analyzed by crackers, making it difficult to effectively protect information security.
By loading the GLSL shader language, watermarks are generated and drawn in the GPU on the browser side, and encryption and obfuscation technologies are used to improve the difficulty of watermarks, ensuring that watermarks are efficiently generated and difficult to crack in web pages.
It improves the performance of watermark generation in web pages, significantly increases the difficulty of cracking watermarks, effectively protecting information security.
Smart Images

Figure CN119004416A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to a web page watermark generation method, device, electronic device and computer storage medium. Background Art
[0002] With the development of Internet technology, network information security is becoming more and more important. In order to protect information security and prevent web page information from being directly used, watermarks are usually added to web pages.
[0003] Currently, the main way to add dynamic watermarks to web pages is to generate them in memory through JavaScript or WebAssembly, and then render them to the canvas in real time. However, the process of generating watermarks in memory not only has low performance, but also the generated watermarks are easy to be debugged and analyzed by crackers.
[0004] Therefore, how to provide a webpage watermark generation method to improve the performance of generating watermarks in webpages and the difficulty of cracking watermarks is a problem that urgently needs to be solved. Summary of the invention
[0005] An embodiment of the present application provides a method for generating a webpage watermark, which improves the performance of generating a watermark in a webpage.
[0006] An embodiment of the present application provides a web page watermark generation method, comprising: in response to a request of a watermark script implanted in a web page of a browser, loading a GLSL shader language for drawing a watermark; generating a target watermark according to a preset watermark generation scheme; using the GLSL shader language to form a watermark drawing code for the target watermark; and providing a page generation code including the watermark drawing code to the browser.
[0007] Optionally, generating a target watermark according to a preset watermark generation scheme includes:
[0008] Generate a watermark ID for representing watermark content;
[0009] The watermark ID is encrypted to generate a target watermark.
[0010] Optionally, the performing encryption processing on the watermark ID to generate a target watermark includes:
[0011] An encryption scheme is randomly selected from a plurality of preset encryption schemes to perform encryption processing on the watermark ID, and an encrypted watermark ID is generated as a target watermark.
[0012] Optionally, the watermark drawing code for forming the target watermark by using the GLSL shader language includes:
[0013] Fill the encrypted watermark ID into the GLSL shader language template to generate the initial watermark drawing code;
[0014] The initial watermark drawing code is obfuscated to generate a target watermark drawing code as the watermark drawing code of the target watermark.
[0015] Optionally, also include:
[0016] Generate a canvas element creation code for instructing a web page on a browser side to create a canvas element corresponding to a canvas element for drawing the target watermark;
[0017] The canvas element creation code is provided to the browser side.
[0018] Optionally, also include:
[0019] Generates timing code for timing the drawing of canvas elements;
[0020] The time-related code is provided to the browser side.
[0021] Optionally, the target watermark includes a time correlation element obtained by performing time correlation processing on a time element provided by the time correlation code.
[0022] Optionally, the canvas element is set to be penetrable by mouse events.
[0023] Optionally, corresponding to the canvas element, an instruction for creating a WebGL environment in the canvas element is set, so that the GLSL shader language can run in the WebGL environment provided by the canvas element.
[0024] The present application also provides a method for generating a webpage watermark, including:
[0025] Send a watermark script request to the server to generate a watermark in the web page;
[0026] Obtaining a watermark drawing code formed according to the GLSL shader language and returned by the server;
[0027] A watermark is drawn according to the watermark drawing code.
[0028] Optionally, also include:
[0029] Get the canvas element creation code returned by the server;
[0030] Creating a canvas element in a webpage based on the canvas element creation code;
[0031] Make the canvas element transparent to mouse events.
[0032] Optionally, drawing a watermark according to the watermark drawing code includes:
[0033] A watermark is drawn in the canvas element according to the watermark drawing code.
[0034] Optionally, drawing a watermark in the canvas element according to a watermark drawing code includes:
[0035] Creating a WebGL environment in the canvas element according to an instruction to create a WebGL environment in the canvas element;
[0036] In the WebGL environment, the watermark drawing code is executed using the GLSL shader language to perform watermark drawing.
[0037] Optionally, also include:
[0038] Get the target watermark drawing code containing the time-related element and the canvas element containing the time-related code returned by the server;
[0039] When generating a canvas element based on the time-related code, the canvas element is generated at each relevant time point according to the preset time-related element;
[0040] When generating the canvas element, according to the time information provided by the time-related element, the target watermark drawing code of the time-related element is adopted to draw the target watermark including the time-related element on the canvas element.
[0041] Optionally, also include:
[0042] Obtaining the timestamp information of the current time, and adding the timestamp information to the watermark drawing code;
[0043] The GLSL shader language is used to encode the encrypted watermark ID and timestamp information into different semi-transparent pixels for display.
[0044] The embodiment of the present application also provides a web page watermark generation device, including: a GLSL shader language loading unit, which is used to load the GLSL shader language used to draw the watermark in response to a request of a watermark script implanted in a web page of a browser; a target watermark generation unit, which is used to generate a target watermark according to a preset watermark generation scheme; a watermark drawing code forming unit, which is used to use the GLSL shader language to form a watermark drawing code for the target watermark; and a page generation code providing unit, which is used to provide a page generation code containing the watermark drawing code to the browser.
[0045] An embodiment of the present application also provides a web page watermark generation device, including: a watermark script sending unit, used to send a watermark script request for generating a watermark in a web page to a server; a watermark drawing code obtaining unit, used to obtain a watermark drawing code formed according to the GLSL shader language and returned by the server; and a watermark drawing unit, used to draw a watermark according to the watermark drawing code.
[0046] An embodiment of the present application further provides an electronic device, comprising a processor and a memory; a computer program is stored in the memory, and after the processor runs the computer program, any one of the methods described above is executed.
[0047] An embodiment of the present application further provides a computer storage medium, wherein the computer storage medium stores a computer program, and after the computer program is run by a processor, any one of the methods described above is executed.
[0048] Compared with the prior art, the embodiments of the present application have the following advantages:
[0049] An embodiment of the present application provides a web page watermark generation method, comprising: in response to a request of a watermark script implanted in a web page of a browser, loading a GLSL shader language for drawing a watermark; generating a target watermark according to a preset watermark generation scheme; using the GLSL shader language to form a watermark drawing code for the target watermark; and providing a page generation code including the watermark drawing code to the browser.
[0050] The webpage watermark generation method described in the embodiment of the present application, in response to the request of the watermark script embedded in the webpage of the browser, loads the GLSL shader language for drawing the watermark, forms the watermark drawing code of the target watermark by using the GLSL shader language, and provides the page generation code containing the watermark drawing code to the browser. Therefore, the webpage watermark generation method improves the performance of generating watermarks in webpages by running the watermark drawing process in the GPU.
[0051] In the preferred embodiment of the present application, an encryption scheme is randomly selected from a plurality of preset encryption schemes to perform encryption processing on the watermark ID, generate an encrypted watermark ID, fill the encrypted watermark ID into the GLSL shader language template, and confuse the watermark drawing code, thereby generating the watermark drawing code of the target watermark. Therefore, the webpage watermark generation method increases the difficulty of cracking the watermark. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] Figure 1 It is a scenario diagram of the webpage watermark generation method provided by this application;
[0053] Figure 2is a flow chart of a webpage watermark generation method provided by the first embodiment of the present application;
[0054] Figure 3 is a flow chart of a webpage watermark generation method provided by the second embodiment of the present application;
[0055] Figure 4 is a schematic diagram of a webpage watermark generating device provided in the third embodiment of the present application;
[0056] Figure 5 is a schematic diagram of a webpage watermark generating device provided in a fourth embodiment of the present application;
[0057] Figure 6 This is a schematic diagram of an electronic device provided in the fifth embodiment of the present application. DETAILED DESCRIPTION
[0058] Many specific details are described in the following description to facilitate a full understanding of the present application. However, the present application can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the connotation of the present application, so the present application is not limited by the specific implementation disclosed below.
[0059] First of all, in order to enable those skilled in the art to better understand the solution of the present application, the following describes in detail the background technology and scenarios of an embodiment of a method for generating a webpage watermark provided by the present application.
[0060] First, a brief explanation of the terms involved in this application is given.
[0061] GPU (Graphics Processing Unit), also known as display core, visual processor, and display chip.
[0062] GLSL (OpenGL Shading Language) is a high-level shading language based on C language. GLSL shader language is part of WebGL and is used to write vertex shader and fragment shader code. These shader codes are loaded and executed by the WebGL API and play a role in the graphics rendering process. GLSL is a programming language specifically for graphics rendering, which has features and syntax compatible with graphics hardware.
[0063] WebGL (Web Graphics Library) is a JavaScript API for rendering interactive 2D and 3D graphics in any compatible web browser without using plugins. WebGL provides the ability to interact with graphics hardware for high-performance graphics rendering in web browsers. WebGL is a subset of the OpenGL ES (OpenGL for Embedded Systems) standard that uses OpenGL Shading Language (GLSL) as a shader language.
[0064] In fact, WebGL itself is not a programming language, but an API for graphics rendering in web browsers. It allows developers to use JavaScript to call WebGL API functions to create and control graphics rendering pipelines and interact with graphics hardware. WebGL provides a series of functions and methods for creating and managing graphics rendering-related objects such as shader programs, vertex buffers, textures, and performing graphics rendering and calculations through these objects.
[0065] Therefore, WebGL is an API for graphics rendering in web browsers that uses the OpenGL ES standard and provides functions for interacting with graphics hardware. GLSL is the shader language used in WebGL and is used to write vertex shader and fragment shader code. JavaScript is the programming language used to call WebGL API functions.
[0066] JavaScript is a high-level, interpreted programming language that is widely used in web development. It is a dynamic language that can run in both client-side (browser) and server-side (Node.js) environments. JavaScript was originally created to enable interactive and dynamic effects on web pages. It can be directly embedded in HTML (HyperText Markup Language) pages and interpreted and executed by the browser. Over time, JavaScript has developed into a powerful programming language with a wide range of applications.
[0067] Web Watermarking is a technology used to embed invisible identification information on web pages to identify and protect the copyright and source of web page content. Unlike traditional visible watermarks, web watermarks are hidden in web pages without affecting the user experience, usually by modifying the code or images of the web page. The dark watermark cannot be seen by humans, but can be extracted through corresponding tools.
[0068] A timestamp is usually a sequence of characters that uniquely identifies a moment in time.
[0069] Currently, JavaScript and WebAssembly can be used to generate webpage dark watermarks, but their implementation methods and uses are different. The process of generating webpage dark watermarks with JavaScript is as follows: Using JavaScript, webpage dark watermarks can be implemented in the client of the webpage (i.e., the user's browser). This usually involves modifying the HTML, CSS (Cascading Style Sheets), or JavaScript code of the webpage to embed hidden identification information. For example, dark watermarks can be implemented by modifying the attributes of webpage elements, adding specific comments or tags, or embedding hidden text in the webpage. When a webpage is copied or stolen, the original source can be identified by extracting and comparing these hidden information. The process of generating webpage dark watermarks with WebAssembly is as follows: WebAssembly is a low-level programming language that can run high-performance binary code in webpages. By using WebAssembly, more complex algorithms and processing logic can be moved to the client of the webpage to generate more powerful webpage dark watermarks. WebAssembly can be written in languages such as C / C++ and then compiled into an efficient binary format for execution in a browser. This approach can provide higher performance and more complex watermark algorithms, but it also requires higher technical requirements and development costs.
[0070] The above-mentioned method of adding dynamic watermarks to web pages is mainly to generate them in memory through JavaScript or WebAssembly, and then render them to the canvas in real time. However, the process of generating watermarks in memory not only has low performance, but also the generated watermarks are easy to be debugged and analyzed by crackers.
[0071] Based on this, the embodiment of the present application provides a webpage watermark generation method, which uses WebGL to realize watermark production, and runs the watermark drawing process in the GPU. Specifically, in response to the request of the watermark script implanted in the webpage of the browser, by loading the GLSL shader language for drawing the watermark, the watermark drawing code of the target watermark is formed by using the GLSL shader language, and the page generation code containing the watermark drawing code is provided to the browser. Therefore, in the webpage watermark generation method, the performance of generating watermarks in webpages is improved by running the watermark drawing process in the GPU. In addition, the method randomly selects an encryption scheme from a plurality of preset encryption schemes to perform encryption processing on the watermark ID, generates an encrypted watermark ID, fills the encrypted watermark ID into the GLSL shader language template, and confuses the watermark drawing code, thereby generating the watermark drawing code of the target watermark. Therefore, the webpage watermark generation method increases the difficulty of cracking the watermark.
[0072] The above is the implementation background of this application scheme. Figure 1 The scenario of the web page generation method provided by this application is introduced.
[0073] See also Figure 1 , Figure 1 It is a scene diagram of the webpage watermark generation method provided by the present application. First, the browser side executes step S101: sends a watermark script request for generating a watermark in a webpage to the server side; then, the server side executes step S102: in response to the request of the watermark script in the webpage implanted in the browser side, loads the GLSL shader language for drawing the watermark; generates a target watermark according to a preset watermark generation scheme; and forms a watermark drawing code for the target watermark using the GLSL shader language. Among them, when generating the target watermark, firstly, a watermark ID for representing the watermark content is generated, and then an encryption scheme is randomly selected from a plurality of preset encryption schemes to perform encryption processing on the watermark ID, and an encrypted watermark ID is generated as the target watermark. When the watermark drawing code for the target watermark is formed using the GLSL shader language, the encrypted watermark ID is filled into the GLSL shader language template to generate an initial watermark drawing code; the initial watermark drawing code is obfuscated to generate a target watermark drawing code as the watermark drawing code for the target watermark. It should be noted that, through obfuscation, the code logic related to the watermark can be mixed with other codes, making it difficult for people who try to remove the watermark to find the specific location and implementation method of the watermark, increasing the difficulty for illegal users to identify and tamper with the watermark. After the server generates the watermark drawing code of the target watermark, it will provide the watermark drawing code to the browser. Step S103: The browser obtains the watermark drawing code formed according to the GLSL shader language returned by the server, and the browser draws the watermark after obtaining the watermark drawing code.
[0074] During the specific implementation, when the browser draws the watermark according to the watermark drawing code, it is also necessary to create a canvas element. Therefore, the server needs to generate a canvas element creation code. The server executes step S104: generates a canvas element creation code corresponding to the canvas element used to draw the target watermark on the web page of the browser; provides the canvas element creation code to the browser; the browser executes step S105: obtains the canvas element creation code returned by the server; creates a canvas element in the web page based on the canvas element creation code; sets the canvas element to be penetrable by mouse events. Setting the canvas element to be penetrable by mouse events means that when the user clicks the mouse in the canvas element area, the event will not be intercepted by the canvas, but will penetrate to the bottom of the canvas, thereby not affecting the normal interaction of the web page service.
[0075] When the browser draws the watermark in the canvas element according to the watermark drawing code, it needs to create a WebGL environment in the canvas element. Therefore, the server needs to generate an instruction to create the WebGL environment in the canvas element. The server executes step S106: corresponding to the canvas element, the instruction to create the WebGL environment in the canvas element is set, so that the GLSL shader language can run in the WebGL environment provided by the canvas element; the browser executes step S107: obtains the instruction to create the WebGL environment provided by the server; the browser executes step S108: according to the instruction to create the WebGL environment in the canvas element, the WebGL environment is created in the canvas element; in the WebGL environment, the watermark drawing code is executed using the GLSL shader language to draw the watermark.
[0076] In actual applications, the server can also generate a time-related code for timing the drawing of canvas elements; provide the time-related code to the browser; after the browser obtains the target watermark drawing code containing the time-related element and the canvas element containing the time-related code returned by the server, the canvas element is generated based on the time-related code, according to the preset time-related element, at each relevant time point; when generating the canvas element, according to the time information provided by the time-related element, the target watermark drawing code of the time-related element is used to draw the target watermark containing the time-related element on the canvas element. Among them, the time-related element can be specifically a timestamp. In specific implementation, a timer can be turned on the browser page, and the canvas element is drawn once every period of time. Before drawing, the timestamp information can be passed into the WebGL environment, and the watermark drawing code is executed on the canvas element using the GLSL shader language, so as to draw the target watermark containing the timestamp on the canvas element. Of course, the GLSL shader language can also be used to encode the encrypted watermark ID and timestamp information, and encode them into different semi-transparent pixels for display on the canvas.
[0077] The above is an introduction to the summary process of a web page watermark generation method provided by this application. This method improves the performance of generating watermarks on web pages by loading the GLSL shader language used to draw watermarks and using the GLSL shader language to form the watermark drawing code of the target watermark. At the same time, by obfuscating the watermark drawing code, the difficulty of cracking the watermark is increased.
[0078] The present application is described below through a number of embodiments and drawings.
[0079] First embodiment
[0080] The first embodiment of the present application provides a webpage watermark generation method, which is applied to a server. Figure 2 The web page watermark generation method is described in detail.
[0081] Step S201: In response to a request from a watermark script embedded in a web page on a browser side, a GLSL shader language for drawing a watermark is loaded.
[0082] This step is used by the server to load the GLSL shader language used to draw the watermark.
[0083] In specific implementation, the browser sends a watermark script request for generating a watermark in a web page to the server, and the server loads the GLSL shader language for drawing the watermark in response to the request for the watermark script embedded in the web page of the browser.
[0084] The code for the browser to send a watermark script request to the server to generate a watermark in the web page is as follows:
[0085] var res=await fetch(SERVER_URL)
[0086] var glsl_code=await res.text()
[0087] GLSL shader language is part of WebGL and is used to write vertex shader and fragment shader code. These shader codes are loaded and executed by the WebGL API. WebGL is a JavaScript API based on the OpenGL ES2.0 standard that allows hardware-accelerated 3D graphics rendering in web browsers through the HTML5 canvas element without any plug-ins. WebGL enables browsers to directly access the user's graphics processor (GPU), thereby creating and displaying complex 3D graphics and animations on web pages. The working principle of WebGL is to use the powerful computing power of the GPU to process graphics data, decompose complex three-dimensional scenes into pixels, and draw them on the screen. It exposes a set of low-level drawing instructions similar to OpenGL ES through a JavaScript interface, allowing developers to directly operate different stages of the rendering pipeline, such as vertex shaders, fragment shaders, etc., to achieve highly customized visual effects.
[0088] In an embodiment of the present application, a watermark drawing process is implemented in a WebGL environment by loading the GLSL shader language. The watermark drawing process runs directly in the GPU, which makes the performance of generating watermarks in web pages higher and more difficult to debug. In specific implementations, the watermark may refer to a dark watermark, which is an invisible digital watermark technology that can embed identification information into digital media without affecting the quality and content of the media itself. Unlike visible watermarks, dark watermarks cannot be seen by people, but can be extracted through corresponding tools. By adding dark watermarks to web pages, it is possible to effectively prevent web page information from being directly used, thereby improving the security of the information.
[0089] Step S202: Generate a target watermark according to a preset watermark generation scheme.
[0090] This step is used to generate a target watermark, which is the style of the watermark actually drawn on the web page.
[0091] Generating the target watermark according to the preset watermark generation scheme includes: generating a watermark ID for representing the watermark content; performing encryption processing on the watermark ID to generate the target watermark. Performing encryption processing on the watermark ID to generate the target watermark includes: randomly selecting an encryption scheme from a plurality of preset encryption schemes to perform encryption processing on the watermark ID to generate the encrypted watermark ID as the target watermark.
[0092] The code for encrypting the watermark ID is as follows:
[0093] WATERMARK_ID=SESSION_ID
[0094] In the specific implementation, the server generates the specific content of the watermark, that is, the target watermark. For each web page, the generated target watermark is different and has its own special identification, so as to conveniently determine the source of the watermark; therefore, each target watermark has a watermark ID that marks its uniqueness, and accordingly, the watermark ID can be used to refer to the specific target watermark; generally, the watermark ID itself can be generated in a predetermined manner according to the employee ID, session ID or the ID value provided by the web page service provider on the browser side. For example, the watermark ID related to the target watermark is generated by concatenating the employee ID + session ID + web page service provider ID. On this basis, a specific target watermark can be generated, that is, the corresponding target watermark is generated in a predetermined manner according to the watermark ID, and the target watermark contains the watermark ID in an explicit or implicit manner. In the process of generating the target watermark, the server can encrypt the watermark ID contained in the target watermark, and the encryption method includes deforming the watermark ID. When encrypting the watermark ID, the server pre-stores several sets of specific encryption schemes, and the server can randomly select an encryption scheme from the preset multiple encryption schemes to perform encryption processing on the watermark ID. For example, the server can use a key to encrypt the session ID as follows:
[0095] WATERMARK_ID=SESSION_ID^SECRET_KEY
[0096] / / Use the key to encrypt the session ID
[0097] Step S203: using the GLSL shader language to form a watermark drawing code for the target watermark.
[0098] This step is used to form a watermark drawing code for the target watermark. After the watermark drawing code is formed, the server provides the watermark drawing code to the browser so that the browser draws the watermark according to the watermark drawing code.
[0099] The watermark drawing code of the target watermark is formed by using the GLSL shader language, including: filling the encrypted watermark ID into the GLSL shader language template to generate an initial watermark drawing code; obfuscating the initial watermark drawing code to generate a target watermark drawing code as the watermark drawing code of the target watermark.
[0100] In specific implementation, after encrypting the watermark ID, the generated encrypted watermark ID is filled into the GLSL shader language template to generate the initial watermark drawing code, and then the initial watermark drawing code is obfuscated. For example, during obfuscation, computer instructions can be replaced with logically equivalent but more computationally complex operations. Since the obfuscation process is random, the GLSL shader language obtained by the user is different each time, which can interfere with the debugger's analysis.
[0101] It should be noted that obfuscation is a way to protect the code. In the scenario of adding watermarks, code obfuscation is a strategy to enhance software protection and trace illegal distribution. By taking obfuscation measures, the code logic related to the watermark can be mixed with other codes, making it difficult for people who try to remove the watermark to find the specific location and implementation of the watermark, increasing the difficulty for illegal users to identify and tamper with the watermark. Obfuscation can also be used as legal evidence. If the software is pirated or illegally distributed, obfuscation and watermarking can be used together as legal evidence. Obfuscation ensures that the watermark is not easy to remove even if it is discovered, retaining the ability to track the source of infringement.
[0102] Step S204: providing the page generation code including the watermark drawing code to the browser.
[0103] This step is used to provide the page generation code containing the watermark drawing code to the browser side, so that the browser side generates a web page containing the target watermark based on the page generation code.
[0104] In the specific implementation, when the browser side draws the watermark according to the watermark drawing code, it is also necessary to create a canvas element, so the server side needs to generate a canvas element creation code. Specifically, the server side generates a canvas element creation code for instructing the web page on the browser side to create a canvas element corresponding to the canvas element for drawing the target watermark; and provides the canvas element creation code to the browser side.
[0105] The canvas element (i.e., the canvas element) is an important feature introduced by HTML5. It provides a way to dynamically draw graphics on a web page. By using JavaScript in conjunction with the canvas element, developers can create graphics, draw pictures, and achieve animation effects directly on the web page without relying on external plug-ins such as Flash. When drawing graphics on the canvas, you need to use JavaScript to operate the canvas's 2D rendering context or WebGL's 3D rendering context. For more complex graphics, animations, or 3D graphics, you can use WebGL. WebGL is a JavaScript API based on OpenGL ES, designed for high-performance 3D and 2D graphics, and can achieve hardware-accelerated rendering on the canvas element. Whether using a 2D context or a WebGL context, the canvas element provides a rich API to meet various graphics drawing needs, including but not limited to straight lines, curves, circles, ellipses, text, image processing, etc. Through these APIs, developers can create rich and diverse visual content and interactive applications.
[0106] In the embodiment of the present application, corresponding to the canvas element, the server sets an instruction for creating a WebGL environment in the canvas element, so that the GLSL shader language can run in the WebGL environment provided by the canvas element. After the instruction for creating the WebGL environment in the canvas element is set, the server provides the instruction for creating the WebGL environment to the browser, so that the browser creates a WebGL environment in the canvas element according to the instruction for creating the WebGL environment in the canvas element; then, in the WebGL environment, the watermark drawing code is executed using the GLSL shader language to draw the watermark.
[0107] It should be noted that in Web development, if you want mouse events (such as clicks, hovers, etc.) to penetrate an element and trigger corresponding events of the elements below it, you can use the pointer-events attribute of CSS. By setting this attribute to none, a specific element can be made transparent to mouse events, thereby allowing these events to be passed to the layers below. In an embodiment of the present application, the canvas element is set to be penetrable by mouse events. After the canvas element is set to be penetrable by mouse events, when the user clicks the mouse in the canvas element area, the event will not be intercepted by the canvas, but will penetrate to the bottom of the canvas, thereby not affecting the normal interaction of the web service.
[0108] In specific implementation, a timer can also be set on the web page of the browser side to draw the canvas every certain period of time, so that the canvas content can be updated periodically. Therefore, the server side needs to generate a time-related code for timing the drawing of canvas elements; the time-related code is provided to the browser side, so that the browser side can time-draw the canvas. In an embodiment of the present application, the target watermark includes a time-related element after time-related processing according to the time element provided by the time-related code. Among them, the time-related element can specifically be a timestamp, that is, the target watermark is a watermark containing a timestamp. The purpose of adding a timestamp to the watermark is to encode the time information into the watermark. In the future, when the watermark is decoded, in addition to knowing the watermark ID, it can also be known when the screenshot of the picture was generated.
[0109] The above is the whole process of the webpage watermark generation method. The method uses WebGL to realize watermark production and runs the watermark drawing process in the GPU. Specifically, in response to the request of the watermark script in the webpage implanted in the browser, the GLSL shader language for drawing the watermark is loaded, and the watermark drawing code of the target watermark is formed by using the GLSL shader language, and the page generation code containing the watermark drawing code is provided to the browser. Therefore, the webpage watermark generation method improves the performance of generating watermarks in webpages by running the watermark drawing process in the GPU. In addition, the method randomly selects an encryption scheme from a plurality of preset encryption schemes to perform encryption processing on the watermark ID, generates an encrypted watermark ID, fills the encrypted watermark ID into the GLSL shader language template, and confuses the watermark drawing code, thereby generating the watermark drawing code of the target watermark. Therefore, the webpage watermark generation method increases the difficulty of cracking the watermark.
[0110] Second embodiment
[0111] In the above first embodiment, a webpage watermark generation method is provided, and the method is applied to the server side. Correspondingly, the second embodiment of the present application provides a webpage watermark generation method, and the method is applied to the browser side. The parts of this embodiment that are the same as the first embodiment are not repeated here, and please refer to the corresponding parts in the first embodiment.
[0112] Step S301: Sending a watermark script request for generating a watermark in a web page to a server.
[0113] This step is used by the browser to send a watermark script request to the server to generate a watermark in the web page of the browser. The script is usually in the HTML code of the web page through <script>标签将JavaScript代码嵌入到网页中;脚本作为一种编程语言(例如JavaScript)形成的代码,可以在浏览器打开页面时执行。使用脚本可以实现网页的交互性和动态性,使网页能够对用户的操作做出响应,并实现各种功能。本步骤的水印脚本,即一段关于请求生成水印的脚本代码,该代码嵌入具体的网页,在浏览器端向服务器请求提供网页内容时,同时发出生成水印的请求。在网页的水印脚本中,可以根据对水印的样式、位置和内容进行一定的规定,可以设置水印的透明度、大小和旋转角度等属性。许多情况下水印脚本可以在客户端执行,但本申请提供的方案中,水印脚本主要是提供生成水印的请求,其中可以包含形成水印ID的相关信息,例如,客户ID、网页ID等;也可以包含影响目标水印的具体内容的信息,但最终而言,目标水印是由服务端提供的GLSL着色器语言形成的水印绘制代码,具体在上一个实施例中已经说明。
[0114] 步骤S302:获得所述服务端返回的根据GLSL着色器语言形成的水印绘制代码。
[0115] 本步骤用于浏览器端获得服务端返回的根据GLSL着色器语言形成的水印绘制代码;这些代码是包含在服务端返回的网页代码中的。
[0116] 步骤S303:根据所述水印绘制代码绘制水印。
[0117] 本步骤用于浏览器端根据服务端提供的水印绘制代码绘制水印。
[0118] 需要说明的是,服务端根据GLSL着色器语言形成水印绘制代码时,首先是从预设的多种加密方案中随机选取一种加密方案对水印ID执行加密处理,然后,将加密后的水印ID填充到GLSL着色器语言模板中,生成初始水印绘制代码,最后,对初始水印绘制代码进行混淆,生成目标水印绘制代码,浏览器端便是根据该目标水印绘制代码绘制水印。通过对水印ID进行加密以及对GLSL着色器语言进行混淆,提升了水印的破解难度。
[0119] 具体实施时,浏览器端还需要创建画布元素,具体为,获得服务端返回的网页代码中的画布元素创建代码;基于所述画布元素创建代码在网页中创建画布元素;将所述画布元素设置为鼠标事件可穿透。创建画布元素后,将其覆盖到需要添加水印的区域,并将该画布元素设置成鼠标事件可穿透。将画布元素设置为鼠标事件可穿透之后,用户在该画布元素区域点击鼠标时事件不会被画布拦截,而是穿透到画布的下方,从而不影响网页服务的正常交互。
[0120] 其中,浏览器端创建画布元素的创建代码以及将画布元素设置为鼠标事件可穿透过程的代码如下:
[0121] var canvasElement=document.createElement(‘canvas’)
[0122] canvasElement.style.pointerEvents=‘none’
[0123] 本申请实施例中,所述根据所述水印绘制代码绘制水印,包括:在所述画布元素中根据水印绘制代码绘制水印。所述在所述画布元素中根据水印绘制代码绘制水印,包括:根据在所述画布元素创建WebGL环境的指令,在所述画布元素中创建WebGL环境;在所述WebGL环境,使用所述GLSL着色器语言执行所述水印绘制代码进行水印绘制。
[0124] 需要说明的是,浏览器端根据水印绘制代码绘制水印时,具体是在画布元素中根据水印绘制代码绘制水印。具体实施时,首先,浏览器端会获得服务端提供的创建WebGL环境的指令,然后,根据服务端提供的在画布元素创建WebGL环境的指令,在画布元素中创建WebGL环境,在WebGL环境中,使用GLSL着色器语言执行水印绘制代码进行水印绘制。
[0125] 其中,在画布元素创建WebGL环境,并将获取到的GLSL语言编译和运行的代码过程如下:
[0126] var gl=canvasElement.getContext(‘webgl’)
[0127] initShader(gl,glsl)
[0128] linkProgram(gl)
[0129] bindBuffer(gl)
[0130] uniform4uiv(gl,input_params)
[0131] draw(gl)
[0132] GLSL着色器语言是WebGL中的一部分,用于编写顶点着色器和片段着色器的代码。这些着色器代码由WebGL API加载和执行。WebGL是一种基于OpenGL ES2.0标准的JavaScript API,它允许在无需任何插件的情况下,通过HTML5的canvas元素在网页浏览器中进行硬件加速的3D图形渲染。WebGL使得浏览器能够直接访问用户的图形处理器(GPU),从而实现在网页上创建和显示复杂的3D图形和动画。因此,通过在画布元素中创建WebGL环境,在WebGL环境中实现水印绘制过程,该水印绘制过程直接在GPU中运行,使得在网页中生成水印的性能更高,并且调试更困难。
[0133] 本申请实施例中,浏览器端还会获取服务端返回的包含时间相关性元素的目标水印绘制代码以及包含时间相关代码的画布元素;基于所述时间相关代码在生成画布元素时,按照预设的时间相关元素,在各个相关时间点生成所述画布元素;在生成所述画布元素时,根据所述时间相关元素提供的时间信息,采用所述时间相关性元素的目标水印绘制代码,在所述画布元素上绘制包含时间相关性元素的目标水印。
[0134] 具体实施时,还可以在浏览器端的网页上设置定时器,每隔一段时间绘制一次画布,从而可以周期性更新画布内容。时间相关性元素具体可以是时间戳,该目标水印是包含时间戳的水印。时间戳是一种表示时间的方式,它是一个从特定时间点(通常是1970年1月1日00:00:00UTC)以来经过的秒(或毫秒)数。这种计时方法被广泛应用于计算机系统、数据库和编程语言中,因为它便于计算和比较时间。在本申请实施例中,还可以将当前时间戳传入WebGL环境中,传入时间戳是为了能将时间信息编码到水印中,将来对水印进行解码时除了能获知水印ID外,还能获知是图片是何时截图产生的。需要说明的是,除了在绘制前将当前时间戳传入WebGL环境中之外,还可以将画布已绘制的次数传入WebGL环境中,画布执行绘制的次数可以通过定时器传入。传入已执行的次数,是为了每次渲染的水印图像不固定,GLSL着色器语言可根据当前次数值,执行不同的绘制逻辑。
[0135] 在本申请实施例中,还可以获取当前时间的时间戳信息,将所述时间戳信息加入所述水印绘制代码;采用所述GLSL着色器语言将加密后的水印ID以及时间戳信息编码成不同的半透明像素进行显示。
[0136] 半透明像素是指在数字图像中,某个像素的颜色值除了包含红色、绿色、蓝色三个颜色通道之外,还包括一个代表透明度的通道,通常称为Alpha通道。这个Alpha通道的取值范围通常是0到1之间,表示从完全透明(0)到完全不透明(1)的渐变程度。当一个像素的Alpha值小于1时,该像素就是半透明像素。
[0137] 下面展示了GLSL着色器语言将加密后的水印ID编码成不同的半透明像素的过程:
[0138] / / 水印ID
[0139] const int ID=1234567;
[0140] / / 当前像素点的X坐标
[0141] in float pos_x;
[0142] / / 当前像素点的Y坐标
[0143] in float pos_y;
[0144] / / 输出颜色
[0145] out vec4 outColor;
[0146] void main(){
[0147] / / 根据当前坐标,截取ID中相应的bit位,例如:
[0148] / / 第1个坐标对应ID第1个bit位,第31个坐标,对应第31个bit位,
[0149] / / 依次循环,第32个坐标对应第1个bit位。
[0150] int bit=ID&(1<<(pos_x%32));
[0151] / / 如果bit位为1则完全透明,如果为0则稍不透明(例如99%透明)
[0152] float transparent=bit?0:0.01;
[0153] / / 输出当前坐标点的颜色
[0154] outColor=vec4(1.,1.,1.,transparent);
[0155] }
[0156] 具体实施时,可以采用GLSL着色器语言对加密后的水印ID以及时间戳信息进行编码,将其编码成不同的半透明像素在画布上进行显示。用户对水印区域截图时,由于受到画布半透明像素的影响,实际获取的图像和原始图片会有一定的偏差。通过该偏差值结合预定算法,可解码出水印ID、时间戳信息。
[0157] 以上便是网页水印生成方法的整体过程,该方法中水印绘制代码是利用GLSL着色器语言形成的,提升了在网页中生成水印的性能,同时,目标水印是经过混淆后的水印绘制代码绘制的,提升了水印的破解难度。当然,目前除了WebGL API,在部分最新的浏览器中还可使用WebGPU API实现GPU层面的水印绘制,并且性能更高。
[0158] 第三实施例
[0159] 在上述第一实施例中,提供了一种网页水印生成方法,与之相对应的,本申请第三实施例提供了一种网页水印生成装置,应用于服务端。由于装置实施例基本相似于方法第一实施例,所以描述得比较简单,相关之处参见方法实施例的部分说明即可。下述描述的装置实施例仅仅是示意性的。
[0160] 请参照图4,为本申请第三实施例提供的一种网页水印生成装置的示意图。
[0161] 该网页水印生成装置400包括:
[0162] GLSL着色器语言加载单元401,用于响应于植入浏览器端的网页中的水印脚本的请求,加载用于绘制水印的GLSL着色器语言;
[0163] 目标水印生成单元402,用于根据预先设置的水印生成方案,生成目标水印;
[0164] 水印绘制代码形成单元403,用于采用所述GLSL着色器语言形成所述目标水印的水印绘制代码;
[0165] 页面生成代码提供单元404,用于将包含所述水印绘制代码的页面生成代码提供给浏览器端。
[0166] 可选的,所述目标水印生成单元402,具体用于生成用于表示水印内容的水印ID;
[0167] 对所述水印ID执行加密处理,生成目标水印。
[0168] 可选的,所述对所述水印ID执行加密处理,生成目标水印,包括:
[0169] 从预设的多种加密方案中随机选取一种加密方案对所述水印ID执行加密处理,生成加密后的水印ID,作为目标水印。
[0170] 可选的,所述水印绘制代码形成单元403,具体用于将加密后的水印ID填充到GLSL着色器语言模板中,生成初始水印绘制代码;
[0171] 对所述初始水印绘制代码进行混淆,生成目标水印绘制代码,作为所述目标水印的水印绘制代码。
[0172] 可选的,还包括:画布元素创建代码生成单元;
[0173] 所述画布元素创建代码生成单元,用于生成用于指示浏览器端的网页创建用于绘制所述目标水印的画布元素对应的画布元素创建代码;
[0174] 将所述画布元素创建代码提供给浏览器端。
[0175] 可选的,还包括:时间相关代码生成单元;
[0176] 所述时间相关代码生成单元,用于生成用于定时绘制画布元素的时间相关代码;
[0177] 将所述时间相关代码提供给浏览器端。
[0178] 可选的,所述目标水印,包括根据所述时间相关代码提供的时间元素进行时间相关性处理后的时间相关性元素。
[0179] 可选的,所述画布元素设置为鼠标事件可穿透。
[0180] 可选的,还包括:创建WebGL环境的指令生成单元;
[0181] 所述创建WebGL环境的指令生成单元,用于对应所述画布元素,设置在所述画布元素创建WebGL环境的指令,使所述GLSL着色器语言能够在所述画布元素提供的WebGL环境中运行。
[0182] 第四实施例
[0183] 在上述第二实施例中,提供了一种网页水印生成方法,与之相对应的,本申请第四实施例提供了一种网页水印生成装置,应用于浏览器端。由于装置实施例基本相似于方法第二实施例,所以描述得比较简单,相关之处参见方法实施例的部分说明即可。下述描述的装置实施例仅仅是示意性的。
[0184] 请参照图5,为本申请第四实施例提供的一种网页水印生成装置的示意图。
[0185] 该网页水印生成装置500包括:
[0186] 水印脚本发送单元501,用于向服务端发送在网页中生成水印的水印脚本请求;
[0187] 水印绘制代码获得单元502,用于获得所述服务端返回的根据GLSL着色器语言形成的水印绘制代码;
[0188] 水印绘制单元503,用于根据所述水印绘制代码绘制水印。
[0189] 可选的,还包括:画布元素创建代码获得单元;
[0190] 所述画布元素创建代码获得单元,用于获得服务端返回的画布元素创建代码;
[0191] 基于所述画布元素创建代码在网页中创建画布元素;
[0192] 将所述画布元素设置为鼠标事件可穿透。
[0193] 可选的,所述水印绘制单元503,具体用于在所述画布元素中根据水印绘制代码绘制水印。
[0194] 可选的,所述在所述画布元素中根据水印绘制代码绘制水印,包括:
[0195] 根据在所述画布元素创建WebGL环境的指令,在所述画布元素中创建WebGL环境;
[0196] 在所述WebGL环境,使用所述GLSL着色器语言执行所述水印绘制代码进行水印绘制。
[0197] 可选的,还包括:包含时间相关性元素的目标水印绘制单元;
[0198] 所述包含时间相关性元素的目标水印绘制单元,用于获取服务端返回的包含时间相关性元素的目标水印绘制代码以及包含时间相关代码的画布元素;
[0199] 基于所述时间相关代码在生成画布元素时,按照预设的时间相关元素,在各个相关时间点生成所述画布元素;
[0200] 在生成所述画布元素时,根据所述时间相关元素提供的时间信息,采用所述时间相关性元素的目标水印绘制代码,在所述画布元素上绘制包含时间相关性元素的目标水印。
[0201] 可选的,还包括:编码单元;
[0202] 所述编码单元,用于获取当前时间的时间戳信息,将所述时间戳信息加入所述水印绘制代码;
[0203] 采用所述GLSL着色器语言将加密后的水印ID以及时间戳信息编码成不同的半透明像素进行显示。
[0204] 第五实施例
[0205] 与本申请上述方法实施例相对应的,本申请第五实施例还提供一种电子设备。如图6所示,图6为本申请第五实施例中提供的一种电子设备的示意图。该电子设备,包括:至少一个处理器601,至少一个通信接口602,至少一个存储器603和至少一个通信总线604;可选的,通信接口602可以为通信模块的接口,如GSM模块的接口;处理器601可能是处理器CPU,或者是特定集成电路ASIC(Application Specific Integrated Circuit),或者是被配置成实施本发明实施例的一个或多个集成电路。存储器603可能包含高速RAM存储器,也可能还包括非易失性存储器(non-volatile memory),例如至少一个磁盘存储器。其中,存储器603存储有程序,处理器601调用存储器603所存储的程序,以执行本申请上述实施例中提供的方法。
[0206] 第六实施例
[0207] 与本申请上述方法相对应的,本申请第六实施例还提供一种计算机存储介质。所述计算机存储介质存储有计算机程序,该计算机程序被处理器运行,以执行本申请上述实施例中提供的方法。
[0208] 本申请虽然以较佳实施例公开如上,但其并不是用来限定本申请,任何本领域技术人员在不脱离本申请的精神和范围内,都可以做出可能的变动和修改,因此本申请的保护范围应当以本申请权利要求所界定的范围为准。
[0209] 在一个典型的配置中,计算设备包括一个或多个处理器(CPU)、输入 / 输出接口、网络接口和内存。
[0210] 内存可能包括计算机可读介质中的非永久性存储器,随机存取存储器(RAM)和 / 或非易失性内存等形式,如只读存储器(ROM)或闪存(flash RAM)。内存是计算机可读介质的示例。
[0211] 1、计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带,磁带磁磁盘存储或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括非暂存电脑可读媒体(transitory media),如调制的数据信号和载波。
[0212] 2、本领域技术人员应明白,本申请的实施例可提供为方法、系统或计算机程序产品。因此,本申请可采用完全硬件实施例、完全软件实施例或结合软件和硬件方面的实施例的形式。而且,本申请可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。
[0213] 需要说明的是,本申请实施例中可能会涉及到对用户数据的使用,在实际应用中,可以在符合所在国的适用法律法规要求的情况下(例如,用户明确同意,对用户切实通知,等),在适用法律法规允许的范围内在本文描述的方案中使用用户特定的个人数据。
[0214] 需要说明的是,本申请所涉及的用户信息(包括但不限于用户设备信息、用户个人信息等)和数据(包括但不限于用于分析的数据、存储的数据、展示的数据等),均为经用户授权或者经过各方充分授权的信息和数据,并且相关数据的收集、使用和处理需要遵守相关国家和地区的相关法律法规和标准,并提供有相应的操作入口,供用户选择授权或者拒绝。< / script>
Claims
1. A webpage watermark generation method, characterized in that: include: In response to a request of a watermark script embedded in a web page of a browser, a GLSL shader language for drawing a watermark is loaded; Generate a target watermark according to a preset watermark generation scheme; Using the GLSL shader language to form a watermark drawing code for the target watermark; The page generation code including the watermark drawing code is provided to the browser side.
2. The webpage watermark generation method according to claim 1, characterized in that: The step of generating a target watermark according to a preset watermark generation scheme includes: Generate a watermark ID for representing watermark content; The watermark ID is encrypted to generate a target watermark.
3. The webpage watermark generation method according to claim 2, characterized in that: The step of performing encryption processing on the watermark ID to generate a target watermark includes: An encryption scheme is randomly selected from a plurality of preset encryption schemes to perform encryption processing on the watermark ID, and an encrypted watermark ID is generated as a target watermark.
4. The webpage watermark generation method according to claim 3, characterized in that: The watermark drawing code for forming the target watermark by using the GLSL shader language includes: Fill the encrypted watermark ID into the GLSL shader language template to generate the initial watermark drawing code; The initial watermark drawing code is obfuscated to generate a target watermark drawing code as the watermark drawing code of the target watermark.
5. The webpage watermark generation method according to claim 1, characterized in that: Also includes: Generate a canvas element creation code for instructing a web page on a browser side to create a canvas element corresponding to a canvas element for drawing the target watermark; The canvas element creation code is provided to the browser side.
6. The webpage watermark generation method according to claim 5, characterized in that: Corresponding to the canvas element, an instruction for creating a WebGL environment in the canvas element is set, so that the GLSL shader language can run in the WebGL environment provided by the canvas element.
7. A webpage watermark generation method, characterized in that: include: Send a watermark script request to the server to generate a watermark in the web page; Obtaining a watermark drawing code formed according to the GLSL shader language and returned by the server; A watermark is drawn according to the watermark drawing code.
8. The webpage watermark generation method according to claim 7, characterized in that: Also includes: Get the canvas element creation code returned by the server; Creating a canvas element in a webpage based on the canvas element creation code; Make the canvas element transparent to mouse events.
9. The webpage watermark generation method according to claim 8, characterized in that: Drawing a watermark according to the watermark drawing code comprises: A watermark is drawn in the canvas element according to the watermark drawing code.
10. The webpage watermark generation method according to claim 9, characterized in that: Drawing a watermark in the canvas element according to the watermark drawing code comprises: Creating a WebGL environment in the canvas element according to an instruction to create a WebGL environment in the canvas element; In the WebGL environment, the watermark drawing code is executed using the GLSL shader language to perform watermark drawing.
11. The webpage watermark generation method according to claim 9, characterized in that: Also includes: Get the target watermark drawing code containing the time-related element and the canvas element containing the time-related code returned by the server; When generating a canvas element based on the time-related code, the canvas element is generated at each relevant time point according to the preset time-related element; When generating the canvas element, according to the time information provided by the time-related element, the target watermark drawing code of the time-related element is adopted to draw the target watermark including the time-related element on the canvas element.
12. A webpage watermark generation device, characterized in that: include: A GLSL shader language loading unit, used to load a GLSL shader language for drawing a watermark in response to a request of a watermark script implanted in a web page of a browser end; A target watermark generation unit, used to generate a target watermark according to a preset watermark generation scheme; A watermark drawing code forming unit, used for forming a watermark drawing code of the target watermark by using the GLSL shader language; The page generation code providing unit is used to provide the page generation code including the watermark drawing code to the browser end.
13. A webpage watermark generation device, characterized in that: include: A watermark script sending unit, used to send a watermark script request for generating a watermark in a web page to a server; A watermark drawing code obtaining unit, used to obtain the watermark drawing code formed according to the GLSL shader language returned by the server; The watermark drawing unit is used to draw the watermark according to the watermark drawing code.
14. An electronic device, characterized in that: The electronic device comprises a processor and a memory; The memory stores a computer program, and after the processor runs the computer program, the method according to any one of claims 1 to 11 is executed.
15. A computer storage medium, characterized in that The computer storage medium stores a computer program, and after the computer program is run by the processor, the method according to any one of claims 1 to 11 is executed.
