Skip to content

Blade Components ​

The package includes two Blade components inspired by Next.js Image component for easy use in Laravel templates.

Img Component ​

The Img component generates an optimized image tag with imgproxy processing.

blade
<x-imgproxy-img
    src="https://example.com/image.jpg"
    alt="Description"
    :width="300"
    :height="200"
    resize-type="fill"
    format="webp"
    :quality="75"
    :dpr="2"
    gravity="ce"
    lazy
    sizes="(max-width: 768px) 100vw, 50vw"
/>

Props ​

PropTypeDefaultDescription
srcstringRequiredSource image URL
altstringRequiredAlt text for accessibility
widthint?nullTarget width in pixels
heightint?nullTarget height in pixels
resizeTypeResizeType?nullResize mode (fit, fill, force, etc.)
formatOutputExtension?nullOutput format (jpeg, png, webp, avif)
qualityint75Compression quality (0-100)
dprint?nullDevice pixel ratio
gravityGravity?nullGravity position for crop/fill
lazybooltrueEnable lazy loading
sizesstring?nullHTML sizes attribute

Example ​

blade
<x-imgproxy-img
    src="{{ $product->image_url }}"
    alt="{{ $product->name }}"
    :width="800"
    :height="600"
    resize-type="fill"
    format="webp"
    :quality="85"
/>

Picture Component ​

The Picture component generates a <picture> element with multiple format sources for responsive images.

blade
<x-imgproxy-picture
    src="https://example.com/image.jpg"
    alt="Description"
    :width="800"
    :height="600"
    :formats="['webp', 'avif', 'jpeg']"
    resize-type="fill"
    :quality="75"
    lazy
    sizes="(max-width: 768px) 100vw, 50vw"
/>

Props ​

PropTypeDefaultDescription
srcstringRequiredSource image URL
altstringRequiredAlt text for accessibility
widthint?nullTarget width in pixels
heightint?nullTarget height in pixels
formatsarray['webp', 'avif', 'jpeg']Output formats in priority order
resizeTypeResizeType?nullResize mode (fit, fill, force, etc.)
qualityint75Compression quality (0-100)
dprint?nullDevice pixel ratio
gravityGravity?nullGravity position for crop/fill
lazybooltrueEnable lazy loading
sizesstring?nullHTML sizes attribute

Example ​

blade
<x-imgproxy-picture
    src="{{ $hero->image }}"
    alt="{{ $hero->title }}"
    :width="1200"
    :height="600"
    :formats="['avif', 'webp', 'jpeg']"
    resize-type="fill"
    :quality="85"
    sizes="(max-width: 1200px) 100vw, 1200px"
/>

This generates a <picture> element with <source> tags for AVIF, WebP, and JPEG formats, allowing browsers to choose the best supported format.

Short Property Aliases ​

For cleaner markup, all components support short property aliases. These are especially useful when you want to reduce verbosity in your templates.

Alias Mapping ​

Original PropAliasType
widthwint?
heighthint?
qualityqint
formatfmtOutputExtension?
resizeTypefitResizeType?
gravitygravGravity?

Usage Example ​

blade
<!-- Verbose (still works) -->
<x-imgproxy-img
    src="image.jpg"
    :width="300"
    :height="200"
    resize-type="fill"
    format="webp"
    :quality="85"
    gravity="ce"
/>

<!-- Concise (using aliases) -->
<x-imgproxy-img
    src="image.jpg"
    :w="300"
    :h="200"
    fit="fill"
    fmt="webp"
    :q="85"
    grav="ce"
/>

Both approaches produce identical results. When both the original and alias are provided, the original property takes precedence.

Released under the MIT License.