![]() Finally, we create a template and print it out to the standard output. It’s often used to encode images, documents, and other types of binary data that aren’t natively supported by text-based formats. base64 -d file2.txt You found the super secret base64 content. Afterward, we check whether it’s an empty variable because the variable will be empty in case of unsupported formats. The base64 utility performs Base64 encoding, which is a method of converting binary data into a sequence of ASCII characters. Let’s run the base64 command with the -d option to decode the contents of the file provided as an argument. Then, we grab the image format using the file command and convert it to lowercase. # Print usage and exit if the file was not providedįmt=$(file "$1" | grep -iEo 'apng|bmp|gif|jpeg|png|webp' | head -n1 | tr '' '')įirst of all, we write the usage function in case of errors. This option is the default behavior for the base64 command. We’ll provide it with the image file, and it should print the img element to the standard output: #!/bin/bashĮcho "Formats: APNG BMP GIF JPEG PNG WEBP" e or -encode The decode option tells the base64 command to encode any input data. It should detect the image format automatically and use it as the MIME type. We can write a shell script to create an img element and embed the Base64 data in it.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |