Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@expo/image-utils
Advanced tools
@expo/image-utils is a utility package for image processing tasks such as resizing, compressing, and converting images. It is particularly useful in the context of Expo and React Native applications.
Resize Image
This feature allows you to resize an image to specified dimensions. The code sample demonstrates how to read an image from the file system, resize it to 100x100 pixels, and save the resized image back to the file system.
const { resizeImage } = require('@expo/image-utils');
const fs = require('fs');
async function resize() {
const imageBuffer = fs.readFileSync('path/to/image.jpg');
const resizedImage = await resizeImage(imageBuffer, { width: 100, height: 100 });
fs.writeFileSync('path/to/resized-image.jpg', resizedImage);
}
resize();
Compress Image
This feature allows you to compress an image to reduce its file size. The code sample demonstrates how to read an image from the file system, compress it with a quality setting of 0.8, and save the compressed image back to the file system.
const { compressImage } = require('@expo/image-utils');
const fs = require('fs');
async function compress() {
const imageBuffer = fs.readFileSync('path/to/image.jpg');
const compressedImage = await compressImage(imageBuffer, { quality: 0.8 });
fs.writeFileSync('path/to/compressed-image.jpg', compressedImage);
}
compress();
Convert Image Format
This feature allows you to convert an image from one format to another. The code sample demonstrates how to read a JPEG image from the file system, convert it to PNG format, and save the converted image back to the file system.
const { convertImageFormat } = require('@expo/image-utils');
const fs = require('fs');
async function convert() {
const imageBuffer = fs.readFileSync('path/to/image.jpg');
const convertedImage = await convertImageFormat(imageBuffer, { format: 'png' });
fs.writeFileSync('path/to/converted-image.png', convertedImage);
}
convert();
Sharp is a high-performance image processing library that supports resizing, cropping, compositing, and format conversion. It is known for its speed and efficiency, making it a popular choice for server-side image processing. Compared to @expo/image-utils, Sharp offers more advanced features and better performance but may be more complex to set up and use.
Jimp is a JavaScript image processing library that works in both Node.js and the browser. It supports a wide range of image manipulation tasks, including resizing, cropping, and color adjustments. Jimp is easier to use and more versatile than @expo/image-utils, but it may not be as performant for large-scale image processing tasks.
GraphicsMagick (gm) is a Node.js wrapper for the GraphicsMagick and ImageMagick command-line tools. It provides a wide range of image processing capabilities, including resizing, cropping, and format conversion. While gm offers extensive functionality, it requires the installation of external dependencies, making it more complex to set up compared to @expo/image-utils.
@expo/image-utils
A library for image processing functionality in Expo CLI.
This library depends on sharp-cli
. If the automatic installation of sharp-cli
fails, you may see the following error in Expo CLI:
This command requires version <version> of `sharp-cli`.
You can install it using `npm install -g sharp-cli@$<version>`
For prerequisites, see: https://sharp.dimens.io/en/stable/install/#prerequisites
To fix this error, you can install sharp-cli
yourself. First check that you have all the platform specific prerequisites for the sharp
library. Then install sharp-cli
globally:
npm install -g sharp-cli
@expo/image-utils
will automatically find the global sharp
command and use that.
FAQs
A package used by Expo CLI for processing images
The npm package @expo/image-utils receives a total of 892,528 weekly downloads. As such, @expo/image-utils popularity was classified as popular.
We found that @expo/image-utils demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 27 open source maintainers collaborating on the project.
Did you know?
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.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.