IMG_SaveWEBP_IO(3)

πŸ“¦
version 3.4.8 Β· 5 versions
, in fedora 43, fedora 44

πŸ’Ύ IMG_SaveWEBP_IO(3) β€” the SDL_image3 glow-up where you yeet a surface into WEBP data through an SDL_IOStream

okay bestie, gather round, because this one is lowkey the cooler, more flexible sibling of the save-to-a-filename function and it deserves its moment πŸ’…


✨ NAME ✨

IMG_SaveWEBP_IO β€” save an SDL_Surface into WEBP image data, via an SDL_IOStream. that's it, that's the whole job, and it ate 🫢


πŸŽ€ SYNOPSIS πŸŽ€

#include <SDL3_image/SDL_image.h>

bool IMG_SaveWEBP_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio, float quality);

🌸 DESCRIPTION 🌸

so like, if all you wanna do is save straight to a filename, you literally do not need this one β€” just use IMG_SaveWEBP() instead and go live your life, queen πŸ‘‘

but if you're the kind of main character who's writing into a memory buffer, a custom stream, or literally anywhere that isn't a plain old file path, then IMG_SaveWEBP_IO is your girl. it takes your surface and pushes the WEBP data out through an SDL_IOStream that you provide. iconic.

one thing you need to know before you go: if closeio is true, then dst will be closed before returning β€” whether this function succeeds or not. no takebacksies, no exceptions, it's getting closed either way. so don't come crying to me if you were planning to reuse that stream afterward 😭


πŸ¦‹ FUNCTION PARAMETERS πŸ¦‹

  • surface β€” the SDL_Surface you wanna save. your canvas, your art, your moment ✨
  • dst β€” the SDL_IOStream the image data gets written to. this is the destination, the vibes-receptacle, the place where the bytes go 🌈
  • closeio β€” pass true to close/free the SDL_IOStream before returning, or false to leave it open like a considerate friend who closes the door quietly on their way out πŸšͺ
  • quality β€” a number between 0 and 100. and the meaning flips depending on which mode you're in, so pay attention bestie:
    • for lossy, 0 gives you the smallest file size and 100 gives you the largest πŸ“‰πŸ“ˆ
    • for lossless, this parameter is actually about how much effort goes into the compression: 0 is the fastest but produces larger files compared to the slowest-but-best 100 πŸ’βž‘οΈπŸ‡

πŸ’– RETURN VALUE πŸ’–

returns true on success or false on failure. and if you get a false, do not just sit there guessing β€” call SDL_GetError() for more info, because she will tell you exactly what went wrong πŸ”


πŸ‘‘ AVAILABILITY πŸ‘‘

this function has been available since SDL_image 3.4.0. so if you're on anything older, sorry babe, she's not there yet πŸ™ˆ


πŸ”₯ SEE ALSO πŸ”₯

  • IMG_SaveWEBP(3) β€” the filename-flavored version of this exact vibe. go check her out too πŸ’œ

no cap: closeio closing your stream on failure too is the kind of detail that ruins your whole afternoon if you forget it. remember it. tattoo it. periodt. πŸ’€

and that's the whole page, bestie πŸŽ€ this was written for SDL_image, version 3.4.8 β€” mwah, go save some WEBP files, you've got this πŸŒŸπŸ’–

πŸ“¦ where this page comes from