If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.

Node.js Image Processing
अगर आपको images के साथ काम करना है, जैसे उनको resize करना, crop करना, या format convert करना, तो Sharp module आपके लिए बहुत useful हो सकता है।
इस blog में हम Node.js Sharp module को detail में समझेंगे और देखेंगे कैसे आप इससे image processing tasks perform कर सकते हैं।
sharp एक high-performance Node.js library है जो images को manipulate करने और process करने के लिए use होती है। यह image files को read, resize, crop, convert और compress कर सकती है।
यह library आपको real-time image transformation tasks perform करने कि सुविधा देती है, जो websites और applications में images को optimize करने के लिए perfect है।
High Performance : Sharp C++ library libvips के ऊपर build कि गयी है जो fast image processing enable करती है।
Multiple Image Formats : JPEG, PNG, WebP, TIFF, GIF, etc. formats के साथ compatible .
Image Resizing : Image को various dimensions में resize कर सकती है।
Image Cropping : Image को custom size और coordinates पर crop कर सकती है।
Image Conversion : एक format से दुसरे format में convert कर सकती है।
Image Rotation and Flipping : Images को rotate और flip कर सकती है।
Sharp module को install करने के लिए आपको npm package manager का use करना होगा।
npm install sharp
●●●
अब हम देखेंगे कि कैसे आप basic image processing tasks perform कर सकते हैं Sharp module के साथ।
const sharp = require('sharp');
// Resize an image to 300x200
sharp('input.jpg')
.resize(300, 200)
.toFile('output.jpg')
.then(() => {
console.log('Image resized successfully!');
})
.catch(err => {
console.error('Error resizing image:', err);
});●●●
const sharp = require('sharp');
// Crop an image to a specific region
sharp('input.jpg')
.extract({ width: 100, height: 100, left: 50, top: 50 })
.toFile('cropped.jpg')
.then(() => {
console.log('Image cropped successfully!');
})
.catch(err => {
console.error('Error cropping image:', err);
});●●●
const sharp = require('sharp');
// Convert an image to PNG format
sharp('input.jpg')
.toFormat('png')
.toFile('output.png')
.then(() => {
console.log('Image converted to PNG format successfully!');
})
.catch(err => {
console.error('Error converting image:', err);
});●●●
const sharp = require('sharp');
// Rotate an image by 90 degrees
sharp('input.jpg')
.rotate(90)
.toFile('rotated.jpg')
.then(() => {
console.log('Image rotated successfully!');
})
.catch(err => {
console.error('Error rotating image:', err);
});Image Optimization : Websites पे images को optimize करके load time improve करने के लिए।
Thumbnails Creation : Large images को small thumbnails में convert करने के लिए।
Image Conversion : Images को एक format से दुसरे format में convert करने के लिए।
Dynamic Image Rendering : Applications में dynamic image rendering के लिए।
●●●
sharp module Node.js applications में image processing को fast और efficient बनाता है। इस guide के through, आपने देखा कि कैसे आप basic image tasks जैसे resize, crop, convert, और rotate perform कर सकते हैं। Sharp के साथ आप real-time image transformations को efficiently handle कर सकते हैं जो modern web applications के लिए essential है।
sharp module को use करके आप अपनी websites और applications को speed और performance को optimize कर सकते हैं, जो users को better experience provide करता है।
Happy coding with Sharp and Node.js!
Loading ...