Image Dominant Color and HEIC Support in Laravel 13.24
Laravel #Laravel 13.24 #Image API #HEIC #Validation #Eloquent #Performance

Image Dominant Color and HEIC Support in Laravel 13.24

4 min read Mohamed Said Mohamed Said

Laravel 13.24 was released on August 4, 2026, bringing meaningful additions to the image API, Eloquent query builder, and validation layer — plus a performance fix that could save your app from multi-minute stalls on large payloads.

Dominant Color Detection

The first-party image API now exposes a dominantColor() method. It downsamples the image to a single pixel and returns the result as a hex string, making it ideal for placeholder backgrounds while a full image loads.

use Illuminate\Support\Facades\Image;

$color = Image::fromPath(storage_path('app/photo.jpg'))->dominantColor();
// "#8a6f4c"

The result is memoized per instance, and any pending transformations run before sampling — so you get the color of the image you are about to store, not the original. You can also pass 'dominant' as the background argument to contain() or rotate(), filling letterbox bars or rotation corners with the image's own color automatically:

Image::fromUpload($request->file('photo'))
    ->contain(1200, 800, background: 'dominant')
    ->store('photos');

HEIC and AVIF Input/Output

Previously, AVIF files were rejected on input and HEIC/HEIF were unsupported in both directions, meaning iPhone photos had to be converted before reaching the framework. Laravel 13.24 fixes this:

  • AVIF, HEIC, and HEIF are now accepted as inputs.
  • toHeic() and optimize('heic') are available as outputs.
  • All three formats are recognized by the image validation rule.
Image::fromPath(storage_path('app/photo.heic'))
    ->usingImagick()
    ->cover(1200, 800)
    ->toAvif()
    ->quality(80)
    ->store('photos');

Note: HEIC processing requires an Imagick build with the HEIC codec compiled in. image/heif MIME types are normalized to .heic on storage.

modelKeys() on the Eloquent Query Builder

Eloquent collections have long had modelKeys(), but retrieving primary keys directly from a query required hardcoding pluck('id'). The query builder now supports it natively:

$ids = Post::query()->where('published', true)->modelKeys();
// [1, 2, 3]

It uses the model's qualified key name, so custom $primaryKey values and joined queries resolve correctly without any column hardcoding.

New array_keys Validation Rule

The existing Rule::array() rejects unexpected keys but reports a generic failure message. The new array_keys rule focuses solely on key constraints and provides a clearer error:

$request->validate([
    'options' => Rule::arrayKeys(['sort', 'direction']),
]);

Given ['sort' => 'name', 'colour' => 'red'], the message reads: "The options field must only contain the following keys: sort, direction."

Custom messages can use :values (accepted keys) or :unexpected (the offending keys), which is especially useful in API responses:

$request->validate(
    ['options' => Rule::arrayKeys(['sort', 'direction'])],
    ['options.array_keys' => 'The :attribute field may not contain :unexpected.']
);
// The options field may not contain colour.

Wildcard Validation Performance Fix

Expanding foo.*.bar rules was quadratic in the number of expanded attributes. At 8,000 array items (roughly 1.1 MB), validation could take over 85 seconds — before a single rule ran. The fix moves the merge logic into a method that takes the accumulator by reference:

| Items | Before | After | |-------|---------|--------| | 1,000 | 0.98s | 0.11s | | 4,000 | 18.59s | 0.47s | | 8,000 | 85.13s | 0.98s |

Note that explodeWildcardRules() no longer calls mergeRulesForAttribute(), so overrides of that method will no longer affect wildcard expansion.

Key Takeaways

  • dominantColor() returns a hex string and works as a background value in contain() and rotate().
  • HEIC and AVIF are now fully supported for input and output; Imagick with the HEIC codec is required for HEIC.
  • modelKeys() on the query builder eliminates the need to hardcode primary key column names.
  • The array_keys rule gives precise, actionable validation messages for unexpected array keys.
  • The wildcard validation fix reduces an 85-second stall to under 1 second for 8,000-item arrays.
  • Arr::forget() now correctly removes the intended keys when processing mixed dotted and top-level keys.

Source: Laravel News — Laravel 13.24.0

Found this useful?

Frequently Asked Questions

3 questions
Q01 Does HEIC image support in Laravel 13.24 work with any server setup?
No. HEIC processing requires that your server's Imagick extension is compiled with the HEIC codec. If that codec is absent, HEIC input and output will not work even after upgrading to Laravel 13.24.
Q02 What is the difference between the new array_keys rule and the existing Rule::array() in Laravel?
Rule::array() validates that a field is an array and optionally restricts its keys, but reports a generic failure message. The new array_keys rule focuses only on key constraints and provides a specific message naming the unexpected keys, including an :unexpected placeholder for custom messages.
Q03 Will the wildcard validation fix in Laravel 13.24 affect applications that override mergeRulesForAttribute()?
Yes. The fix moves wildcard expansion logic so that explodeWildcardRules() no longer routes through mergeRulesForAttribute(). If your application overrides that method, the override will no longer affect wildcard rule expansion.

Continue reading

More Articles

View all