由 Amir T. 出售

A Node.js plugin wrapping ImageMagick CLI tools for image identification, metadata extraction, resizing, and cropping. Ideal for backend developers needing fast image manipulation via a simple callback API.
This block wraps the ImageMagick CLI tools (convert, identify) in a Node.js-friendly async API. It exposes image identification, metadata extraction, resizing, and cropping as callback-based functions. Typical buyers are backend engineers building image-processing pipelines in Node.js or Express services.
imagemagick.js - Core module: all exported functions (identify, readMetadata, convert, resize, crop) plus the internal exec2 subprocess helper.package.json - Package manifest declaring the imagemagick module at version 0.1.3.test.js - Integration smoke-test demonstrating identify, readMetadata, and resize against a real image file.test-crop.js - Smoke-test demonstrating crop with and without a gravity option.sample-images/blue-bottle-coffee.jpg - Sample JPEG used by both test scripts.README.md - Upstream API reference.# No npm runtime dependencies - uses only Node.js built-ins (child_process, events, fs)
npm install user@example.com # optional: only if you want the published npm shim
Native build requirement (mandatory): The ImageMagick CLI tools must be installed on the host OS before any function call will succeed.
# macOS
brew install imagemagick
# Ubuntu / Debian
sudo apt-get install imagemagick
# Alpine (Docker)
apk add imagemagick
No npm native addon compilation, no pod install, no Android linking required.
source/ directory into your project, e.g. src/lib/imagemagick/.require/import the JS file directly.@types/imagemagick types exist that match this exact source:// tsconfig.json - ensure your paths resolve the local module
{
"compilerOptions": {
"paths": {
"imagemagick": ["./src/lib/imagemagick/imagemagick.js"]
}
}
}
启动隔离沙箱并在服务器端直接运行 — 无需本地配置。
此版本的 Tetrees AI Review
This JavaScript library / package completed archive review. Structure, dependency manifests, documentation, functional source, and common risk patterns were checked by the Tetrees verification pipeline; runtime phases are stated separately.
Deterministic AVCP artifact review
管道 avcp-2026-08-04.1 · SHA-256 e4506397b058f2c8…
This version-scoped review deterministically inspects the submitted archive for structure, dependencies, documentation, functional source, and common malicious or high-risk signals. Build and test phases are reported as passed only after an isolated sandbox audition. It is not a guarantee of perfect security.
审查日期 2026年8月4日
将此产品直接导入你的 AI IDE、网页构建器或云端 IDE。
将 Tetrees 连接到兼容的 AI IDE,列出你拥有的产品并获取已验证 ZIP,同时不会开放卖家上传权限。
暂无评价。
Sign in to join the discussion
Loading discussion…
src/lib/imagemagick/imagemagick.d.ts (see Public API below for shapes).PATH at runtime; the module exposes im.identify.path and im.convert.path properties you can override if the binaries live in a non-standard location.// Override binary paths if needed
import im = require('./src/lib/imagemagick/imagemagick');
(im.identify as any).path = '/usr/local/bin/identify';
(im.convert as any).path = '/usr/local/bin/convert';
// Overload 1: identify a file path and receive a parsed features object
function identify(
path: string,
callback: (err: Error | null, features: { format: string; width: number; height: number; depth: number }) => void
): void;
// Overload 2: pass raw args array and receive raw string output
function identify(
args: string[],
callback: (err: Error | null, output: string) => void
): void;
// Overload 3: identify from in-memory binary data
function identify(
options: { data: string | Buffer },
callback: (err: Error | null, features: object) => void
): void;
Use overload 1 for basic dimension/format queries. Use overload 2 when you need a custom -format expression. Use overload 3 when the image is already in memory (e.g. an upload buffer) and you want to avoid writing to disk.
function readMetadata(
path: string | { data: string | Buffer },
callback: (err: Error | null, metadata: Record<string, Record<string, string>>) => void
): void;
Returns a nested object keyed by EXIF/IPTC group names, e.g. metadata.exif.dateTimeOriginal. Use this when you need rich metadata beyond dimensions (camera model, GPS, dates). Accepts a file path string or an { data } object identical to identify.
interface ResizeOptions {
srcPath?: string;
srcData?: string | Buffer;
srcFormat?: string | null;
dstPath?: string;
quality?: number; // 0.0–1.0, default 0.8
format?: string; // default 'jpg'
progressive?: boolean; // default false
width?: number;
height?: number;
strip?: boolean; // default true
filter?: string; // default 'Lagrange'
sharpening?: number; // default 0.2
customArgs?: string[];
}
function resize(
options: ResizeOptions,
callback: (err: Error | null, stdout: string, stderr: string) => void
): void;
Either srcPath/dstPath (file-to-file) or srcData (stdin, stdout returned in callback) are valid modes. At least one of width or height must be set. quality is a float 0–1; the module converts it internally to the 0–100 scale ImageMagick expects.
interface CropOptions extends ResizeOptions {
gravity?: 'NorthWest' | 'North' | 'NorthEast' | 'West' | 'Center'
| 'East' | 'SouthWest' | 'South' | 'SouthEast';
}
function crop(
options: CropOptions,
callback: (err: Error | null, stdout: string, stderr: string) => void
): void;
Resizes then crops to exact width×height dimensions. gravity (default Center) controls which region is kept. Omitting one dimension produces a square crop.
Query an uploaded file's dimensions without writing any additional file. Use the parsed features object to validate dimensions before storing.
import * as path from 'path';
const im = require('./src/lib/imagemagick/imagemagick');
const imagePath = path.join(__dirname, 'uploads', 'photo.jpg');
im.identify(imagePath, (err: Error | null, features: any) => {
if (err) throw err;
console.log(`Format: ${features.format}`);
console.log(`Dimensions: ${features.width}x${features.height}`);
console.log(`Bit depth: ${features.depth}`);
});
An Express route receives a binary upload buffer and resizes it without touching the filesystem.
import * as fs from 'fs';
const im = require('./src/lib/imagemagick/imagemagick');
const srcData = fs.readFileSync('uploads/photo.jpg', 'binary');
im.resize(
{
srcData,
width: 800,
quality: 0.85,
format: 'jpg',
strip: true,
},
(err: Error | null, stdout: string) => {
if (err) throw err;
fs.writeFileSync('output/photo-800w.jpg', stdout, 'binary');
console.log(`Written ${stdout.length} bytes`);
}
);
Produce a 200×200 thumbnail centered on the North region of the image, useful for portrait photos where the subject is near the top.
const im = require('./src/lib/imagemagick/imagemagick');
im.crop(
{
srcPath: 'uploads/portrait.jpg',
dstPath: 'thumbnails/portrait-thumb.jpg',
width: 200,
height: 200,
quality: 0.9,
gravity: 'North',
},
(err: Error | null) => {
if (err) throw err;
console.log('Thumbnail written to thumbnails/portrait-thumb.jpg');
}
);
Retrieve EXIF data from a JPEG to display camera and shot information.
const im = require('./src/lib/imagemagick/imagemagick');
im.readMetadata('uploads/photo.jpg', (err: Error | null, metadata: any) => {
if (err) throw err;
const exif = metadata.exif || {};
console.log('Date taken:', exif.dateTimeOriginal);
console.log('Camera:', exif.make, exif.model);
});
imagemagick.js - The entire library: defines exec2 (a child_process.spawn wrapper with timeout and buffer-limit logic), then exports identify, readMetadata, convert, resize, and crop. All public functions are attached to the module's export object.package.json - Declares package name imagemagick, version 0.1.3, and main: "imagemagick.js". No runtime npm dependencies.test.js - Exercises identify (path and {data} forms), readMetadata, and resize (file-to-file and in-memory). Run with node test.js from the source directory.test-crop.js - Exercises crop with default gravity and with gravity: "North". Run with node test-crop.js.sample-images/blue-bottle-coffee.jpg - Real JPEG used as fixture by both test files. Safe to replace with any JPEG for your own tests.README.md - Upstream documentation covering installation and the full API surface.convert: command not found at runtime - ImageMagick CLI is not on PATH; install it via the OS package manager or set im.convert.path to the absolute binary path.convert resolves to /usr/bin/convert (part of Xcode tools, not ImageMagick) - Install ImageMagick via brew install imagemagick and set im.convert.path = '/usr/local/bin/convert' (Intel) or '/opt/homebrew/bin/convert' (Apple Silicon).stdout to disk - Always pass 'binary' as the encoding to fs.writeFileSync; omitting it defaults to UTF-8 and corrupts non-ASCII byte sequences in JPEG data.maxBuffer exceeded on large images - The default internal buffer is 500 KB; for high-resolution source images passed as srcData, increase it by passing customArgs or splitting the operation; the module does not expose a maxBuffer option publicly.cannot find module error - The module ships no .d.ts; add a hand-written declaration file or use const im = require('./imagemagick') with // @ts-ignore until you write shims.features object - Usually caused by ImageMagick version differences in identify output format; pin the CLI version or test with im.identify(['-version'], cb) to confirm the binary is reachable and returns expected output.I have dropped the imagemagick Node.js wrapper source (upstream npm package: user@example.com)
into my project at `src/lib/imagemagick/`. There is a USAGE.md at the root of that folder
that describes the full API with TypeScript signatures and working examples.
Please help me integrate this into my existing project step by step:
1. Read `source/imagemagick.js` to understand the real exported functions:
identify, readMetadata, convert, resize, and crop.
2. Read USAGE.md for TypeScript signatures and example patterns.
3. Create a typed wrapper module at `src/services/imageService.ts` that re-exports
identify, readMetadata, resize, and crop with proper TypeScript types as shown in USAGE.md.
4. Wrap each function in a Promise-based helper (e.g. `resizeAsync`, `cropAsync`) so the
rest of the codebase can use async/await.
5. Add error handling that surfaces the ImageMagick stderr output in the thrown Error message.
6. Show me where to place this service in my existing Express router so that POST /upload
automatically resizes the incoming image to 1200px wide before saving.
Do not invent any new ImageMagick options. Only use the options visible in USAGE.md and the
source files under `source/`.
The upstream package does not include an explicit LICENSE file in the distributed source; see source/README.md for any license notices present there. The original package is published on npm as user@example.com by Rasmus Andersson. The README notes this code is unmaintained and recommends the gm module for new projects.
This product’s unique contribution is clean room implementation of valuable code block into AVCP compatible standard.
完整安装指南与集成提示词将在购买后解锁。
Automation, Utilities & Developer Tools
免费