Go supports multimedia and graphics through its standard image packages for 2D raster work, plus third-party libraries for games (Ebitengine), GUIs (Fyne, Gio), OpenGL and SDL bindings, audio playback and video processing. It is not a dedicated graphics language, but it is well suited to image pipelines, servers that process media, and 2D games.
The standard library handles decoding, drawing and encoding of common image formats. For real-time graphics, audio or video, you will typically use a community library or call a native tool.
The image, image/color, image/draw, image/png, image/jpeg and image/gif packages cover creating, decoding, drawing on and encoding images. Extra formats and text rendering live in golang.org/x/image.
This program generates a PNG with a horizontal gradient:
image.NewRGBA allocates a pixel buffer, Set writes one pixel, and png.Encode writes the file. For speed on large images, write directly into img.Pix instead of calling Set per pixel.
To decode an unknown file, import the format packages for their side effects and call image.Decode:
The standard library does not include high-quality resizing. Use golang.org/x/image/draw (for example draw.CatmullRom.Scale), a library such as github.com/disintegration/imaging, or a libvips binding for heavy workloads. When you accept uploaded images on a server, limit the decoded dimensions as well as the file size, because a small compressed file can expand to a very large bitmap.
Ebitengine (github.com/hajimehoshi/ebiten/v2) is the most widely used 2D game library for Go. It runs on desktop, mobile, consoles and WebAssembly. You implement three methods of the ebiten.Game interface:
Update runs the game logic at a fixed rate, Draw renders each frame, and Layout returns the logical screen size, which is scaled to the window. Ebitengine also provides input, sprite drawing, shaders and audio support.
Choose the library by what you are building:
| Need | Options |
|---|---|
| Desktop and mobile GUI apps | Fyne (fyne.io/fyne/v2), Gio (gioui.org) |
| 2D games | Ebitengine, raylib bindings (raylib-go) |
| OpenGL or windowing | go-gl bindings with GLFW |
| SDL2 window, input and audio | go-sdl2 |
| Vector drawing to image or PDF | fogleman/gg, tdewolff/canvas |
| Charts | gonum.org/v1/plot |
Libraries based on OpenGL, GLFW or SDL use cgo, so you need a C toolchain and the native libraries installed. Pure-Go options such as Ebitengine on several platforms, Gio and image are easier to cross-compile. Always call GUI and OpenGL functions from the OS main thread; in Go this usually means calling runtime.LockOSThread() in an init function or at the start of main, which most libraries document.
For audio, github.com/ebitengine/oto plays raw PCM sound and decoders such as github.com/hajimehoshi/go-mp3 read MP3 files. The beep library builds higher-level playback on top. Check each project's documentation for supported formats and platforms.
Go has no video codec in its standard library. The practical approaches are:
ffmpeg with os/exec for transcoding, thumbnails and clipping. This is simple and robust, and works well in job workers.net/http and let a transcoding tool produce the segments.Go's goroutines suit media pipelines: run a bounded pool of workers, each handling one file, and use context to cancel long jobs.
pprof and go test -bench before optimising pixel loops.runtime.NumCPU().Go has OpenGL and Vulkan bindings and some engines, but the 3D ecosystem is small. Go is much stronger for 2D games and tools.
No. Use golang.org/x/image/draw, imaging, or libvips for resizing and filters.
Not always. The standard image packages, Gio and Ebitengine on many platforms avoid cgo, while OpenGL, GLFW and SDL bindings need it.
Run FFmpeg as a subprocess for most cases, and use a cgo binding only when you need direct frame access.
Go handles multimedia through the standard image packages, Ebitengine for 2D games, Fyne and Gio for interfaces, bindings for OpenGL and SDL, and FFmpeg for video. Choose pure-Go libraries when you want easy cross-compilation, lean on goroutines for batch processing, and limit untrusted input.