### Build with Autoconf Tools (Unix-like) Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/doc/building.md Builds and installs WebP using standard autoconf tools on Debian-like systems. This involves installing prerequisites, generating the configure script, and then configuring, building, and installing the library and tools. ```shell $ sudo apt-get install gcc make autoconf automake libtool ``` ```shell ./configure make make install ``` -------------------------------- ### Example Usage of Python libwebp Bindings Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/_swig/README.md This Python script demonstrates using the SWIG-generated libwebp bindings. It appends the installed site-packages directory to sys.path, imports the libwebp module, and prints the decoder version and available attributes. Note that this example uses Python 2 syntax for print. ```python import glob import sys sys.path.append(glob.glob('pylocal/lib/python*/site-packages')[0]) from com.google.webp import libwebp print "libwebp decoder version: %x" % libwebp.WebPGetDecoderVersion() print "libwebp attributes:" for attr in dir(libwebp): print attr ``` -------------------------------- ### Build WebP Project using makefile.unix Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/doc/tools.md This command builds the vwebp example tool for the WebP project using the makefile.unix. It assumes the necessary build tools and dependencies are already installed. ```shell make -f makefile.unix examples/vwebp ``` -------------------------------- ### Build with vcpkg Dependency Manager Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/doc/building.md Installs libwebp using the vcpkg dependency manager. This involves cloning the vcpkg repository, bootstrapping it, integrating it with the system, and then installing the libwebp package. The vcpkg port is maintained by Microsoft and the community. ```shell git clone https://github.com/Microsoft/vcpkg.git cd vcpkg ./bootstrap-vcpkg.sh ./vcpkg integrate install ./vcpkg install libwebp ``` -------------------------------- ### Build and Install Python SWIG Bindings for libwebp Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/_swig/README.md These commands build and install the Python SWIG bindings for libwebp. 'build_ext' compiles the C/C++ extensions, and 'install' places them in the specified prefix, making them available for import. ```shell $ python setup.py build_ext $ python setup.py install --prefix=pylocal ``` -------------------------------- ### Unix Build with makefile.unix Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/doc/building.md Compiles WebP binaries (cwebp, dwebp) and the static library (libwebp.a) on Unix-like systems with GNU tools installed. This method provides a simpler alternative to the autoconf-based installation. ```shell make -f makefile.unix ``` -------------------------------- ### Compile and Run JNI libwebp Example in Java Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/_swig/README.md Commands to compile the Java JNI example and then run it. Requires the libwebp.jar in the classpath. The '-Djava.library.path=.' argument ensures the JNI library can be found. ```shell $ javac -cp libwebp.jar libwebp_jni_example.java $ java -Djava.library.path=. -cp libwebp.jar:. libwebp_jni_example ``` -------------------------------- ### Build with CMake Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/doc/building.md Compiles libwebp, cwebp, dwebp, gif2webp, img2webp, webpinfo, and JS bindings using CMake. This requires a compiler and CMake, and involves creating a build directory, configuring with CMake, and then building and installing. ```shell $ sudo apt-get install build-essential cmake ``` ```shell mkdir build && cd build && cmake ../ make make install ``` ```shell cmake -DWEBP_BUILD_CWEBP=ON -DWEBP_BUILD_DWEBP=ON ../ ``` -------------------------------- ### Install WebP Libraries and Headers Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/CMakeLists.txt Installs the built WebP libraries and headers to the appropriate system directories. This includes executables, archives, and runtime libraries, along with public headers organized under a 'webp' subdirectory. It also exports targets for package configuration. ```cmake # Install the different headers and libraries. install( TARGETS ${INSTALLED_LIBRARIES} EXPORT ${PROJECT_NAME}Targets PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/webp INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) ``` -------------------------------- ### Example Usage of JNI libwebp Bindings in Java Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/_swig/README.md This Java example demonstrates how to load the JNI library and call functions from the libwebp library. It prints the decoder version and lists all available methods in the libwebp class. Ensure libwebp.jar is in the classpath and the JNI library is in the library path. ```java import com.google.webp.libwebp; import java.lang.reflect.Method; public class libwebp_jni_example { static { System.loadLibrary("webp_jni"); } /** * usage: java -cp libwebp.jar:. libwebp_jni_example */ public static void main(String argv[]) { final int version = libwebp.WebPGetDecoderVersion(); System.out.println("libwebp version: " + Integer.toHexString(version)); System.out.println("libwebp methods:"); final Method[] libwebpMethods = libwebp.class.getDeclaredMethods(); for (int i = 0; i < libwebpMethods.length; i++) { System.out.println(libwebpMethods[i]); } } } ``` -------------------------------- ### Install WebP Man Pages Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/CMakeLists.txt Installs the man pages for various WebP command-line tools. The installation is conditional on the WEBP_BUILD_ flag being enabled for each respective tool. Man pages are installed into the standard man directory structure. ```cmake # Install the man pages. set(MAN_PAGES cwebp.1 dwebp.1 gif2webp.1 img2webp.1 vwebp.1 webpmux.1 webpinfo.1) set(EXEC_BUILDS "CWEBP" "DWEBP" "GIF2WEBP" "IMG2WEBP" "VWEBP" "WEBPMUX" "WEBPINFO") list(LENGTH MAN_PAGES MAN_PAGES_LENGTH) math(EXPR MAN_PAGES_RANGE "${MAN_PAGES_LENGTH} - 1") foreach(I_MAN RANGE ${MAN_PAGES_RANGE}) list(GET EXEC_BUILDS ${I_MAN} EXEC_BUILD) if(WEBP_BUILD_${EXEC_BUILD}) list(GET MAN_PAGES ${I_MAN} MAN_PAGE) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/man/${MAN_PAGE} DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 COMPONENT doc) endif() endforeach() ``` -------------------------------- ### Build cwebp Executable (CMake) Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/CMakeLists.txt Builds the cwebp executable, used for encoding images to WebP format. It depends on exampleutil, imagedec, and the core webp library, and is installed to the binary directory. ```cmake if(WEBP_BUILD_CWEBP) # cwebp parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/examples "CWEBP_SRCS" "cwebp") add_executable(cwebp ${CWEBP_SRCS}) target_link_libraries(cwebp exampleutil imagedec webp) target_include_directories(cwebp PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}) install(TARGETS cwebp RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() ``` -------------------------------- ### Build dwebp Executable (CMake) Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/CMakeLists.txt Builds the dwebp executable, which is used for decoding WebP images. This executable depends on the exampleutil, imagedec, and imageenc libraries, and is installed to the binary directory. ```cmake if(WEBP_BUILD_DWEBP) # dwebp parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/examples "DWEBP_SRCS" "dwebp") add_executable(dwebp ${DWEBP_SRCS}) target_link_libraries(dwebp exampleutil imagedec imageenc) target_include_directories(dwebp PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src) install(TARGETS dwebp RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() ``` -------------------------------- ### CMake Project Integration Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/doc/building.md Shows how to integrate the WebP library into a CMake project after it has been installed. It involves using find_package to locate WebP, which then defines variables for include directories and libraries. ```cmake find_package(WebP) # WebP_INCLUDE_DIRS and WebP_LIBRARIES will be defined ``` -------------------------------- ### Getting cwebp Help Information Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/doc/tools.md Shows how to retrieve detailed usage instructions and a comprehensive list of available options for the cwebp encoder. This is useful for exploring advanced features and fine-tuning the encoding process. ```shell cwebp -longhelp ``` -------------------------------- ### Configuring pkg-config Files for WebP Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/CMakeLists.txt This CMake function automates the configuration and installation of pkg-config files. It takes a base filename, configures a template file, and installs the resulting .pc file into the pkgconfig directory. It also handles the removal of '-lm' for MSVC compatibility. ```cmake function(configure_pkg_config FILE) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.in" "${CMAKE_CURRENT_BINARY_DIR}/${FILE}" @ONLY) if(HAVE_MATH_LIBRARY) # MSVC doesn't have libm file(READ ${CMAKE_CURRENT_BINARY_DIR}/${FILE} data) string(REPLACE "-lm" "" data ${data}) file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${FILE} ${data}) endif() install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${FILE}" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) endfunction() ``` -------------------------------- ### Build img2webp Executable (CMake) Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/CMakeLists.txt Builds the img2webp executable for converting various image formats to WebP. This executable depends on multiple WebP utility libraries and is installed to the binary directory. ```cmake if(WEBP_BUILD_IMG2WEBP) # img2webp include_directories(${WEBP_DEP_IMG_INCLUDE_DIRS}) parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/examples "IMG2WEBP_SRCS" "img2webp") add_executable(img2webp ${IMG2WEBP_SRCS}) target_link_libraries(img2webp exampleutil imagedec imageioutil webp libwebpmux) target_include_directories(img2webp PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}) install(TARGETS img2webp RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() ``` -------------------------------- ### Serve WebP Demo Page with Python HTTP Server Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/webp_js/README.md Starts a Python HTTP server in the 'webp_js' directory to serve the demo HTML page. This allows you to access the WebP decoder demo in your browser. ```shell cd webp_js && python3 -m http.server 8080 ``` -------------------------------- ### Build gif2webp Executable (CMake) Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/CMakeLists.txt Builds the gif2webp executable, used for converting GIF images to WebP format. It requires additional include directories for GIF support and links against several WebP libraries, including libwebpmux, and is installed to the binary directory. ```cmake if(WEBP_BUILD_GIF2WEBP) # gif2webp include_directories(${WEBP_DEP_GIF_INCLUDE_DIRS}) parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/examples "GIF2WEBP_SRCS" "gif2webp") add_executable(gif2webp ${GIF2WEBP_SRCS}) target_link_libraries(gif2webp exampleutil imageioutil webp libwebpmux ${WEBP_DEP_GIF_LIBRARIES}) target_include_directories(gif2webp PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src) install(TARGETS gif2webp RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() ``` -------------------------------- ### Build anim_diff Utility with makefile.unix Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/doc/tools.md This snippet demonstrates how to build the anim_diff utility using the provided makefile.unix, which is a common method for compiling C/C++ projects on Unix-like systems. It requires the libgif development files to be installed. ```shell $ make -f makefile.unix examples/anim_diff ``` -------------------------------- ### Build libwebpmux Library (CMake) Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/CMakeLists.txt Constructs the libwebpmux shared library, which provides functionalities for manipulating WebP image metadata and features like animation. It links against the core webp library and is configured for installation with pkg-config support. ```cmake if(WEBP_BUILD_LIBWEBPMUX) parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/src/mux "WEBP_MUX_SRCS" "") add_library(libwebpmux ${WEBP_MUX_SRCS}) target_link_libraries(libwebpmux webp) target_include_directories(libwebpmux PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) set_version(src/mux/Makefile.am libwebpmux webpmux) set_target_properties( libwebpmux PROPERTIES PUBLIC_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/src/webp/mux.h;\ ${CMAKE_CURRENT_SOURCE_DIR}/src/webp/mux_types.h;\ ${CMAKE_CURRENT_SOURCE_DIR}/src/webp/types.h;") set_target_properties(libwebpmux PROPERTIES OUTPUT_NAME webpmux) list(APPEND INSTALLED_LIBRARIES libwebpmux) configure_pkg_config("src/mux/libwebpmux.pc") endif() ``` -------------------------------- ### WebP Encoding with Presets and Quality Tuning Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/doc/tools.md Provides an example of using a preset configuration to set encoding parameters suitable for specific image types (e.g., 'photo'). It also shows how to adjust the spatial noise shaping (sns) and filter strength (f) for further quality and compression optimization. ```shell cwebp -preset photo -sns 50 -f 60 input.jpg -o output.webp ``` -------------------------------- ### AnimEncoder API: Create Animated WebP Images (C) Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/doc/api.md Provides an example of creating animated WebP images using the AnimEncoder API. It involves initializing encoder options, creating a new encoder, adding frames with duration, assembling the animation, and cleaning up resources. ```c WebPAnimEncoderOptions enc_options; WebPAnimEncoderOptionsInit(&enc_options); // ... (Tune 'enc_options' as needed). WebPAnimEncoder* enc = WebPAnimEncoderNew(width, height, &enc_options); while() { WebPConfig config; WebPConfigInit(&config); // ... (Tune 'config' as needed). WebPAnimEncoderAdd(enc, frame, duration, &config); } WebPAnimEncoderAssemble(enc, webp_data); WebPAnimEncoderDelete(enc); // ... (Write the 'webp_data' to a file, or re-mux it further); ``` -------------------------------- ### Create Animated WebP using img2webp Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/doc/tools.md The img2webp utility converts a sequence of input images into an animated WebP file. This example demonstrates setting a loop count, specifying a lossy mode for one frame, setting a duration for another, and outputting to 'out.webp'. ```shell img2webp -loop 2 in0.png -lossy in1.jpg -d 80 in2.tiff -o out.webp ``` -------------------------------- ### Build with Gradle Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/doc/building.md Compiles libwebp, cwebp, dwebp, and webpmux_example using Gradle. This method requires a compiler and Gradle, and involves running the Gradle wrapper with the appropriate task. ```shell $ sudo apt-get install build-essential gradle ``` ```shell ./gradlew buildAllExecutables ``` -------------------------------- ### Example WebP Image Data Sequence (BNF) Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/doc/webp-lossless-bitstream-spec.txt Illustrates a possible sequence of data for a WebP image, starting with the RIFF header and followed by image size, transformation flags, color cache information, prefix codes, and LZ77-coded image data. ```bnf RIFF-header image-size %b1 subtract-green-tx %b1 predictor-tx %b0 color-cache-info %b0 prefix-codes lz77-coded-image ``` -------------------------------- ### Windows Build with nmake Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/doc/building.md Builds the WebP tools (cwebp.exe, dwebp.exe) and the static library (libwebp) for Windows using nmake. The build process automatically detects the target architecture (x86/x64) based on the available Visual Studio compiler. ```batch nmake /f Makefile.vc CFG=release-static RTLIBCFG=static OBJDIR=output ``` -------------------------------- ### Build WebP Project using Makefile.vc (Windows) Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/doc/tools.md This command builds the vwebp executable for Windows using the nmake build system and Makefile.vc. It specifies a release-static configuration and indicates the output path for the binary. ```shell nmake /f Makefile.vc CFG=release-static \ ../obj/x64/release-static/bin/vwebp.exe ``` -------------------------------- ### Apply Commit Message Hook Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/CONTRIBUTING.md Installs a Git commit message hook script that automatically adds an ID to commits. This helps in tracking contributions and linking them to review requests. ```shell curl -Lo .git/hooks/commit-msg https://chromium-review.googlesource.com/tools/hooks/commit-msg && chmod u+x .git/hooks/commit-msg ``` -------------------------------- ### Configure and Build WebP Project with Autoconf Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/doc/tools.md This sequence configures the WebP project using autoconf with the '--enable-everything' option, then builds the project. This is an alternative build method to using Makefiles. ```shell ./configure --enable-everything make ``` -------------------------------- ### Set Install RPATH for Shared Libraries Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/CMakeLists.txt Configures the runtime search path (RPATH) for shared libraries on systems where it's not already defined. This helps the system find shared libraries at runtime. ```cmake if(BUILD_SHARED_LIBS AND NOT DEFINED CMAKE_INSTALL_RPATH) set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") endif() ``` -------------------------------- ### Build WebP Utility Libraries (CMake) Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/CMakeLists.txt Defines and builds several static utility libraries for WebP image processing, including exampleutil, imageutil, imagedec, and imageenc. These libraries are essential for various WebP tools and rely on the core webp library and other dependencies. ```cmake if(WEBP_BUILD_ANIM_UTILS OR WEBP_BUILD_CWEBP OR WEBP_BUILD_DWEBP OR WEBP_BUILD_EXTRAS OR WEBP_BUILD_GIF2WEBP OR WEBP_BUILD_IMG2WEBP OR WEBP_BUILD_VWEBP OR WEBP_BUILD_WEBPMUX OR WEBP_BUILD_WEBPINFO) # Example utility library. parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/examples "EXAMPLEUTIL_SRCS" "example_util_[^ ]*") list(APPEND EXAMPLEUTIL_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/examples/stopwatch.h) add_library(exampleutil STATIC ${EXAMPLEUTIL_SRCS}) target_include_directories( exampleutil PUBLIC $) parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/imageio "IMAGEIOUTILS_SRCS" "imageio_util_[^ ]*") add_library(imageioutil STATIC ${IMAGEIOUTILS_SRCS}) target_link_libraries(imageioutil webp) # Image-decoding utility library. parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/imageio "IMAGEDEC_SRCS" "imagedec_[^ ]*") add_library(imagedec STATIC ${IMAGEDEC_SRCS}) target_link_libraries(imagedec imageioutil webpdemux webp ${WEBP_DEP_IMG_LIBRARIES}) # Image-encoding utility library. parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/imageio "IMAGEENC_SRCS" "imageenc_[^ ]*") add_library(imageenc STATIC ${IMAGEENC_SRCS}) target_link_libraries(imageenc imageioutil webp) set_property( TARGET exampleutil imageioutil imagedec imageenc PROPERTY INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/src) target_include_directories(imagedec PRIVATE ${WEBP_DEP_IMG_INCLUDE_DIRS}) target_include_directories(imageenc PRIVATE ${WEBP_DEP_IMG_INCLUDE_DIRS}) endif() ``` -------------------------------- ### Configure WebP JS Decoder with Emcmake Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/webp_js/README.md Configures the WEBP_JS project to build the JavaScript decoder using Emscripten and CMake. Ensure Emscripten SDK is installed and configured before running this command. ```shell cd webp_js && \ emcmake cmake -DWEBP_BUILD_WEBP_JS=ON ../ ``` -------------------------------- ### Display vwebp help message Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/doc/tools.md This command displays the help message for the `vwebp` visualization tool, outlining the options available for decoding and displaying WebP files using OpenGL. ```shell vwebp in_file [options] ``` -------------------------------- ### Clone libwebp Repository Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/CONTRIBUTING.md Fetches the latest version of the libwebp source code from its Git repository. This is the initial step for making any code modifications. ```shell git clone https://chromium.googlesource.com/webm/libwebp && cd libwebp ``` -------------------------------- ### Get WebP Image Information Source: https://context7.com/chai2010/webp/llms.txt Retrieves basic WebP image metadata without fully decoding the image, returning width, height, and alpha channel presence. Efficient for quick property checks. ```APIDOC ## Get WebP Image Information ### Description Retrieves basic WebP image metadata without fully decoding the image. Returns width, height, and alpha channel presence. This is efficient for quickly checking image properties without the overhead of full decoding. ### Method GET (or internal library function) ### Endpoint N/A (Library function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **data** ([]byte) - Required - The byte slice containing the WebP image data. ### Request Example ```go package main import ( "fmt" "io/ioutil" "log" "github.com/chai2010/webp" ) func main() { data, err := ioutil.ReadFile("./testdata/1_webp_ll.webp") if err != nil { log.Fatal(err) } width, height, hasAlpha, err := webp.GetInfo(data) if err != nil { log.Fatal(err) } fmt.Printf("Image dimensions: %dx%d\n", width, height) fmt.Printf("Has alpha channel: %v\n", hasAlpha) // Output: // Image dimensions: 400x301 // Has alpha channel: true } ``` ### Response #### Success Response (200) - **width** (int) - The width of the WebP image. - **height** (int) - The height of the WebP image. - **hasAlpha** (bool) - True if the image has an alpha channel, false otherwise. #### Response Example ```json { "width": 400, "height": 301, "hasAlpha": true } ``` ``` -------------------------------- ### WebP Mux Tool: Get Image Information Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/doc/tools.md This command uses the webpmux tool to extract basic information about a WebP file. The '-info' flag is used to display details about the input WebP file. ```shell webpmux -info INPUT ``` -------------------------------- ### Build webp Extras Library and Tools with CMake Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/CMakeLists.txt Configures the build for various webp extras, including a static library 'extras', and executables like 'get_disto', 'webp_quality', and 'vwebp_sdl'. It handles SDL2 dependency for vwebp_sdl and checks for SDL header compatibility. This section is active if WEBP_BUILD_EXTRAS is true. ```cmake if(WEBP_BUILD_EXTRAS) set(EXTRAS_MAKEFILE "${CMAKE_CURRENT_SOURCE_DIR}/extras") parse_makefile_am(${EXTRAS_MAKEFILE} "WEBP_EXTRAS_SRCS" "libwebpextras_la") parse_makefile_am(${EXTRAS_MAKEFILE} "GET_DISTO_SRCS" "get_disto") parse_makefile_am(${EXTRAS_MAKEFILE} "WEBP_QUALITY_SRCS" "webp_quality") parse_makefile_am(${EXTRAS_MAKEFILE} "VWEBP_SDL_SRCS" "vwebp_sdl") # libextras add_library(extras STATIC ${WEBP_EXTRAS_SRCS}) target_include_directories( extras PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src) # get_disto add_executable(get_disto ${GET_DISTO_SRCS}) target_link_libraries(get_disto imagedec) target_include_directories(get_disto PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/src) # webp_quality add_executable(webp_quality ${WEBP_QUALITY_SRCS}) target_link_libraries(webp_quality exampleutil imagedec extras) target_include_directories(webp_quality PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) # vwebp_sdl find_package(SDL2 QUIET) if(WEBP_BUILD_VWEBP AND SDL2_FOUND) add_executable(vwebp_sdl ${VWEBP_SDL_SRCS}) target_link_libraries(vwebp_sdl ${SDL2_LIBRARIES} imageioutil webp) target_include_directories( vwebp_sdl PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/src ${SDL2_INCLUDE_DIRS}) set(WEBP_HAVE_SDL 1) target_compile_definitions(vwebp_sdl PUBLIC WEBP_HAVE_SDL) set(CMAKE_REQUIRED_INCLUDES "${SDL2_INCLUDE_DIRS}") check_c_source_compiles( "\n #define SDL_MAIN_HANDLED\n #include \"SDL.h\"\n int main(void) {\n return 0;\n }\n " HAVE_JUST_SDL_H) set(CMAKE_REQUIRED_INCLUDES) if(HAVE_JUST_SDL_H) target_compile_definitions(vwebp_sdl PRIVATE WEBP_HAVE_JUST_SDL_H) endif() endif() endif() ``` -------------------------------- ### Get WebP Decoder Version in Go Source: https://context7.com/chai2010/webp/llms.txt Retrieves the version of the underlying libwebp decoder library. The version is returned as a single integer that can be parsed into major, minor, and revision components. This is useful for compatibility checks or reporting. ```go package main import ( "fmt" "github.com/chai2010/webp" ) func main() { version := webp.WebPGetDecoderVersion() major := (version >> 16) & 0xFF minor := (version >> 8) & 0xFF revision := version & 0xFF fmt.Printf("WebP Decoder Version: %d.%d.%d\n", major, minor, revision) fmt.Printf("Hex version: 0x%06X\n", version) // Output example: WebP Decoder Version: 1.4.0 } ``` -------------------------------- ### Build vwebp Executable (CMake) Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/CMakeLists.txt Builds the vwebp executable, a viewer for WebP images that utilizes OpenGL and GLUT. It requires specific include directories and links against various graphics and WebP libraries. ```cmake if(WEBP_BUILD_VWEBP) # vwebp find_package(GLUT) if(GLUT_FOUND) include_directories(${WEBP_DEP_IMG_INCLUDE_DIRS}) parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/examples "VWEBP_SRCS" "vwebp") add_executable(vwebp ${VWEBP_SRCS}) target_link_libraries( vwebp ${OPENGL_LIBRARIES} exampleutil GLUT::GLUT imageioutil webp webpdemux) target_include_directories( vwebp PRIVATE ${GLUT_INCLUDE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/src ``` -------------------------------- ### MIPS Linux Build Configuration Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/doc/building.md Configures and builds WebP for MIPS Linux, targeting specific architectures like mips32r5 or mips64r6. It involves setting up the toolchain in the PATH and defining MIPS-specific CFLAGS and LDFLAGS for both 32-bit and 64-bit builds. ```shell # Add toolchain to PATH export PATH=$PATH:/path/to/toolchain/bin # 32-bit build for mips32r5 (p5600) HOST=mips-mti-linux-gnu MIPS_CFLAGS="-O3 -mips32r5 -mabi=32 -mtune=p5600 -mmsa -mfp64 \ -msched-weight -mload-store-pairs -fPIE" MIPS_LDFLAGS="-mips32r5 -mabi=32 -mmsa -mfp64 -pie" # 64-bit build for mips64r6 (i6400) HOST=mips-img-linux-gnu MIPS_CFLAGS="-O3 -mips64r6 -mabi=64 -mtune=i6400 -mmsa -mfp64 \ -msched-weight -mload-store-pairs -fPIE" MIPS_LDFLAGS="-mips64r6 -mabi=64 -mmsa -mfp64 -pie" ./configure --host=${HOST} --build=`config.guess` \ CC="${HOST}-gcc -EL" \ CFLAGS="$MIPS_CFLAGS" \ LDFLAGS="$MIPS_LDFLAGS" make make install ``` -------------------------------- ### Mux API: Get Image and Color Profile from WebP File (C) Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/doc/api.md Shows how to create a WebPMux object from existing WebP data, extract frame image data, and retrieve the ICC profile chunk. It includes data cleanup. ```c int copy_data = 0; // ... (Read data from file). WebPMux* mux = WebPMuxCreate(&data, copy_data); WebPMuxGetFrame(mux, 1, &image); // ... (Consume image; e.g. call WebPDecode() to decode the data). WebPMuxGetChunk(mux, "ICCP", &icc_profile); // ... (Consume icc_profile). WebPMuxDelete(mux); free(data); ``` -------------------------------- ### Reading Color Table Size (C) Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/doc/webp-lossless-bitstream-spec.txt This C code snippet demonstrates how to read the size of the color table from the bitstream. It reads an 8-bit value and adds 1 to get the actual size, which specifies the number of unique colors or entries in the color table. ```c // 8-bit value for the color table size int color_table_size = ReadBits(8) + 1; ``` -------------------------------- ### Mux API: Create and Assemble WebP Data with Metadata (C) Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/doc/api.md Demonstrates creating a WebPMux object, setting image data, ICC profile, and XMP metadata, then assembling it into WebP RIFF format. It handles data copying and cleanup. ```c int copy_data = 0; WebPMux* mux = WebPMuxNew(); // ... (Prepare image data). WebPMuxSetImage(mux, &image, copy_data); // ... (Prepare ICC profile data). WebPMuxSetChunk(mux, "ICCP", &icc_profile, copy_data); // ... (Prepare XMP metadata). WebPMuxSetChunk(mux, "XMP ", &xmp, copy_data); // Get data from mux in WebP RIFF format. WebPMuxAssemble(mux, &output_data); WebPMuxDelete(mux); // ... (Consume output_data; e.g. write output_data.bytes to file). WebPDataClear(&output_data); ``` -------------------------------- ### Generate HTML Docs with kramdown and CodeRay Syntax Highlighting Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/doc/specs_generation.md Generates HTML documentation with syntax highlighting enabled for code blocks using kramdown and CodeRay. This command specifies the input file, template, and enables CSS styling for syntax highlighting, including line numbers and a default language. ```shell kramdown doc/webp-lossless-bitstream-spec.txt --template \ doc/template.html --coderay-css style --coderay-default-lang c > \ doc/output/webp-lossless-bitstream-spec.html ``` -------------------------------- ### Basic WebP Encoding with cwebp Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/doc/tools.md Demonstrates the fundamental command to convert an input image (e.g., PNG) to WebP format with a specified quality level. The output is saved to a designated file. This is the most common usage scenario for basic image compression. ```shell cwebp input.png -q 80 -o output.webp ``` -------------------------------- ### Decode WebP to PPM using dwebp Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/doc/tools.md This command decodes a WebP image file to a PPM image file using the `dwebp` tool. It's part of the example usage to verify decoding accuracy by comparing the output with a reference file using `diff`. ```shell cd examples ./dwebp test.webp -ppm -o test.ppm diff test.ppm test_ref.ppm ``` -------------------------------- ### WebP Advanced Encoding with WebPConfig and WebPPicture (C) Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/doc/api.md Demonstrates an advanced encoding workflow using `WebPConfig` for settings and `WebPPicture` for input data. This API allows for detailed control over encoding parameters like presets, quality, and image properties. It involves initializing configuration and picture structures, allocating memory, setting up a writer, compressing the image, and freeing resources. ```c #include // Setup a config, starting form a preset and tuning some additional // parameters WebPConfig config; if (!WebPConfigPreset(&config, WEBP_PRESET_PHOTO, quality_factor)) { return 0; // version error } // ... additional tuning config.sns_strength = 90; config.filter_sharpness = 6; config_error = WebPValidateConfig(&config); // not mandatory, but useful // Setup the input data WebPPicture pic; if (!WebPPictureInit(&pic)) { return 0; // version error } pic.width = width; pic.height = height; // allocated picture of dimension width x height if (!WebPPictureAlloc(&pic)) { return 0; // memory error } // at this point, 'pic' has been initialized as a container, // and can receive the Y/U/V samples. // Alternatively, one could use ready-made import functions like // WebPPictureImportRGB(), which will take care of memory allocation. // In any case, past this point, one will have to call // WebPPictureFree(&pic) to reclaim memory. // Set up a byte-output write method. WebPMemoryWriter, for instance. WebPMemoryWriter wrt; WebPMemoryWriterInit(&wrt); // initialize 'wrt' pic.writer = MyFileWriter; pic.custom_ptr = my_opaque_structure_to_make_MyFileWriter_work; // Compress! int ok = WebPEncode(&config, &pic); // ok = 0 => error occurred! WebPPictureFree(&pic); // must be called independently of the 'ok' result. // output data should have been handled by the writer at that point. // -> compressed data is the memory buffer described by wrt.mem / wrt.size // deallocate the memory used by compressed data WebPMemoryWriterClear(&wrt); ``` -------------------------------- ### Commit Changes Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/CONTRIBUTING.md Stages all modified files and creates a new commit with a specified message. This prepares the changes for submission. ```shell git commit -a -m "Set commit message here" ``` -------------------------------- ### WebP Get Image Information (C) Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/doc/api.md Provides a way to retrieve the dimensions (width and height) of a WebP image without performing the full decoding process. This function is useful for pre-allocating buffers or for simply inspecting WebP file metadata. It takes the WebP data buffer and its size as input. ```c int WebPGetInfo(const uint8_t* data, size_t data_size, int* width, int* height); ``` -------------------------------- ### Display dwebp help message Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/doc/tools.md This command displays the help message for the `dwebp` decoding tool, listing all available options for converting WebP files to various image formats and controlling the decoding process. ```shell dwebp -h ``` -------------------------------- ### WebP Mux Tool: Set Animation Duration for Frame Interval Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/doc/tools.md This command demonstrates setting a uniform duration for a range of frames in an animated WebP file using webpmux. The '-duration' option with 'duration,start,end' specifies the duration and the frame interval, and '-o' indicates the output file. ```shell webpmux -duration duration,start,end INPUT -o OUTPUT ``` -------------------------------- ### Display webpinfo help message Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/doc/tools.md This command shows the usage and available options for the `webpinfo` tool, which is used to analyze the chunk-level structure and bitstream header information of WebP files. ```shell webpinfo [options] in_files ``` -------------------------------- ### Get WebP Image Information in Go Source: https://context7.com/chai2010/webp/llms.txt Retrieves basic WebP image metadata, including width, height, and alpha channel presence, without fully decoding the image. This provides an efficient way to check image properties for tasks like thumbnail generation. Input is the raw WebP byte data, output is width, height, and a boolean indicating alpha channel presence. ```go package main import ( "fmt" "io/ioutil" "log" "github.com/chai2010/webp" ) func main() { data, err := ioutil.ReadFile("./testdata/1_webp_ll.webp") if err != nil { log.Fatal(err) } width, height, hasAlpha, err := webp.GetInfo(data) if err != nil { log.Fatal(err) } fmt.Printf("Image dimensions: %dx%d\n", width, height) fmt.Printf("Has alpha channel: %v\n", hasAlpha) // Output: // Image dimensions: 400x301 // Has alpha channel: true } ``` -------------------------------- ### CMake: Build Sharpyuv Library Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/CMakeLists.txt This CMake code snippet defines and configures the 'sharpyuv' library. It parses source files from a Makefile.am, adds it as a library, links dependencies, sets version information, configures include directories, and sets properties for public headers and pkg-config files. ```cmake parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/sharpyuv "WEBP_SHARPYUV_SRCS" "") add_library(sharpyuv ${WEBP_SHARPYUV_SRCS}) target_link_libraries(sharpyuv ${SHARPYUV_DEP_LIBRARIES}) set_version(sharpyuv/Makefile.am sharpyuv sharpyuv) target_include_directories( sharpyuv PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src) set_target_properties( sharpyuv PROPERTIES PUBLIC_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/sharpyuv/sharpyuv.h;\\ ${CMAKE_CURRENT_SOURCE_DIR}/sharpyuv/sharpyuv_csp.h") configure_pkg_config("sharpyuv/libsharpyuv.pc") install( TARGETS sharpyuv EXPORT ${PROJECT_NAME}Targets PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/webp/sharpyuv INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/webp ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) ``` -------------------------------- ### Build webpinfo Executable with CMake Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/CMakeLists.txt Configures and builds the webpinfo executable using CMake. It parses makefile rules to identify source files and links against necessary utility libraries. This target is built only if WEBP_BUILD_WEBPINFO is enabled. ```cmake if(WEBP_BUILD_WEBPINFO) # webpinfo include_directories(${WEBP_DEP_IMG_INCLUDE_DIRS}) parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/examples "WEBPINFO_SRCS" "webpinfo") add_executable(webpinfo ${WEBPINFO_SRCS}) target_link_libraries(webpinfo exampleutil imageioutil) target_include_directories(webpinfo PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/src) install(TARGETS webpinfo RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() ``` -------------------------------- ### Load and Save WebP Files in Go Source: https://context7.com/chai2010/webp/llms.txt Provides high-level functions to load WebP images from files into Go's image.Image interface and save Go images to WebP files. It supports various compression options, including quality-based lossy and lossless compression. Dependencies include the standard Go image package and 'github.com/chai2010/webp'. ```go package main import ( "fmt" "image" "image/color" "log" "github.com/chai2010/webp" ) func main() { // Load WebP file directly img, err := webp.Load("input.webp") if err != nil { log.Fatal(err) } fmt.Printf("Loaded image: %dx%d\n", img.Bounds().Dx(), img.Bounds().Dy()) // Load only configuration (dimensions, color model) config, err := webp.LoadConfig("input.webp") if err != nil { log.Fatal(err) } fmt.Printf("Image config: %dx%d, color model: %v\n", config.Width, config.Height, config.ColorModel) // Create a new image newImg := image.NewRGBA(image.Rect(0, 0, 200, 200)) for y := 0; y < 200; y++ { for x := 0; x < 200; x++ { newImg.Set(x, y, color.RGBA{ R: uint8(x), G: uint8(y), B: 128, A: 255, }) } } // Save with high quality lossy compression err = webp.Save("output_quality95.webp", newImg, &webp.Options{ Lossless: false, Quality: 95, }) if err != nil { log.Fatal(err) } // Save with lossless compression err = webp.Save("output_lossless.webp", newImg, &webp.Options{ Lossless: true, }) if err != nil { log.Fatal(err) } log.Println("Saved images successfully") } ``` -------------------------------- ### WebP Encoding with Advanced Options Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/doc/tools.md Demonstrates several advanced encoding options including resizing, cropping, enabling multi-threading for faster encoding, and reducing memory usage at the cost of speed. Also shows how to enable PSNR distortion printing. ```shell cwebp input.png -resize 800 600 -crop 100 100 400 400 -mt -low_memory -print_psnr -o output.webp ``` -------------------------------- ### Build Utility Tools Options Source: https://github.com/chai2010/webp/blob/master/internal/libwebp-1.4.0/CMakeLists.txt Configures build options for various WebP utility tools. Each option allows users to enable or disable the build of specific command-line tools and libraries. ```cmake option(WEBP_BUILD_ANIM_UTILS "Build animation utilities." ON) option(WEBP_BUILD_CWEBP "Build the cwebp command line tool." ON) option(WEBP_BUILD_DWEBP "Build the dwebp command line tool." ON) option(WEBP_BUILD_GIF2WEBP "Build the gif2webp conversion tool." ON) option(WEBP_BUILD_IMG2WEBP "Build the img2webp animation tool." ON) option(WEBP_BUILD_VWEBP "Build the vwebp viewer tool." ON) option(WEBP_BUILD_WEBPINFO "Build the webpinfo command line tool." ON) option(WEBP_BUILD_LIBWEBPMUX "Build the libwebpmux library." ON) option(WEBP_BUILD_WEBPMUX "Build the webpmux command line tool." ON) option(WEBP_BUILD_EXTRAS "Build extras." ON) option(WEBP_BUILD_WEBP_JS "Emscripten build of webp.js." OFF) ```