🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

@sanity/image-url

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sanity/image-url

Tools to generate image urls from Sanity content

1.1.0
latest
Version published
Weekly downloads
226K
-16.17%
Maintainers
0
Weekly downloads
 
Created

What is @sanity/image-url?

@sanity/image-url is a JavaScript client for generating URLs for images stored in Sanity's content lake. It allows you to build image URLs with various transformations such as resizing, cropping, and format conversion.

What are @sanity/image-url's main functionalities?

Basic URL Generation

This feature allows you to generate a basic URL for an image stored in Sanity. You need to provide the project ID and dataset, and then you can generate the URL for a specific image asset.

const imageUrlBuilder = require('@sanity/image-url');
const client = { projectId: 'yourProjectId', dataset: 'yourDataset' };
const builder = imageUrlBuilder(client);
const url = builder.image('image-asset-id').url();
console.log(url);

Image Resizing

This feature allows you to resize an image by specifying the width and height. The generated URL will point to the resized image.

const url = builder.image('image-asset-id').width(300).height(200).url();
console.log(url);

Image Cropping

This feature allows you to crop an image. You can specify different cropping options such as 'center', 'top', 'bottom', etc.

const url = builder.image('image-asset-id').crop('center').url();
console.log(url);

Format Conversion

This feature allows you to convert the image format. For example, you can convert an image to 'webp' format.

const url = builder.image('image-asset-id').format('webp').url();
console.log(url);

Other packages similar to @sanity/image-url

FAQs

Package last updated on 31 Oct 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