Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jcayzac/astro-image-service

Package Overview
Dependencies
Maintainers
0
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jcayzac/astro-image-service

A drop-in replacement for Astro's default image service, with art direction support.

  • 1.0.1-investigation17
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
0
Weekly downloads
 
Created
Source

@jcayzac/astro-image-service

Drop-in replacement for Astro's built-in image service, with support for cropping.

Motivation

Astro's built-in image service is great, but it lacks support for cropping. When the service receives a transformation request with both the width and height parameters provided, it ignores the height parameter and preserves the aspect ratio of the input image.

The image service provided by this package do things differently: when both the width and height parameters are provided, the image is first cropped to match the new image aspect ratio, then resized to the requested dimensions while maintaining the original pixel aspect ratio. This is similar to what object-fit: cover does in CSS.

This lets you crop images to specific aspect ratios, a very crude form of art direction useful in various scenarios, for example:

[!NOTE] I am considering adding support for more art direction in some upcoming release.

I think the ability to specify the cropping strategy and the focal point of the image would be the bare minimum.

Some composition API where you can add e.g. an author avatar or a website logo somewhere, and add some text on top of the image, would be nice too.

Right now it mostly depends on what I need for my own projects. If you want these features sooner, consider supporting me!

Installation

# pnpm
pnpm add @jcayzac/astro-image-service sharp

# bun
bunx add @jcayzac/astro-image-service sharp

# npm
npx add @jcayzac/astro-image-service sharp

# yarn
yarn add @jcayzac/astro-image-service sharp

# deno
deno add npm:@jcayzac/astro-image-service npm:sharp

Usage

  1. In your Astro project, replace the built-in image service with this one in your configuration file:

    import { defineConfig } from 'astro/config'
    
    export default defineConfig({
      image: {
        service: {
          entrypoint: '@jcayzac/astro-image-service',
        },
      },
      // …other options
    })
    
  2. Use Astro's <Image /> component, the getImage() function from astro:assets or the _image API endpoint as usual.

Like it? Buy me a coffee!

If you like anything here, consider buying me a coffee using one of the following platforms:

GitHub SponsorsRevolutWiseKo-FiPayPal

Keywords

FAQs

Package last updated on 19 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc