Changing Colors

00:00 Changing the colors of the QR code. If you like to create QR codes with your favorite colors, then the .save() method has optional parameters that you can add to make your codes more colorful.

00:12 In this section, you’ll modify the color of the background, the quiet zone, and the light and dark modules of your QR codes. All you have to do is specify the keyword and a color of choice.

00:23 You can use the RGB format, the name of the color, or a hexadecimal value. As an example, if you want to change the color of the background to light blue, then you can use the code seen on screen.

00:36 Here

00:45 you can see the addition of the light argument, which is set to light blue. The background of the code will now be light blue rather than the default of white.

00:56 Running the code will generate the QR code, which is seen on screen. You could also replace the color name with the RGB or hexadecimal format color. The three lines seen on screen are all equivalent to each other.

01:12 The full list of named colors supported by Segno is available at the link seen on screen. You can also change the colors of all the black modules of the QR code.

01:23 To do this, pass the color of your choice to the dark parameter in the save method. The

01:34 code on screen will change the colors of the dark modules to dark blue.

01:41 Running this code will generate the QR code seen on screen. Once more the quiet zone isn’t as visible because the background color is white, but it is possible to change the quiet zone color independently of the light color.

01:54 This is done by adding a quiet_zone parameter in the .save() method. On screen is an example of additions to the previous code to change the color of the space around the QR code from white to light gray.

02:14 Predictably, running this code will generate the QR code that you can see on screen now. As you may know, some image formats support transparency, allowing some or all elements of an image to be semi or fully transparent.

02:29 Providing you’re creating an image format which supports this, then segno allows creation of transparent codes. While you’ll need to be careful with this feature, balancing artistic control with readability, it is easy to implement.

02:43 The format for the colors when using transparency needs to be in hexadecimal mode. As you saw previously, six-character hexadecimal colors specify red, green, and blue.

02:54 Eight-character hexadecimal colors add another alpha value, which specifies the transparency of the color.

03:10 Here, the dark is still dark blue, but with some transparency, set to CC. Light is still set to a very light blue with a transparency of CC as well.

03:20 The quiet zone is set to the hexadecimal equivalent of light gray, but with a more transparent value of 77.

03:29 This may not be apparent on a plain background, but you can see it when placed over a background on screen with the non-transparent version for comparison.

03:39 So far, you’ve used the light and dark parameters to change the color of all the white and black modules of the QR code, but not all of the modules in the QR code house the data that’s encoded.

03:50 Some of the modules are present to allow a code to be recognized and scan accurately. So in the next section of the course, you’ll see how you can fine-tune the coloring of the QR code information.

Become a Member to join the conversation.