### Configure libqrencode Build Options Source: https://github.com/fukuchi/libqrencode/blob/master/README.md Examples of configuring the libqrencode build process using the 'configure' script with specific options. This allows customization of the installation path and inclusion of optional components like tests and tools. ```bash ./configure --help ``` ```bash ./configure --without-tools ``` ```bash ./configure --with-tests ``` -------------------------------- ### Install libqrencode with vcpkg Source: https://github.com/fukuchi/libqrencode/blob/master/README.md This snippet shows the commands to clone the vcpkg repository, bootstrap it, integrate it with your system, and then install the libqrencode library. ```bash git clone https://github.com/Microsoft/vcpkg.git cd vcpkg ./bootstrap-vcpkg.sh ./vcpkg integrate install ./vcpkg install libqrencode ``` -------------------------------- ### CMake Installation Rules Source: https://github.com/fukuchi/libqrencode/blob/master/CMakeLists.txt Configures installation paths for the project using GNUInstallDirs. It generates man page and pkgconfig files, and then installs the qrencode library, its header file, the man page, and the pkgconfig file to their respective system locations. ```cmake include(GNUInstallDirs) set(prefix "${CMAKE_INSTALL_PREFIX}") set(exec_prefix "${CMAKE_INSTALL_FULL_BINDIR}") set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}") set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}") set(VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}") configure_file(qrencode.1.in qrencode.1 @ONLY) configure_file(libqrencode.pc.in libqrencode.pc @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qrencode.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libqrencode.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) install(FILES qrencode.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) install(TARGETS qrencode DESTINATION ${CMAKE_INSTALL_LIBDIR}) ``` -------------------------------- ### Compile and Install libqrencode using Autotools Source: https://github.com/fukuchi/libqrencode/blob/master/README.md Standard compilation and installation process for the libqrencode library and its command-line utility using the autotools build system. This involves configuring the build, compiling the source code, and installing the binaries and libraries. ```bash ./configure make sudo make install sudo ldconfig ``` -------------------------------- ### Compile and Install libqrencode using CMake Source: https://github.com/fukuchi/libqrencode/blob/master/README.md Alternative compilation and installation process for libqrencode using CMake. This method is useful if the autotools 'configure' script is not available or preferred. It involves running CMake to configure the build and then using make to compile and install. ```bash cmake . make ``` -------------------------------- ### Configure libqrencode Build Options with CMake Source: https://github.com/fukuchi/libqrencode/blob/master/README.md Examples of configuring the libqrencode build process using CMake with specific options. This allows enabling optional components like tests during the build. ```bash cmake . -DWITH_TESTS=YES ``` -------------------------------- ### Generate PNG QR Codes via CLI Source: https://context7.com/fukuchi/libqrencode/llms.txt Examples of using the qrencode command-line utility to generate PNG images with various configurations like error correction, module size, and colors. ```bash qrencode -o output.png "Hello, World!" qrencode -l H -o output.png "Important data" qrencode -s 10 -m 2 -o output.png "https://example.com" qrencode -v 10 -o output.png "Large data capacity" qrencode -d 300 -o print.png "Print-ready QR" qrencode --foreground=FF0000 --background=FFFFFF -o red.png "Red QR" qrencode --foreground=000000FF --background=FFFFFF00 -o transparent.png "Transparent BG" ``` -------------------------------- ### Analyze QR Code Bitmap Data in C Source: https://context7.com/fukuchi/libqrencode/llms.txt A C example demonstrating how to parse the internal bit flags of a QRcode structure to analyze module types and distribution. ```c #include #include "qrencode.h" void analyze_qrcode(QRcode *qr) { printf("QR Code Analysis:\n"); printf("Version: %d, Size: %dx%d modules\n\n", qr->version, qr->width, qr->width); int black_count = 0, data_count = 0, ecc_count = 0; int finder_count = 0, timing_count = 0; for (int y = 0; y < qr->width; y++) { for (int x = 0; x < qr->width; x++) { unsigned char module = qr->data[y * qr->width + x]; if (module & 0x01) black_count++; if (!(module & 0x80)) { if (module & 0x02) ecc_count++; else data_count++; } if (module & 0x40) finder_count++; if (module & 0x10) timing_count++; } } int total = qr->width * qr->width; printf("Module counts:\n"); printf(" Black modules: %d (%.1f%%)\n", black_count, 100.0*black_count/total); printf(" Data modules: %d\n", data_count); printf(" ECC modules: %d\n", ecc_count); printf(" Finder patterns: %d\n", finder_count); printf(" Timing patterns: %d\n", timing_count); } int main(void) { QRcode *qr = QRcode_encodeString("Test", 0, QR_ECLEVEL_M, QR_MODE_8, 1); if (qr) { analyze_qrcode(qr); QRcode_free(qr); } return 0; } ``` -------------------------------- ### Terminal and ASCII Output Source: https://context7.com/fukuchi/libqrencode/llms.txt Examples of displaying QR codes directly in the terminal using various text-based output formats. ```APIDOC ## UTF-8 output to terminal (compact, uses half-block characters) ### Description Displays a QR code in the terminal using UTF-8 characters for a compact representation. ### Method Command Line Tool ### Endpoint N/A ### Parameters #### Command Line Arguments - **-t UTF8** - Required - Specifies UTF-8 terminal output. - **-o -** - Required - Outputs to standard output (the terminal). - **"Scan me!"** - Required - The data to encode. ### Request Example ```bash qrencode -t UTF8 -o - "Scan me!" ``` ## UTF-8 inverted (for dark terminals) ### Description Displays an inverted QR code in the terminal using UTF-8 characters, suitable for dark terminal backgrounds. ### Method Command Line Tool ### Endpoint N/A ### Parameters #### Command Line Arguments - **-t UTF8i** - Required - Specifies inverted UTF-8 terminal output. - **-o -** - Required - Outputs to standard output (the terminal). - **"Inverted"** - Required - The data to encode. ### Request Example ```bash qrencode -t UTF8i -o - "Inverted" ``` ## ANSI colored output ### Description Displays a QR code in the terminal using ANSI escape codes for color. ### Method Command Line Tool ### Endpoint N/A ### Parameters #### Command Line Arguments - **-t ANSI** - Required - Specifies ANSI colored terminal output. - **-o -** - Required - Outputs to standard output (the terminal). - **"Colored terminal QR"** - Required - The data to encode. ### Request Example ```bash qrencode -t ANSI -o - "Colored terminal QR" ``` ## ANSI with 256 colors ### Description Displays a QR code in the terminal using ANSI 256-color escape codes for a wider color range. ### Method Command Line Tool ### Endpoint N/A ### Parameters #### Command Line Arguments - **-t ANSI256** - Required - Specifies ANSI 256-color terminal output. - **-o -** - Required - Outputs to standard output (the terminal). - **"256-color QR"** - Required - The data to encode. ### Request Example ```bash qrencode -t ANSI256 -o - "256-color QR" ``` ## Plain ASCII (double-width characters) ### Description Displays a QR code in the terminal using plain ASCII characters with double-width spacing. ### Method Command Line Tool ### Endpoint N/A ### Parameters #### Command Line Arguments - **-t ASCII** - Required - Specifies plain ASCII terminal output. - **-o -** - Required - Outputs to standard output (the terminal). - **"ASCII art QR"** - Required - The data to encode. ### Request Example ```bash qrencode -t ASCII -o - "ASCII art QR" ``` ## ASCII inverted ### Description Displays an inverted QR code in the terminal using plain ASCII characters. ### Method Command Line Tool ### Endpoint N/A ### Parameters #### Command Line Arguments - **-t ASCIIi** - Required - Specifies inverted ASCII terminal output. - **-o -** - Required - Outputs to standard output (the terminal). - **"Inverted ASCII"** - Required - The data to encode. ### Request Example ```bash qrencode -t ASCIIi -o - "Inverted ASCII" ``` ## ANSI + UTF8 combined for best terminal display ### Description Displays a QR code in the terminal using a combination of ANSI colors and UTF-8 characters for optimal visual representation. ### Method Command Line Tool ### Endpoint N/A ### Parameters #### Command Line Arguments - **-t ANSIUTF8** - Required - Specifies combined ANSI and UTF-8 terminal output. - **-o -** - Required - Outputs to standard output (the terminal). - **"Best terminal output"** - Required - The data to encode. ### Request Example ```bash qrencode -t ANSIUTF8 -o - "Best terminal output" ``` ``` -------------------------------- ### Extract Module Information from QRcode Data (C API) Source: https://context7.com/fukuchi/libqrencode/llms.txt A C code example demonstrating how to use the libqrencode library to encode a string and then analyze the resulting QR code's module data, including counts of black modules, data, ECC, finder patterns, and timing patterns. ```APIDOC ## Extract Module Information from QRcode Data ### Description This C code snippet demonstrates how to use the `libqrencode` library to encode a string into a QR code and then analyze the internal `QRcode` data structure. It iterates through each module, checks its properties using bit flags (like black/white, data/ECC area, pattern types), and provides counts for various module types. ### Method C Programming Language (using libqrencode) ### Endpoint N/A (Library Function Usage) ### Parameters #### Function Parameters - **QRcode *qr** - Input - A pointer to the `QRcode` structure returned by `QRcode_encodeString` or similar functions. #### Internal Bit Flags (within `qr->data` module byte) - **0x01**: LSB, indicates module color (1=black, 0=white). - **0x02**: Indicates ECC area (1) or data area (0). - **0x04**: Format information. - **0x08**: Version information. - **0x10**: Timing pattern. - **0x20**: Alignment pattern. - **0x40**: Finder pattern and separator. - **0x80**: Non-data module (any special pattern). ### Request Example (Conceptual C Code) ```c #include #include "qrencode.h" // ... (analyze_qrcode function definition as provided in the example) int main(void) { QRcode *qr = QRcode_encodeString("Test", 0, QR_ECLEVEL_M, QR_MODE_8, 1); if (qr) { analyze_qrcode(qr); QRcode_free(qr); } return 0; } ``` ### Response (Example Output) ``` QR Code Analysis: Version: 1, Size: 21x21 modules Module counts: Black modules: 53 (11.9%) Data modules: 157 ECC modules: 68 Finder patterns: 9 Timing patterns: 21 ``` ### Success Response (200) - **QRcode structure**: Contains `version`, `width`, and `data` (byte array of modules). - **Analysis Output**: Printed to standard output, detailing module counts and percentages. ``` -------------------------------- ### EPS Output Formats Source: https://context7.com/fukuchi/libqrencode/llms.txt Examples of generating QR codes in Encapsulated PostScript (EPS) format for print workflows, including custom color options. ```APIDOC ## EPS for print workflows ### Description Generates a QR code and saves it as an Encapsulated PostScript (EPS) file, suitable for print workflows. ### Method Command Line Tool ### Endpoint N/A ### Parameters #### Command Line Arguments - **-t EPS** - Required - Specifies EPS output format. - **-o output.eps** - Required - Specifies the output file name. - **"PostScript QR"** - Required - The data to encode. ### Request Example ```bash qrencode -t EPS -o output.eps "PostScript QR" ``` ## EPS with custom colors ### Description Generates an EPS QR code with custom foreground color. ### Method Command Line Tool ### Endpoint N/A ### Parameters #### Command Line Arguments - **-t EPS** - Required - Specifies EPS output format. - **--foreground=000080** - Optional - Sets the foreground color (e.g., blue in hex). - **-o blue.eps** - Required - Specifies the output file name. - **"Blue QR"** - Required - The data to encode. ### Request Example ```bash qrencode -t EPS --foreground=000080 -o blue.eps "Blue QR" ``` ``` -------------------------------- ### QRcode_APIVersion - Get Library Version Source: https://context7.com/fukuchi/libqrencode/llms.txt Retrieves the version of the libqrencode library, allowing for runtime version checking and compatibility verification. ```APIDOC ## QRcode_APIVersion - Get Library Version ### Description Returns the version of the libqrencode library for runtime version checking and compatibility verification. ### Method `void QRcode_APIVersion(int *major, int *minor, int *micro)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```c #include "qrencode.h" int major, minor, micro; QRcode_APIVersion(&major, &minor, µ); printf("Version: %d.%d.%d\n", major, minor, micro); ``` ### Response #### Success Response (200) - **major** (int*) - Pointer to an integer to store the major version number. - **minor** (int*) - Pointer to an integer to store the minor version number. - **micro** (int*) - Pointer to an integer to store the micro version number. #### Response Example ```c int major, minor, micro; QRcode_APIVersion(&major, &minor, µ); // major, minor, and micro are now populated with version numbers ``` ## QRcode_APIVersionString - Get Library Version String Returns the version of the libqrencode library as a string. ### Description Provides the library version in a human-readable string format, useful for logging or display purposes. ### Method `char *QRcode_APIVersionString(void)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```c #include "qrencode.h" char *version_str = QRcode_APIVersionString(); printf("Library Version: %s\n", version_str); ``` ### Response #### Success Response (200) - **char*** - A pointer to a string representing the library version (e.g., "4.1.1"). #### Response Example ```c char *version_str = QRcode_APIVersionString(); // version_str points to "4.1.1" (or the actual installed version) ``` ### Error Handling - Returns `NULL` if the version string cannot be obtained (highly unlikely). ``` -------------------------------- ### SVG Output Formats Source: https://context7.com/fukuchi/libqrencode/llms.txt Examples of generating QR codes in Scalable Vector Graphics (SVG) format with different options for efficiency, embedding, and compression. ```APIDOC ## SVG Output ### Description Generates a QR code and saves it as an SVG file. ### Method Command Line Tool ### Endpoint N/A ### Parameters #### Command Line Arguments - **-t SVG** - Required - Specifies SVG output format. - **-o output.svg** - Required - Specifies the output file name. - **"Vector QR code"** - Required - The data to encode. ### Request Example ```bash qrencode -t SVG -o output.svg "Vector QR code" ``` ## SVG with single path (more efficient) ### Description Generates an optimized SVG QR code using a single path element for better efficiency. ### Method Command Line Tool ### Endpoint N/A ### Parameters #### Command Line Arguments - **-t SVG** - Required - Specifies SVG output format. - **--svg-path** - Optional - Enables single path optimization. - **-o efficient.svg** - Required - Specifies the output file name. - **"Optimized SVG"** - Required - The data to encode. ### Request Example ```bash qrencode -t SVG --svg-path -o efficient.svg "Optimized SVG" ``` ## SVG for embedding (without XML declaration) ### Description Generates an SVG QR code suitable for embedding directly into HTML, without the XML declaration. ### Method Command Line Tool ### Endpoint N/A ### Parameters #### Command Line Arguments - **-t SVG** - Required - Specifies SVG output format. - **--inline** - Optional - Removes the XML declaration for embedding. - **-o embed.svg** - Required - Specifies the output file name. - **"For HTML embedding"** - Required - The data to encode. ### Request Example ```bash qrencode -t SVG --inline -o embed.svg "For HTML embedding" ``` ## SVG with run-length encoding for smaller files ### Description Generates a compressed SVG QR code using run-length encoding (RLE) to reduce file size. ### Method Command Line Tool ### Endpoint N/A ### Parameters #### Command Line Arguments - **-t SVG** - Required - Specifies SVG output format. - **--rle** - Optional - Enables run-length encoding for compression. - **-o compressed.svg** - Required - Specifies the output file name. - **"Compressed SVG"** - Required - The data to encode. ### Request Example ```bash qrencode -t SVG --rle -o compressed.svg "Compressed SVG" ``` ``` -------------------------------- ### Create Micro QR Code Input with libqrencode Source: https://context7.com/fukuchi/libqrencode/llms.txt Demonstrates how to initialize a Micro QR input object and encode data into a Micro QR code. It includes both manual input object creation and a convenience function for direct string encoding. ```c #include #include "qrencode.h" int main(void) { QRinput *input = QRinput_newMQR(2, QR_ECLEVEL_L); if (input == NULL) { perror("Failed to create Micro QR input"); return 1; } const unsigned char data[] = "12345"; if (QRinput_append(input, QR_MODE_NUM, 5, data) < 0) { perror("Data too large for Micro QR"); QRinput_free(input); return 1; } QRcode *qrcode = QRcode_encodeInput(input); if (qrcode == NULL) { perror("Failed to encode Micro QR"); QRinput_free(input); return 1; } printf("Created Micro QR code: version M%d, width=%d\n", qrcode->version, qrcode->width); QRcode_free(qrcode); QRinput_free(input); return 0; } void encode_micro_qr_string(void) { QRcode *qrcode = QRcode_encodeStringMQR("HELLO", 2, QR_ECLEVEL_L, QR_MODE_8, 1); if (qrcode != NULL) { printf("Micro QR created\n"); QRcode_free(qrcode); } } ``` -------------------------------- ### Build Utility Tools (CMake) Source: https://github.com/fukuchi/libqrencode/blob/master/CMakeLists.txt Configures the build process for utility tools, specifically the 'qrenc' executable. It conditionally enables PNG support and links necessary libraries. This snippet is written in CMake. ```cmake if(WITH_TOOLS) if(NOT WITHOUT_PNG) add_definitions(-DHAVE_PNG=1) endif() add_executable(qrenc qrenc.c) set_target_properties(qrenc PROPERTIES OUTPUT_NAME qrencode) if(NOT WITHOUT_PNG) target_link_libraries(qrenc qrencode PNG::PNG) else() target_link_libraries(qrenc qrencode) endif() if(MSVC) target_link_libraries(qrenc ${GETOPT_LIBRARIES}) endif(MSVC) install(TARGETS qrenc DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() ``` -------------------------------- ### Handle Input Streams and Files Source: https://context7.com/fukuchi/libqrencode/llms.txt Techniques for reading data from files or standard input for QR code generation, including binary file support. ```bash qrencode -r input.txt -o output.png echo "Piped data" | qrencode -o output.png qrencode -o output.png cat binary_file | qrencode -8 -o output.png qrencode -8 -r data.bin -o binary.png ``` -------------------------------- ### Reading Input from Files and Stdin Source: https://context7.com/fukuchi/libqrencode/llms.txt Demonstrates how to encode data for QR codes by reading from files or standard input (stdin). ```APIDOC ## Read input from file ### Description Encodes data from a specified file into a QR code and saves it as a PNG image. ### Method Command Line Tool ### Endpoint N/A ### Parameters #### Command Line Arguments - **-r input.txt** - Required - Specifies the input file. - **-o output.png** - Required - Specifies the output PNG file. ### Request Example ```bash qrencode -r input.txt -o output.png ``` ## Read from stdin (pipe) ### Description Encodes data piped from standard input into a QR code and saves it as a PNG image. ### Method Command Line Tool ### Endpoint N/A ### Parameters #### Command Line Arguments - **-o output.png** - Required - Specifies the output PNG file. ### Request Example ```bash echo "Piped data" | qrencode -o output.png ``` ## Read from stdin interactively ### Description Encodes data entered interactively via standard input into a QR code and saves it as a PNG image. Input ends when Ctrl+D is pressed. ### Method Command Line Tool ### Endpoint N/A ### Parameters #### Command Line Arguments - **-o output.png** - Required - Specifies the output PNG file. ### Request Example ```bash qrencode -o output.png # Type data and press Ctrl+D ``` ## Encode binary file content ### Description Encodes the content of a binary file using 8-bit mode into a QR code and saves it as a PNG image. ### Method Command Line Tool ### Endpoint N/A ### Parameters #### Command Line Arguments - **-8** - Optional - Specifies 8-bit mode. - **-o output.png** - Required - Specifies the output PNG file. ### Request Example ```bash cat binary_file | qrencode -8 -o output.png ``` ## Encode entire file in 8-bit mode ### Description Reads an entire file in 8-bit mode and encodes its content into a QR code saved as a PNG image. ### Method Command Line Tool ### Endpoint N/A ### Parameters #### Command Line Arguments - **-8** - Optional - Specifies 8-bit mode. - **-r data.bin** - Required - Specifies the input file. - **-o binary.png** - Required - Specifies the output PNG file. ### Request Example ```bash qrencode -8 -r data.bin -o binary.png ``` ``` -------------------------------- ### CMake Project Configuration and Options Source: https://github.com/fukuchi/libqrencode/blob/master/CMakeLists.txt Sets up the CMake project, defines build options such as enabling/disabling tools, tests, PNG support, profiling, coverage, AddressSanitizer, and shared libraries. It also handles deprecation warnings for build options. ```cmake cmake_minimum_required(VERSION 3.1.0) project(QRencode VERSION 4.1.1 LANGUAGES C) option(WITH_TOOLS "Build utility tools" YES ) option(WITH_TESTS "Build tests" NO ) option(WITHOUT_PNG "Disable PNG support" NO) option(GPROF "Generate extra code to write profile information" OFF) option(COVERAGE "Generate extra code to write coverage information" OFF) option(ASAN "Use AddressSanitizer" OFF) option(BUILD_SHARED_LIBS "Enable build of shared libraries" NO) if(BUILD_TESTING) set(WITH_TESTS ON) message(DEPRECATION "use WITH_TESTS option instead BUILD_TESTING") endif() ``` -------------------------------- ### Configuration Summary Output (CMake) Source: https://github.com/fukuchi/libqrencode/blob/master/CMakeLists.txt Generates a summary of the build configuration, displaying system information, detected dependencies, and project-specific settings. This is achieved using CMake's message command. ```cmake message(STATUS "------------------------------------------------------------" ) message(STATUS "[QRencode] Configuration summary." ) message(STATUS "------------------------------------------------------------ ") message(STATUS " System configuration:" ) message(STATUS " .. Processor type .............. = ${CMAKE_SYSTEM_PROCESSOR}") message(STATUS " .. CMake executable ............ = ${CMAKE_COMMAND}" ) message(STATUS " .. CMake version ............... = ${CMAKE_VERSION}" ) message(STATUS " .. System name ................. = ${CMAKE_SYSTEM}" ) message(STATUS " .. C++ compiler ................ = ${CMAKE_CXX_COMPILER}" ) message(STATUS " .. C compiler .................. = ${CMAKE_C_COMPILER}" ) message(STATUS " .. size(void*) ................. = ${CMAKE_SIZEOF_VOID_P}" ) message(STATUS " Dependencies:" ) message(STATUS " .. Thread library of the system = ${CMAKE_THREAD_LIBS_INIT}") message(STATUS " .. Iconv ....................... = ${ICONV_FOUND}" ) message(STATUS " .... Iconv includes ............ = ${ICONV_INCLUDE_DIR}" ) message(STATUS " .... Iconv library ............. = ${ICONV_LIBRARIES}" ) message(STATUS " .. ZLIB ........................ = ${ZLIB_FOUND}" ) message(STATUS " .. PNG ......................... = ${PNG_FOUND}" ) message(STATUS " .... PNG includes .............. = ${PNG_INCLUDE_DIR}" ) message(STATUS " .... PNG library ............... = ${PNG_LIBRARIES}" ) message(STATUS " Project configuration:" ) message(STATUS " .. Build test programs ........ = ${WITH_TESTS}" ) message(STATUS " .. Build utility tools ........ = ${WITH_TOOLS}" ) message(STATUS " .. Disable PNG support ........ = ${WITHOUT_PNG}" ) message(STATUS " .. Installation prefix ......... = ${CMAKE_INSTALL_PREFIX}" ) message(STATUS "------------------------------------------------------------ ") ``` -------------------------------- ### Retrieve libqrencode Library Version Source: https://context7.com/fukuchi/libqrencode/llms.txt Shows how to programmatically check the version of the libqrencode library using both numeric components and a formatted string. ```c #include #include "qrencode.h" int main(void) { int major, minor, micro; QRcode_APIVersion(&major, &minor, µ); printf("libqrencode version: %d.%d.%d\n", major, minor, micro); char *version_str = QRcode_APIVersionString(); printf("Version string: %s\n", version_str); if (major < 4) { fprintf(stderr, "Warning: libqrencode 4.x recommended\n"); } return 0; } ``` -------------------------------- ### Command-Line Tool - Generate PNG QR Code Source: https://context7.com/fukuchi/libqrencode/llms.txt The qrencode command-line utility creates QR code images in various formats. Basic PNG output requires specifying an output filename. ```bash ## Generate PNG QR Code ### Description The `qrencode` command-line utility creates QR code images in various formats. Basic PNG output requires specifying an output filename. ### Usage `qrencode [options] -o ""` ### Options - `-o `: Specifies the output file path. The format is determined by the file extension (e.g., `.png`). - `-l `: Sets the error correction level (L, M, Q, H). - `-s `: Sets the module size in pixels. - `-m `: Sets the margin around the QR code in modules. - `-v `: Sets the QR code version (1-40). - `-d `: Sets the DPI for print-quality images. - `--foreground=`: Sets the foreground color (e.g., `FF0000` for red). - `--background=`: Sets the background color (e.g., `FFFFFF` for white). ### Examples #### Basic PNG Generation ```bash qrencode -o output.png "Hello, World!" ``` #### Specify Error Correction Level ```bash qrencode -l H -o output.png "Important data" ``` #### Set Module Size and Margin ```bash qrencode -s 10 -m 2 -o output.png "https://example.com" ``` #### Set Specific Version ```bash qrencode -v 10 -o output.png "Large data capacity" ``` #### Set DPI for Print ```bash qrencode -d 300 -o print.png "Print-ready QR" ``` #### Custom Colors ```bash qrencode --foreground=FF0000 --background=FFFFFF -o red.png "Red QR" ``` #### With Transparency ```bash qrencode --foreground=000000FF --background=FFFFFF00 -o transparent.png "Transparent BG" ``` ``` -------------------------------- ### C: Create QR Input Object with Version and Level (QRinput_new2) Source: https://context7.com/fukuchi/libqrencode/llms.txt Demonstrates creating a QR input object using QRinput_new2, allowing manual construction of QR code data. This function provides fine-grained control over data segmentation and encoding, suitable for mixing encoding modes or adding special headers. It appends numeric, alphanumeric, and binary data before encoding the final QR code. ```c #include #include "qrencode.h" int main(void) { // Create input object with specific version and error correction QRinput *input = QRinput_new2(5, QR_ECLEVEL_H); // Version 5, highest EC if (input == NULL) { perror("Failed to create input"); return 1; } // Append numeric data (most efficient for digits) const unsigned char num_data[] = "1234567890"; if (QRinput_append(input, QR_MODE_NUM, 10, num_data) < 0) { perror("Failed to append numeric data"); QRinput_free(input); return 1; } // Append alphanumeric data const unsigned char alpha_data[] = "HELLO WORLD"; if (QRinput_append(input, QR_MODE_AN, 11, alpha_data) < 0) { perror("Failed to append alphanumeric data"); QRinput_free(input); return 1; } // Append 8-bit binary data const unsigned char binary[] = {0x01, 0x02, 0x03, 0x04}; if (QRinput_append(input, QR_MODE_8, 4, binary) < 0) { perror("Failed to append binary data"); QRinput_free(input); return 1; } // Encode the structured input QRcode *qrcode = QRcode_encodeInput(input); if (qrcode == NULL) { perror("Failed to encode"); QRinput_free(input); return 1; } printf("Created QR code version %d with mixed data types\n", qrcode->version); QRcode_free(qrcode); QRinput_free(input); return 0; } ``` -------------------------------- ### Build Tests and Static Libraries (CMake) Source: https://github.com/fukuchi/libqrencode/blob/master/CMakeLists.txt Manages the build configuration for testing and static library support. It enables testing if WITH_TESTS is defined and sets a flag for static builds in release mode. This snippet is written in CMake. ```cmake if(WITH_TESTS) enable_testing() add_definitions(-DWITH_TESTS=) add_definitions(-DSTATIC_IN_RELEASE=) add_subdirectory(tests) else() add_definitions(-DSTATIC_IN_RELEASE=static) endif() ``` -------------------------------- ### Generate Micro QR Codes Source: https://context7.com/fukuchi/libqrencode/llms.txt Commands to generate space-efficient Micro QR codes for small data payloads. ```bash qrencode -M -v 2 -o micro.png "SHORT" qrencode -M -o micro.png "123" ``` -------------------------------- ### QRinput_newMQR - Create Micro QR Code Input Source: https://context7.com/fukuchi/libqrencode/llms.txt Creates an input object for encoding Micro QR codes, which are smaller variants suitable for embedding in limited space. Micro QR codes support versions 1-4 with reduced data capacity. ```APIDOC ## QRinput_newMQR - Create Micro QR Code Input ### Description Creates an input object for encoding Micro QR codes, which are smaller variants suitable for embedding in limited space. Micro QR codes support versions 1-4 with reduced data capacity. ### Method `QRinput_newMQR(int version, QRecLevel level)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```c #include "qrencode.h" QRinput *input = QRinput_newMQR(2, QR_ECLEVEL_L); ``` ### Response #### Success Response (200) - **QRinput*** - A pointer to the newly created QRinput object. #### Response Example ```c // Successful creation returns a valid pointer QRinput *input = QRinput_newMQR(2, QR_ECLEVEL_L); ``` ### Error Handling - Returns `NULL` if memory allocation fails or if an invalid version is provided (version must be between 1 and 4 for Micro QR). ## QRinput_append - Append Data to QR Input Appends data to the QR input object. This function is used after creating an input object (e.g., with `QRinput_newMQR`) to add the data to be encoded. ### Description Appends data to the QR input object. This function is used after creating an input object (e.g., with `QRinput_newMQR`) to add the data to be encoded. ### Method `int QRinput_append(QRinput *input, QRencodeMode mode, int length, const unsigned char *data)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```c #include "qrencode.h" QRinput *input = QRinput_newMQR(2, QR_ECLEVEL_L); const unsigned char data[] = "12345"; QRinput_append(input, QR_MODE_NUM, 5, data); ``` ### Response #### Success Response (200) - **int** - Returns 0 on success, or a negative value on failure (e.g., data too large for the QR code capacity). #### Response Example ```c // Returns 0 on success if (QRinput_append(input, QR_MODE_NUM, 5, data) == 0) { // Data appended successfully } ``` ### Error Handling - Returns a negative value if the data is too large to fit in the QR code's capacity for the specified mode and version. ## QRcode_encodeInput - Encode QR Code from Input Object Encodes a QR code from a previously prepared `QRinput` object. ### Description Encodes a QR code from a previously prepared `QRinput` object. This is the primary function for encoding QR codes when you need fine-grained control over the input data and parameters. ### Method `QRcode *QRcode_encodeInput(QRinput *input)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```c #include "qrencode.h" QRinput *input = QRinput_newMQR(2, QR_ECLEVEL_L); // ... append data to input ... QRcode *qrcode = QRcode_encodeInput(input); ``` ### Response #### Success Response (200) - **QRcode*** - A pointer to the `QRcode` structure containing the encoded QR code data (e.g., modules, version, width). #### Response Example ```c QRcode *qrcode = QRcode_encodeInput(input); if (qrcode != NULL) { printf("QR code encoded successfully. Width: %d, Version: %d\n", qrcode->width, qrcode->version); } ``` ### Error Handling - Returns `NULL` if encoding fails (e.g., due to invalid input or insufficient capacity). ## QRcode_encodeStringMQR - Convenience Function for Micro QR Code Strings A convenience function to directly encode a string into a Micro QR code. ### Description This function simplifies the process of creating a Micro QR code from a string, handling input creation and encoding internally. ### Method `QRcode *QRcode_encodeStringMQR(const char *string, int version, QRecLevel level, QRencodeMode mode, int case_sensitive)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```c #include "qrencode.h" QRcode *qrcode = QRcode_encodeStringMQR("HELLO", 2, QR_ECLEVEL_L, QR_MODE_8, 1); ``` ### Response #### Success Response (200) - **QRcode*** - A pointer to the `QRcode` structure if encoding is successful. #### Response Example ```c QRcode *qrcode = QRcode_encodeStringMQR("HELLO", 2, QR_ECLEVEL_L, QR_MODE_8, 1); if (qrcode != NULL) { printf("Micro QR code created."); QRcode_free(qrcode); } ``` ### Error Handling - Returns `NULL` if encoding fails, potentially due to invalid parameters or data exceeding Micro QR capacity. ``` -------------------------------- ### Render QR Codes in Terminal Source: https://context7.com/fukuchi/libqrencode/llms.txt Commands to output QR codes directly to the terminal using various character sets and color encodings. ```bash qrencode -t UTF8 -o - "Scan me!" qrencode -t UTF8i -o - "Inverted" qrencode -t ANSI -o - "Colored terminal QR" qrencode -t ANSI256 -o - "256-color QR" qrencode -t ASCII -o - "ASCII art QR" qrencode -t ASCIIi -o - "Inverted ASCII" qrencode -t ANSIUTF8 -o - "Best terminal output" ``` -------------------------------- ### CMake Library Definition and Build Source: https://github.com/fukuchi/libqrencode/blob/master/CMakeLists.txt Defines the source and header files for the qrencode library. It then creates either a static or shared library target named 'qrencode' based on the BUILD_SHARED_LIBS option. For shared libraries, it sets version information and exports symbols on Windows if using MSVC. ```cmake set(QRENCODE_SRCS qrencode.c qrinput.c bitstream.c qrspec.c rsecc.c split.c mask.c mqrspec.c mmask.c) set(QRENCODE_HDRS qrencode_inner.h qrinput.h bitstream.h qrspec.h rsecc.h split.h mask.h mqrspec.h mmask.h) if(BUILD_SHARED_LIBS) if(MSVC) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) endif() add_library(qrencode SHARED ${QRENCODE_SRCS} ${QRENCODE_HDRS}) set_target_properties(qrencode PROPERTIES VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH} SOVERSION ${PROJECT_VERSION_MAJOR}) else() add_library(qrencode ${QRENCODE_SRCS} ${QRENCODE_HDRS}) endif() if(CMAKE_USE_PTHREADS_INIT) target_link_libraries(qrencode Threads::Threads) endif() ``` -------------------------------- ### Command-Line Tool - Generate Vector Formats Source: https://context7.com/fukuchi/libqrencode/llms.txt Vector formats like SVG and EPS are ideal for print and scaling without quality loss. ```bash ## Generate SVG and EPS Vector Formats ### Description Vector formats are ideal for print and scaling without quality loss. ### Usage `qrencode [options] -t -o ""` ### Formats - `SVG`: Scalable Vector Graphics - `EPS`: Encapsulated PostScript ### Examples #### Generate SVG ```bash qrencode -t SVG -o output.svg "Vector QR Code" ``` #### Generate EPS ```bash qrencode -t EPS -o output.eps "Print Quality QR" ``` #### SVG with specific error correction level and size ```bash qrencode -l Q -s 5 -t SVG -o high_quality.svg "Detailed Information" ``` ``` -------------------------------- ### Micro QR Code Generation Source: https://context7.com/fukuchi/libqrencode/llms.txt Instructions for generating smaller Micro QR codes, suitable for applications with limited space. ```APIDOC ## Micro QR code (versions 1-4 only) ### Description Generates a Micro QR code, which is a smaller variant with limited data capacity. Only versions 1 through 4 are supported. ### Method Command Line Tool ### Endpoint N/A ### Parameters #### Command Line Arguments - **-M** - Required - Enables Micro QR code generation. - **-v 2** - Required - Specifies the QR code version (must be 1-4 for Micro QR). - **-o micro.png** - Required - Specifies the output PNG file. - **"SHORT"** - Required - The data to encode. ### Request Example ```bash qrencode -M -v 2 -o micro.png "SHORT" ``` ## Micro QR with auto version selection ### Description Generates a Micro QR code, allowing the tool to automatically select the smallest suitable version (1-4) based on the input data. ### Method Command Line Tool ### Endpoint N/A ### Parameters #### Command Line Arguments - **-M** - Required - Enables Micro QR code generation. - **-o micro.png** - Required - Specifies the output PNG file. - **"123"** - Required - The data to encode. ### Request Example ```bash qrencode -M -o micro.png "123" ``` ## Note: Micro QR has limited capacity and doesn't support structured append ### Description Important limitations of Micro QR codes: they have a significantly reduced data capacity compared to standard QR codes and do not support the structured append feature. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ``` -------------------------------- ### Render QR Code to Raw RGB Bitmap (C) Source: https://context7.com/fukuchi/libqrencode/llms.txt Converts QR code data into a raw RGB bitmap buffer. This function is useful for custom image processing and allows for specifying module size and margin. It outputs the image dimensions and returns a pointer to the allocated RGB buffer. Dependencies include stdio.h, stdlib.h, and qrencode.h. ```c #include #include #include "qrencode.h" // Create RGB bitmap with specified module size and margin unsigned char *qrcode_to_rgb(QRcode *qr, int module_size, int margin, int *out_width, int *out_height) { int img_width = (qr->width + margin * 2) * module_size; int img_height = img_width; // Allocate RGB buffer (3 bytes per pixel) unsigned char *rgb = malloc(img_width * img_height * 3); if (!rgb) return NULL; // Fill with white background memset(rgb, 255, img_width * img_height * 3); // Draw QR code modules for (int qy = 0; qy < qr->width; qy++) { for (int qx = 0; qx < qr->width; qx++) { unsigned char module = qr->data[qy * qr->width + qx]; if (module & 0x01) { // Black module // Draw a module_size x module_size black square int px_start = (margin + qx) * module_size; int py_start = (margin + qy) * module_size; for (int py = py_start; py < py_start + module_size; py++) { for (int px = px_start; px < px_start + module_size; px++) { int idx = (py * img_width + px) * 3; rgb[idx] = 0; // R rgb[idx + 1] = 0; // G rgb[idx + 2] = 0; // B } } } } } *out_width = img_width; *out_height = img_height; return rgb; } int main(void) { QRcode *qr = QRcode_encodeString("Hello", 0, QR_ECLEVEL_M, QR_MODE_8, 1); if (!qr) return 1; int width, height; unsigned char *rgb = qrcode_to_rgb(qr, 10, 4, &width, &height); if (rgb) { printf("Created %dx%d RGB bitmap\n", width, height); // Write to PPM file (simple uncompressed format) FILE *f = fopen("qrcode.ppm", "wb"); fprintf(f, "P6\n%d %d\n255\n", width, height); fwrite(rgb, 1, width * height * 3, f); fclose(f); printf("Saved to qrcode.ppm\n"); free(rgb); } QRcode_free(qr); return 0; } ``` -------------------------------- ### Structured Append for Large Data Source: https://context7.com/fukuchi/libqrencode/llms.txt Commands to split large datasets into multiple QR codes that can be reassembled by a reader. ```bash qrencode -S -v 10 -o output.png "Very long text that needs multiple codes..." qrencode -S -v 5 -l H -r largefile.txt -o chunks.png qrencode -S -v 8 --verbose -o parts.png "Large data" ```