js to implement verification code interference (static)

js to implement verification code interference (static)

This article shares the specific code of js to implement verification code interference for your reference. The specific content is as follows

Effect

Code

<!DOCTYPE html>
<html>
 <head>
 <meta charset="UTF-8">
 <title></title>
 <style>
  *{
  padding: 0;
  margin: 0;
  }
  canvas{
  background: #272822;
  }
 </style>
 </head>
 <body>
 <canvas id='canvas' width='800' height='500'></canvas>
 <script>
  //Get the drawing board var canvas=document.getElementById('canvas');
  //Get the drawing environment var cv=canvas.getContext('2d');
  
  cv.fillStyle = '#272822';
  cv2.fillRect(0,0,800,500);
  cv.font='80px Microsoft YaHei';
  cv2.fillStyle='greenyellow';
  cv2.fillText( Math.floor(Math.random()*10000),200,200);
  
  //Get all image pixel information var alldata=cv.getImageData(0,0,800,500);
  //Get the number of pixels var dian=alldata.data.length/4;
  for(var i=0;i<10000;i++){
  //Get a random number var num=Math.floor(Math.random()*dian);
  //Calculate the starting number of the four pieces of information corresponding to the pixel var start=(num-1)*4;
  alldata.data[start]=Math.floor(Math.random()*256);
  alldata.data[start+1]=Math.floor(Math.random()*256);
  alldata.data[start+2]=Math.floor(Math.random()*256);
  }
  //Write the data back to the drawing board cv.putImageData(alldata,0,0);
 </script>
 </body>
</html>

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • JavaScript writing verification code script example with rotation + line interference

<<:  Detailed explanation of Docker Volume permission management

>>:  Example of integrating Kafka with Nginx

Recommend

Example of using store in vue3 to record scroll position

Table of contents Overall Effect Listen for conta...

How to create LVM for XFS file system in Ubuntu

Preface lvm (Logical Volume Manager) logical volu...

Example code for using text-align and margin: 0 auto to center in CSS

Use text-align, margin: 0 auto to center in CSS W...

Linux general java program startup script code example

Although the frequency of starting the shell is v...

Mysql experiment: using explain to analyze the trend of indexes

Overview Indexing is a skill that must be mastere...

Detailed explanation of the calculation method of flex-grow and flex-shrink in flex layout

Flex(彈性布局) in CSS can flexibly control the layout...

Detailed explanation of Linux text editor Vim

Vim is a powerful full-screen text editor and the...

Advantages and Problems of XHTML CSS Website Design

XHTML is the standard website design language cur...

Use of nginx custom variables and built-in predefined variables

Overview Nginx can use variables to simplify conf...

Install tomcat and deploy the website under Linux (recommended)

Install jdk: Oracle official download https://www...

Docker container time zone error issue

Table of contents background question Problem ana...

The difference and usage of Vue2 and Vue3 brother component communication bus

Table of contents vue2.x vue3.x tiny-emitter plug...