npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jcayzac/astro-image-service-ng

v0.2.4

Published

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

Downloads

2,192

Readme

@jcayzac/astro-image-service-ng

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

license npm version npm downloads bundle

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-ng sharp

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

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

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

# deno
deno add npm:@jcayzac/astro-image-service-ng 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-ng',
        },
      },
      // …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 Sponsors Revolut Wise Ko-Fi PayPal