Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Shell script to make the website more readable

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to use Shell scripts to make the site more readable, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!

The W3C provides the Web content accessibility Guide Web Content Accessibility Guidelines, which includes guidance to help Web designers choose guidelines that are easy to distinguish between text and background colors. Z this is called "contrast contrast ratio". The contrast defined by the W3C requires some calculation: given two colors, first calculate the relative brightness of each color, and then calculate the contrast. The contrast ranges from 1 to 21 (usually written from 1:1 to 21:1). The higher the contrast, the more prominent the text in the background. For example, black text on a white background is very eye-catching with a contrast of 21:1. White text on a white background with a contrast of 1:1 is unreadable.

According to the W3C, the contrast of the text should be at least 4.5 Drex1 and the title should be at least 3:1. But this seems to be a minimum requirement. The W3C also recommends at least 7:1 in the text and at least 4.5 in the title.

Calculating contrast can be cumbersome, so it's best to automate it. I've done this with this convenient Bash script. Typically, scripts do the following:

Get text color and background color

Calculate the relative brightness

Calculate the contrast

Get Color

You may know that every color on the monitor can be represented by red, green and blue (R, G and B). To calculate the relative brightness of a color, the script needs to know the red, green, and blue components of the color. Ideally, the script would read this information as separate R, G, and B values. Web designers may know the specific RGB code for their favorite color, but most people don't know the RGB value for different colors. As an alternative, most people refer to colors by names such as "red" or "gold" or "maroon".

Fortunately, GNOME's Zenity tool has a color picker application that allows you to select colors in different ways, and then return RGB values in a predictable format, rgb (RmagGMagee B). Color values can be easily obtained using Zenity:

Color=$ (zenity-- title 'Set text color'-- color-selection-- color='black')

If the user (unexpectedly) clicks the Cancel button, the script assumes a color:

If [$?-ne 0]; then echo'* * color canceled. Assume black' color='rgb (0je 0je 0)'fi

The script does a similar thing with the background color value, setting it to $background.

Calculate the relative brightness

Once you have set the foreground color in $color and the background color in $background, the next step is to calculate the relative brightness of each color. W3C provides an algorithm to calculate the relative brightness of colors.

For sRGB color spaces, the relative brightness of a color is defined as:

L = 0.2126 * R + 0.7152 * G + 0.0722 * B

R, G, and B are defined as:

If RsRGB

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report