Performance
Results
Laravel Go Image runs 25 of the 27 benchmarked operations faster than Intervention Image 4.4.2 with the GD driver. It encodes GIFs 19 times faster, blurs 8 times faster, and reduces colors 15 times faster. Only JPEG and PNG decoding are slower.
These results come from a Linux machine with 2 CPUs, Go 1.27.4, PHP 8.4.28, and GD 2.3.3. Go spreads most operations over every CPU, while GD uses one, so results depend on the number of CPUs.
| Operation | Go (ms) | PHP (ms) | Go is |
|---|---|---|---|
| decode JPEG | 37 | 17 | 2.2× slower |
| decode PNG | 56 | 48 | 1.2× slower |
| encode JPEG | 22 | 34 | 1.5× faster |
| encode PNG | 270 | 830 | 3.1× faster |
| encode WebP | 54 | 262 | 4.9× faster |
| encode GIF | 33 | 612 | 18.6× faster |
| thumbnail | 30 | 37 | 1.2× faster |
| scale | 29 | 71 | 2.4× faster |
| cover | 15 | 47 | 3.1× faster |
| contain | 36 | 77 | 2.2× faster |
| crop | 7.2 | 66 | 9.1× faster |
| rotate 90° | 23 | 99 | 4.2× faster |
| rotate 45° | 109 | 311 | 2.9× faster |
| flip | 20 | 26 | 1.3× faster |
| grayscale | 13 | 44 | 3.4× faster |
| brightness | 5.8 | 51 | 8.7× faster |
| contrast | 5.9 | 64 | 10.9× faster |
| gamma | 5.8 | 161 | 27.9× faster |
| colorize | 18 | 51 | 2.8× faster |
| invert | 6.5 | 48 | 7.4× faster |
| blur | 94 | 786 | 8.4× faster |
| sharpen | 57 | 183 | 3.2× faster |
| pixelate | 40 | 44 | 1.1× faster |
| reduce colors | 29 | 415 | 14.5× faster |
| insert | 3.2 | 26 | 8.2× faster |
| draw shapes | 14 | 28 | 2.0× faster |
| text | 2.6 | 28 | 10.9× faster |
What the benchmark measures
Both sides read the same inputs: a generated 1920x1080 test image with smooth gradients and noise, saved as JPEG and PNG, a 200x100 translucent logo, and the Go Regular font. Each operation runs once to warm up, then repeats for at least 5 runs and up to 50 runs or one second, and the run reports its median. The benchmark runs each side three times, and the table and charts show the median of the three runs, so one noisy run doesn't skew them.
Every operation except the decode and thumbnail ones starts from a copy of an already decoded photo, so it doesn't measure decoding. The PHP side copies the decoded image with clone, and the Go side with Clone.
WebP encoding on both sides is lossy at quality 75. The Go numbers use the system libwebp. Without it, the package falls back to libwebp in WebAssembly, which took 241 ms, a little faster than GD's 262 ms. See WebP encoding.
Where PHP is faster
GD decodes JPEG with libjpeg-turbo, which uses SIMD instructions. The package's JPEG decoder reads baseline scans with a fast bit reader and lookup tables, and renders the pixels on every CPU, but the entropy decoding of a scan can't be split across CPUs, and without SIMD it takes about half of the decode time. JPEG decoding still takes about twice as long as GD's.
PNG decoding spends most of its time inflating zlib data. The package inflates with github.com/klauspost/compress on one goroutine while it filters rows on another, but a single zlib stream can't be split, and C's zlib inflates faster than Go, so PNG decoding takes about 1.2 times as long.
Operations that decode a JPEG to make it smaller, such as the thumbnail, avoid most of that cost. The package decodes JPEGs lazily and renders them at 1/2, 1/4, or 1/8 scale when an operation such as Cover or Scale shrinks them enough, rendering only the area it keeps, so the thumbnail is faster than GD's.
Running the benchmarks
The benchmarks live in the repository's benchmarks directory. run.sh prepares the inputs, runs both sides, and redraws the charts in art/. It needs Go, PHP with GD, and Composer:
./benchmarks/run.sh