For resizing an image stored on the IPFS network via the Lighthouse gateway, you can use the image's Content Identifier (CID) along with specific query parameters to define the desired dimensions.
constfetch=require('node-fetch'); // node-fetch must be installed if you're using Node.js versions before 18.xconstresizeImage= (cid, height, width, path) => {consturl=`https://gateway.lighthouse.storage/ipfs/${cid}?h=${height}&w=${width}`;fetch(url).then(response => {if (response.ok) returnresponse.buffer();thrownewError('Network response was not ok.'); }).then(buffer => {constfs=require('fs');fs.writeFile(path, buffer, () => {console.log(`Resized image saved to ${path}`); }); }).catch(error => {console.error('Failed to save the resized image:', error); });};// Replace 'CID' with the actual Content Identifier of your image, and 'path' with your desired file path.resizeImage('CID',200,800,'path/to/your/directory/filename.ext');
curl"https://gateway.lighthouse.storage/ipfs/CID?h=200&w=800"--outputpath/to/your/directory/filename.ext# Replace 'CID' with your file's Content Identifier and adjust the output path accordingly.
To resize an image using a web browser, navigate to the URL with the appropriate parameters. Replace CID with your file's Content Identifier: