Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@jcayzac/astro-image-service
Advanced tools
A drop-in replacement for Astro's default image service, with art direction support.
@jcayzac/astro-image-service
Drop-in replacement for Astro's built-in image service, with support for cropping.
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:
<picture>
element to serve different images based on the viewport size, and you're OK with dropping all but the center of the image on very small viewports.ImageObject
inside JSON-LD embedded in your pages. Facebook recommends a 40:21
(aka 1.91:1
) aspect ratio for the former while Google recommends 16:9
, 4:3
and 1:1
for the latter.[!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!
# 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
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
})
Use Astro's <Image />
component, the getImage()
function from astro:assets
or the _image
API endpoint as usual.
If you like anything here, consider buying me a coffee using one of the following platforms:
GitHub Sponsors ・ Revolut ・ Wise ・ Ko-Fi ・ PayPal
FAQs
A drop-in replacement for Astro's default image service, with art direction support.
The npm package @jcayzac/astro-image-service receives a total of 0 weekly downloads. As such, @jcayzac/astro-image-service popularity was classified as not popular.
We found that @jcayzac/astro-image-service demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.