Gathering detailed insights and metrics for @sanity/image-url
Gathering detailed insights and metrics for @sanity/image-url
Gathering detailed insights and metrics for @sanity/image-url
Gathering detailed insights and metrics for @sanity/image-url
gatsby-plugin-sanity-image
Gatsby plugin providing easy responsive behavior for Sanity-hosted images
@tylermcrobert/svelte-sanity-image
A Svelte component for creating responsive, optimized images from Sanity.io. Powered by the [Sanity Image Builder](https://www.sanity.io/docs/image-url) under the hood, it simplifies responsive image handling and layout shift prevention in your Svelte pro
@yoot/sanity
Sanity adapter for @yoot/yoot
@gogaille/sanity-image-url
Tools to generate image urls from Sanity content
npm install @sanity/image-url
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.7
Supply Chain
100
Quality
84.4
Maintenance
100
Vulnerability
100
License
TypeScript (99.53%)
JavaScript (0.47%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
78 Stars
144 Commits
23 Forks
11 Watchers
3 Branches
50 Contributors
Updated on Jun 25, 2025
Latest Version
1.1.0
Package Id
@sanity/image-url@1.1.0
Unpacked Size
173.83 kB
Size
42.88 kB
File Count
30
NPM Version
10.8.3
Node Version
20.16.0
Published on
Oct 31, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Quickly generate image urls from Sanity image records.
This helper will by default respect any crops/hotspots specified in the Sanity content provided to it. The most typical use case for this is to give it a sanity image and specify a width, height or both and get a nice, cropped and resized image according to the wishes of the content editor and the specifications of the front end developer.
In addition to the core use case, this library provides a handy builder to access the rich selection of processing options available in the Sanity image pipeline.
npm install --save @sanity/image-url
The most common way to use this library in your project is to configure it by passing it your configured sanityClient. That way it will automatically be preconfigured to your current project and dataset:
1import React from 'react' 2import myConfiguredSanityClient from './sanityClient' 3import imageUrlBuilder from '@sanity/image-url' 4 5const builder = imageUrlBuilder(myConfiguredSanityClient) 6 7function urlFor(source) { 8 return builder.image(source) 9}
Then you can use the handy builder syntax to generate your urls:
1<img src={urlFor(author.image).width(200).url()} />
This will ensure that the author image is always 200 pixels wide, automatically applying any crop specified by the editor and cropping towards the hot-spot she drew. You can specify both width and height like this:
1<img src={urlFor(movie.poster).width(500).height(300).url()}>
There are a large number of useful options you can specify, like e.g. blur:
1<img src={urlFor(mysteryPerson.mugshot).width(200).height(200).blur(50).url()}>
Note that the url()
function needs to be the final one in order to output the url as a string.
image(source)
Specify the image to be rendered. Accepts either a Sanity image
record, an asset
record, or just the asset id as a string. In order for hotspot/crop processing to be applied, the image
record must be supplied, as well as both width and height.
dataset(dataset)
, projectId(projectId)
Usually you should preconfigure your builder with dataset and project id, but even when you did, these let you temporarily override them if you need to render assets from other projects or datasets.
width(pixels)
Specify the width of the rendered image in pixels.
height(pixels)
Specify the height of the rendered image in pixels.
size(width, height)
Specify width and height in one go.
focalPoint(x, y)
Specify a center point to focus on when cropping the image. Values from 0.0 to 1.0 in fractions of the image dimensions. When specified, overrides any crop or hotspot in the image record.
blur(amount)
, sharpen(amount)
, invert()
Apply image processing.
rect(left, top, width, height)
Specify the crop in pixels. Overrides any crop/hotspot in the image record.
format(name)
Specify the image format of the image. 'jpg', 'pjpg', 'png', 'webp'
auto(mode)
Specify transformations to automatically apply based on browser capabilities. Supported values:
format
- Automatically uses WebP if supportedorientation(angle)
Rotation in degrees. Acceptable values: 0, 90, 180, 270
quality(value)
Compression quality, where applicable. 0-100
forceDownload(defaultFileName)
Make this an url to download the image. Specify the file name that will be suggested to the user.
flipHorizontal()
, flipVertical()
Flips the image.
crop(mode)
Specifies how to crop the image. When specified, overrides any crop or hotspot in the image record. See the documentation for details.
fit(value)
Configures the fit mode. See the documentation for details.
dpr(value)
Specifies device pixel ratio scaling factor. From 1 to 3.
saturation(value)
Adjusts the saturation of the image. Currently the only supported value is -100
- meaning it grayscales the image.
ignoreImageParams()
Ignore any specifications from the image record (i.e. crop and hotspot).
url()
, toString()
Return the url as a string.
pad(value)
Specify the number of pixels to pad the image.
vanityName(fileName)
Specify a "vanity name" for the image. This is useful for SEO purposes and is added to the end of the URL. For example:
1urlFor('image-928ac96d53b0c9049836c86ff25fd3c009039a16-200x200-png').vanityName('myImage.png') 2// https://cdn.sanity.io/…/928ac96d53b0c9049836c86ff25fd3c009039a16-200x200.png/myImage.png
frame(value)
Specify the frame of an animated image to transform. Acceptable values:
1
- Returns the first frame of the animated image as a static preview of the image.minWidth(pixels)
, maxWidth(pixels)
, minHeight(pixels)
, maxHeight(pixels)
Specifies min/max dimensions when cropping.
Deprecated: You usually want to use width
/height
with a fit mode of max
or min
instead.
ℹ️ This feature is available to select Enterprise accounts. Get in touch with your sales executive to learn more.
You can specify a custom baseUrl
in the builder options in order to override the default (https://cdn.sanity.io
):
1import imageUrlBuilder from '@sanity/image-url' 2 3const builder = imageUrlBuilder({ 4 baseUrl: 'https://my.custom.domain', 5 projectId: 'abc123', 6 dataset: 'production', 7}) 8const urlFor = (source) => builder.image(source) 9 10urlFor('image-928ac96d53b0c9049836c86ff25fd3c009039a16-200x200-png') 11 .auto('format') 12 .fit('max') 13 .width(720) 14 .toString() 15 16// output: https://my.custom.domain/images/abc123/production/928ac96d53b0c9049836c86ff25fd3c009039a16-200x200.png?auto=format&fit=max&w=720
If you already have a configured client instance:
1import imageUrlBuilder from '@sanity/image-url' 2import myConfiguredClient from './mySanityClient' 3 4const builder = imageUrlBuilder({ 5 ...myConfiguredClient.config(), 6 baseUrl: 'https://my.custom.domain', 7})
MIT © Sanity.io
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
4 existing vulnerabilities detected
Details
Reason
Found 8/30 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More