
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
A powerful and feature-rich image cropping and manipulation library for Node.js, built with TypeScript and powered by @napi-rs/canvas.
cover
, contain
, fill
, inside
, outside
center
, top
, bottom
, left
, right
, top-left
, top-right
, bottom-left
, bottom-right
npm install cropify
const { cropImage } = require('cropify');
const fs = require('fs');
// Basic cropping
const result = await cropImage({
imagePath: 'input.jpg',
width: 800,
height: 600,
cropCenter: true
});
fs.writeFileSync('output.png', result);
cropImage(options: CropifyOptions)
Crops and manipulates an image based on the provided options.
Parameters:
options
- Configuration object with the following properties:{
imagePath: string | Buffer | URL; // Input image path or buffer
x?: number; // X coordinate (default: 0)
y?: number; // Y coordinate (default: 0)
width?: number; // Output width (default: original)
height?: number; // Output height (default: original)
borderRadius?: number; // Rounded corners radius
circle?: boolean; // Circular crop
cropCenter?: boolean; // Center the crop
}
{
fit?: 'cover' | 'contain' | 'fill' | 'inside' | 'outside';
position?: 'center' | 'top' | 'bottom' | 'left' | 'right' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
background?: string; // Background color (CSS color)
}
{
shape?: {
type: 'rectangle' | 'circle' | 'polygon' | 'star' | 'custom';
sides?: number; // For polygon/star (3+)
points?: Array<{x: number, y: number}>; // For custom shapes (%)
customPath?: string; // SVG path (planned)
}
}
{
filters?: {
brightness?: number; // -100 to 100
contrast?: number; // -100 to 100
saturation?: number; // -100 to 100
blur?: number; // 0 to 20
grayscale?: boolean; // Convert to grayscale
sepia?: boolean; // Apply sepia tone
invert?: boolean; // Invert colors
hue?: number; // Hue rotation (0-360)
}
}
{
output?: {
format?: 'png' | 'jpeg' | 'webp';
quality?: number; // 0-100 (JPEG/WebP only)
progressive?: boolean; // Progressive JPEG (planned)
adaptiveQuality?: boolean; // Adaptive quality (planned)
}
}
cropImages(images: Array<CropifyOptions & { outputPath?: string }>)
Process multiple images in batch.
generateThumbnails(imagePath, sizes, baseOptions?)
Generate multiple thumbnail sizes from a single image.
presets
Pre-configured sizes for social media platforms and common use cases.
const result = await cropImage({
imagePath: 'photo.jpg',
width: 800,
height: 600,
fit: 'cover',
position: 'center',
filters: {
brightness: 20,
contrast: 15,
saturation: -10
},
output: {
format: 'jpeg',
quality: 85
}
});
// Hexagon
const hexagon = await cropImage({
imagePath: 'image.jpg',
width: 400,
height: 400,
shape: {
type: 'polygon',
sides: 6
}
});
// Star
const star = await cropImage({
imagePath: 'image.jpg',
width: 400,
height: 400,
shape: {
type: 'star',
sides: 5
}
});
// Custom diamond shape
const diamond = await cropImage({
imagePath: 'image.jpg',
width: 400,
height: 400,
shape: {
type: 'custom',
points: [
{ x: 50, y: 0 }, // Top
{ x: 100, y: 50 }, // Right
{ x: 50, y: 100 }, // Bottom
{ x: 0, y: 50 } // Left
]
}
});
const batchResults = await cropImages([
{
imagePath: 'photo1.jpg',
width: 300,
height: 300,
filters: { grayscale: true },
outputPath: 'gray1.png'
},
{
imagePath: 'photo2.jpg',
width: 300,
height: 300,
circle: true,
outputPath: 'circle2.png'
}
]);
batchResults.forEach((result, index) => {
if (result.success && result.outputPath) {
fs.writeFileSync(result.outputPath, result.buffer);
}
});
const thumbnails = await generateThumbnails(
'large-image.jpg',
[
{ width: 150, height: 150, suffix: 'small' },
{ width: 300, height: 300, suffix: 'medium' },
{ width: 600, height: 600, suffix: 'large' }
],
{
fit: 'cover',
borderRadius: 10
}
);
thumbnails.forEach(thumb => {
if (thumb.success) {
fs.writeFileSync(`thumb-${thumb.suffix}.png`, thumb.buffer);
}
});
// Instagram square post
const instagramPost = await cropImage({
imagePath: 'photo.jpg',
...presets.instagram.square,
fit: 'cover',
filters: {
brightness: 10,
saturation: 20
},
output: {
format: 'jpeg',
quality: 90
}
});
// Twitter header
const twitterHeader = await cropImage({
imagePath: 'header.jpg',
...presets.twitter.header,
fit: 'cover',
position: 'center'
});
const artisticImage = await cropImage({
imagePath: 'portrait.jpg',
width: 800,
height: 800,
fit: 'cover',
shape: {
type: 'polygon',
sides: 8 // Octagon
},
filters: {
brightness: 15,
contrast: 10,
saturation: 25,
hue: 30
},
background: '#2c3e50',
output: {
format: 'webp',
quality: 90
}
});
cover
: Scale image to cover entire area (may crop)contain
: Scale image to fit entirely within area (may have empty space)fill
: Stretch image to fill exact dimensions (may distort)inside
: Like contain, but never upscaleoutside
: Like cover, but never downscaleControl where the image is positioned within the target area:
center
: Center the imagetop
, bottom
, left
, right
: Align to edgestop-left
, top-right
, bottom-left
, bottom-right
: Corner alignmentFull TypeScript support with comprehensive type definitions:
import { cropImage, CropifyOptions, FilterOptions } from 'cropify';
const options: CropifyOptions = {
imagePath: 'image.jpg',
width: 800,
height: 600,
filters: {
brightness: 20
}
};
@napi-rs/canvas
for high-performance canvas operationsContributions are welcome! Please feel free to submit a Pull Request.
MIT License - see LICENSE file for details.
FAQs
Advanced image cropping and manipulation library with powerful features
The npm package cropify receives a total of 567 weekly downloads. As such, cropify popularity was classified as not popular.
We found that cropify demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.