transpic-cli 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.lock +1342 -0
- package/Cargo.toml +17 -0
- package/examples/output/blur.png +0 -0
- package/examples/output/format.jpg +0 -0
- package/examples/output/grayscale.png +0 -0
- package/examples/output/invert.png +0 -0
- package/examples/output/resize.png +0 -0
- package/examples/output/rotate.png +0 -0
- package/examples/test.png +0 -0
- package/package.json +23 -0
- package/src/cli.js +29 -0
- package/src/main.rs +81 -0
package/Cargo.toml
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "transpic-cli"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2024"
|
|
5
|
+
publish = false
|
|
6
|
+
|
|
7
|
+
[profile.release]
|
|
8
|
+
opt-level = 3
|
|
9
|
+
panic = "abort"
|
|
10
|
+
codegen-units = 1
|
|
11
|
+
lto = true
|
|
12
|
+
strip = "symbols"
|
|
13
|
+
debug = false
|
|
14
|
+
|
|
15
|
+
[dependencies]
|
|
16
|
+
clap = { version = "4.6.1", features = ["derive"] }
|
|
17
|
+
transpic-core = { path = "../core" }
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "transpic-cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A fast image manipulation CLI tool",
|
|
5
|
+
"main": "src/cli.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"transpic": "./src/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "cargo build --release"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"cli",
|
|
14
|
+
"image",
|
|
15
|
+
"manipulation",
|
|
16
|
+
"rust",
|
|
17
|
+
"blur",
|
|
18
|
+
"resize",
|
|
19
|
+
"transpic"
|
|
20
|
+
],
|
|
21
|
+
"author": "Axtraz",
|
|
22
|
+
"license": "MIT"
|
|
23
|
+
}
|
package/src/cli.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { spawn } = require('child_process');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
|
|
7
|
+
const binaryName = process.platform === 'win32' ? 'transpic-cli.exe' : 'transpic-cli';
|
|
8
|
+
const binaryPath = path.join(__dirname, '..', 'target', 'release', binaryName);
|
|
9
|
+
|
|
10
|
+
if (!fs.existsSync(binaryPath)) {
|
|
11
|
+
console.error("Error: Rust binary not found.");
|
|
12
|
+
console.error("Please run 'npm run build' or 'cargo build --release' first.");
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const args = process.argv.slice(2);
|
|
17
|
+
|
|
18
|
+
const child = spawn(binaryPath, args, {
|
|
19
|
+
stdio: 'inherit'
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
child.on('close', (code) => {
|
|
23
|
+
process.exit(code ?? 0);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
child.on('error', (err) => {
|
|
27
|
+
console.error("Failed to start transpic:", err.message);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
});
|
package/src/main.rs
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
use clap::Parser;
|
|
2
|
+
use std::path::PathBuf;
|
|
3
|
+
use std::time::Instant;
|
|
4
|
+
use transpic_core::{ImageOptions, process_image};
|
|
5
|
+
|
|
6
|
+
#[derive(Parser, Debug)]
|
|
7
|
+
#[command(name = "transpic-cli")]
|
|
8
|
+
#[command(version)]
|
|
9
|
+
#[command(about = "A fast image manipulation CLI tool", long_about = None)]
|
|
10
|
+
struct Cli {
|
|
11
|
+
#[arg(
|
|
12
|
+
short,
|
|
13
|
+
long,
|
|
14
|
+
help = "Path to the input image, example: --path assets/image.png"
|
|
15
|
+
)]
|
|
16
|
+
path: PathBuf,
|
|
17
|
+
|
|
18
|
+
#[arg(long, help = "Output format, example: --format png")]
|
|
19
|
+
format: Option<String>,
|
|
20
|
+
|
|
21
|
+
#[arg(long, help = "Blur intensity, example: --blur 1")]
|
|
22
|
+
blur: Option<f32>,
|
|
23
|
+
|
|
24
|
+
#[arg(long, help = "Grayscale the image, example: --grayscale")]
|
|
25
|
+
grayscale: bool,
|
|
26
|
+
|
|
27
|
+
#[arg(long, help = "Invert the image colors, example: --invert")]
|
|
28
|
+
invert: bool,
|
|
29
|
+
|
|
30
|
+
#[arg(long, help = "Resize the image, example: --resize 800x600")]
|
|
31
|
+
resize: Option<String>,
|
|
32
|
+
|
|
33
|
+
#[arg(
|
|
34
|
+
long,
|
|
35
|
+
help = "Rotation angle in degrees (90, 180, or 270), example: --rotate 180"
|
|
36
|
+
)]
|
|
37
|
+
rotate: Option<u32>,
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
fn main() {
|
|
41
|
+
if let Err(e) = run() {
|
|
42
|
+
eprintln!("\x1b[31mError: {}\x1b[0m", e);
|
|
43
|
+
std::process::exit(1);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
fn run() -> Result<(), Box<dyn std::error::Error>> {
|
|
48
|
+
let cli = Cli::parse();
|
|
49
|
+
let start = Instant::now();
|
|
50
|
+
|
|
51
|
+
if cli.format.is_none()
|
|
52
|
+
&& cli.blur.is_none()
|
|
53
|
+
&& !cli.grayscale
|
|
54
|
+
&& !cli.invert
|
|
55
|
+
&& cli.resize.is_none()
|
|
56
|
+
&& cli.rotate.is_none()
|
|
57
|
+
{
|
|
58
|
+
return Err(
|
|
59
|
+
"You must specify at least one action (e.g., --grayscale, --blur 2, etc.).".into(),
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
let options = ImageOptions {
|
|
64
|
+
blur: cli.blur,
|
|
65
|
+
grayscale: cli.grayscale,
|
|
66
|
+
invert: cli.invert,
|
|
67
|
+
resize: cli.resize,
|
|
68
|
+
rotate: cli.rotate,
|
|
69
|
+
output_format: cli.format,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
let saved_filename = process_image(&cli.path, options)?;
|
|
73
|
+
|
|
74
|
+
let duration = start.elapsed();
|
|
75
|
+
println!(
|
|
76
|
+
"\x1b[32m✓ Image edited successfully in {:.2?} and saved as '{}'\x1b[0m",
|
|
77
|
+
duration, saved_filename
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
Ok(())
|
|
81
|
+
}
|