0%
SupportNFT API
How to Resize NFT Images and Thumbnails with NFT API

How to Resize NFT Images and Thumbnails with NFT API

Written by Author headshotKilliane Menand
Published on October 1, 20242 min read

When working with Alchemy's NFT API, you may need to resize images or thumbnails to fit different device screens or layouts. This guide will walk you through resizing both while maintaining the correct aspect ratio.

Thumbnails are automatically generated and cached in the payload response for convenience. These are smaller, compressed versions of the original image optimized for quick loading.

Copied
https://res.cloudinary.com/alchemyapi/image/upload/thumbnail/eth-mainnet/<hash>

To resize a thumbnail, you can modify the Cloudinary URL by adding specific width (`w_`) and height (`h_`) values. For example, to set a width of 256 pixels while keeping the original aspect ratio, you would do the following:

Copied
https://res.cloudinary.com/alchemyapi/image/upload/w_256/thumbnail/eth-mainnet/<hash>

This resizes the thumbnail to a width of 256 pixels while maintaining its aspect ratio. You can also define height (`h_`) if needed.

You can use any combination of width and height values to get the desired size:

Copied
https://res.cloudinary.com/alchemyapi/image/upload/w_400,h_400/thumbnail/eth-mainnet/<hash>

Original images are the high-resolution versions of the NFTs and are also stored on Alchemy's CDN. These can be resized similarly to thumbnails but require a different approach for optimal quality.

Copied
https://nft-cdn.alchemy.com/eth-mainnet/<hash>

To resize the original image while keeping the aspect ratio, use Cloudinary’s width (`w_`) and height (`h_`) values in the URL like this:

Copied
https://res.cloudinary.com/alchemyapi/image/upload/w_256/scaled/eth-mainnet/<hash>

This will return the image resized to a width of 256 pixels, with the aspect ratio maintained. You can adjust the width or height as needed.

Just like with thumbnails, you can use any width and height values to resize the original image:

Copied
https://res.cloudinary.com/alchemyapi/image/upload/w_400,h_400/scaled/eth-mainnet/<hash>

- Thumbnails: Compressed, smaller versions for quick loading. Best for previews and small display areas.

- Images: Full-resolution, high-quality versions of the NFT asset. Best for larger screens or when displaying full details of the NFT.

- Thumbnails and images are resized through Cloudinary but have different URL paths, so be sure to modify the correct URL.

- Always maintain the aspect ratio by using only width (`w_`) or height (`h_`) unless you need to alter the ratio intentionally.

- For thumbnails, modify the URL like this:

Copied
https://res.cloudinary.com/alchemyapi/image/upload/w_256/thumbnail/eth-mainnet/<hash>

- For images, modify the URL like this:

Copied
https://res.cloudinary.com/alchemyapi/image/upload/w_256/scaled/eth-mainnet/<hash>

This approach ensures that you can resize both the thumbnail and the original image while maintaining the aspect ratio and optimizing for different display needs!

Was this article helpful?
Share:
Banner background image

Not finding what you need?