And an optimal solution IMHO would be for the origin server to simply return 302 to a specific resource, selected upon the value of the Accept header:
GET /thumb.php?id=kekw HTTP/1.1
Accept: image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8
HTTP/1.1 302 Found
Location: /media/thumb.jpg?id=kekw
Vary: Accept
GET /media/thumb.jpg HTTP/1.1
Content-Type: image/jpeg