Open Source Node.js API to Manipulate Images
Load, Read, Resize, Merge and Convert Images (JPEG, PNG, GIF) and Extract Metadata from Images using Open Source Node.js Library.
These days, many web applications need to tweak images, like resizing them, changing file types, or adding effects. If you’re a software developer using Node.js, you can turn to Node-EasyImage for help. This tool is free and user-friendly, making it a handy solution for handling various image tasks. By using this API, developers can smoothly add image functions to their apps without hassle. There are several important features part of the library, such as image resizing, image cropping, rotating images, image metadata extraction, image format conversion and many more.
Node-EasyImage is a handy open-source tool designed for developers using Node.js. It simplifies image editing tasks by allowing you to create image thumbnails quickly. Whether you’re working on e-commerce sites, social media, or galleries, this library makes it a breeze to generate top-notch thumbnails with minimal code. It streamlines the process, ensuring you can effortlessly produce polished and uniform thumbnails every time. Using robust libraries such as ImageMagick and GraphicsMagick, this tool is designed to work seamlessly within the Node.js platform. It grants developers the ability to tap into sophisticated image processing functions without the need for in-depth understanding of these libraries. With a promise-based interface, it easily fits into contemporary JavaScript processes, making it the preferred option for handling image editing tasks.
Getting Started with Node-EasyImage
The recommended way to install Node-EasyImage via NPM. Please use the following command to install it.
Install Node-EasyImage via NPM
$ npm install --save easyimage
Resize Images inside Node.js
Resizing images is one of the most frequently required tasks when working with images, especially in web development, where different screen sizes demand responsive images. The open source Node-EasyImage simplifies this with just a few lines of code. In the following code example, software developers can resize an image called image.jpg to 500x500 pixels and save it as resized_image.jpg. The function is asynchronous, and the Promise ensures user handle success or failure in an elegant way.
How to Resize Images inside Node.js Apps?
const easyimage = require('easyimage');
easyimage.resize({
src: 'image.jpg',
dst: 'resized_image.jpg',
width: 500,
height: 500
}).then(function (image) {
console.log('Image resized:', image);
}).catch(function (err) {
console.error('Error resizing image:', err);
});
Extracting Image Metadata in Node.js Apps
Understanding the properties of an image is critical when processing or displaying it. Node-EasyImage library makes it easy for software developers to extract key metadata like dimensions, file size, author, image creation date, and image format, making it easier to work with large collections of images inside Node.js applications. This data is very useful in photo management applications or when you want to categorize and store images based on specific criteria. Here is a simple example that shows, how software developers can extract metadata from an image inside Node.js application.
How to Extract Metadata from Image inside Node.js Apps?
easyimage.info('input.jpg')
.then((file) => {
console.log('Image Info:', file);
})
.catch((err) => {
console.log(err);
});
Image Format Conversion in Node.js
The open source Node-EasyImage library completely support conversion between various image formats such as JPEG, PNG, GIF, BMP and many others inside Node.js environment. This is a very useful feature and particularly helpful in applications that need to process multiple image types and standardize them for a consistent user experience. In the following example, a JPEG image is converted to PNG format. The converted image is saved as output.png, which can then be used for various purposes such as reducing file size or enhancing compatibility.
How to Convert JPEG Image to PNG File Format inside Node.js ?
// Convert image from JPEG to PNG
easyimage.convert({
src: 'input.jpg',
dst: 'output.png'
}).then(function (image) {
console.log('Converted image:', image);
}).catch(function (err) {
console.log(err);
});
Image Composition and Merging
Another advanced feature is the ability to compose or merge images inside Node.js applications. The Node-EasyImage library enables software developers to overlay images on top of each other, merge multiple images into one, or create composite images for more complex applications like generating thumbnails with watermarks. Here is an example that shows how image1.jpg and image2.jpg are merged into a single image saved as merged.jpg. This feature is useful for applications that generate collages, watermarked images, or promotional banners.
How to Perform Image Merging inside Node.js Apps?
// Merge two images into one
easyimage.merge({
src: ['image1.jpg', 'image2.jpg'],
dst: 'merged.jpg'
}).then(function (image) {
console.log('Merged image:', image);
}).catch(function (err) {
console.log(err);
});