Is Webp broken? [ Solved ]

I’ve noticed that SDL_Image can’t open webp on my machine. Is it broken for everyone, or just X11 Linux, or is it something that I’ve done wrong?

I have installed libwebp-dev and libwebp7, added IMG_INIT_WEBP to the IMG_Init call, and I’ve tested against several webp images (though all downloaded from google images), but all attempts to view through SDL_image have failed.

I am running SDL3 and SDL3_image that was built using the default CMake call. It looks like SDL_image has had support for webp images since 2011, is there perhaps an argument that I need to pass at build time?

Here’s some minimal code that has the issue:

#include <SDL3/SDL.h>
#include <SDL3_image/SDL_image.h>

int main(int argc, char ** argv)
{
	SDL_Init(SDL_INIT_VIDEO);
	IMG_Init(IMG_INIT_PNG|IMG_INIT_JPG|IMG_INIT_WEBP);
	SDL_Window * win = SDL_CreateWindow("Small Image Viewer", 400, 400, SDL_WINDOW_RESIZABLE);
	SDL_Renderer * screen = SDL_CreateRenderer(win, 0);
	SDL_SetRenderVSync(screen, 1);

	SDL_Texture * image = NULL;
	SDL_FRect pos = {0, 0, 10, 10};
	if(argc == 2)
	{
		image = IMG_LoadTexture(screen, argv[1]);
		SDL_GetTextureSize(image, &pos.w, &pos.h);
		if(!image)
		{
			SDL_Log("Failed to load %s", argv[1]);
		}
	}

	bool run = true;
	while(run)
	{
		SDL_Event ev;
		while(SDL_PollEvent(&ev))
		{
			switch(ev.type)
			{
				case SDL_EVENT_QUIT:
					run = false;
					break;
			}
		}
		SDL_RenderClear(screen);
		SDL_RenderTexture(screen, image, NULL, &pos);
		SDL_RenderPresent(screen);
	}
	if(image)
	{
		SDL_DestroyTexture(image);
	}
	IMG_Quit();
	SDL_Quit();
}

I also tried compiling with -lwebp with no effect:
g++ main.cpp -lSDL3 -lSDL3_image -lwebp

Sorry, the solution is just that the SDL_Image should be rebuilt after installing libwebp, the default cmake settings will check your system for libwebp before adding support.

1 Like