3 stable releases
new 1.2.0 | Mar 16, 2025 |
---|---|
1.1.0 | Mar 16, 2025 |
1.0.0 | Mar 8, 2025 |
#70 in Images
305 downloads per month
30KB
242 lines
MXTransform
MXTransform is a Rust program for doing matrix transformations on images.
See some example transformations here. 2D transformations are supported, which means you have to provide a 2x2 matrix.
Usage
Run mxtransform --help
to see the detailed usage information.
In general, you need to provide an input image with -i
or --input
, a transformation matrix with -m
or --matrix
, and an output image with -o
or --output
.
Input format
-
In case you need to provide a negative number as the first argument to an option, you can use
=
to indicate that the following arguments are not options. For example, to provide a negative X offset of -1920 you have to use:-f=-1920,0
or--offset=-1920,0
. This is not required if the first argument is positive. -
Matrices are provided as comma-separated values. For example, the following matrix:
| 1 2 | | 3 4 |
Would be provided as
-m 1,2,3,4
or--matrix 1,2,3,4
. See above for how to provide negative numbers.
Examples
-
To transform
input.png
tooutput.png
using the following matrix, which will stretch the image horizontally by a factor of 2:| 2 0 | | 0 1 |
You would run:
mxtransform -i input.png -o output.png -m 2,0,0,1
-
You can also specify an offset with
-f
or--offset
followed byX,Y
, in case the image ends up outside the bounds of the output image. For example to stretch the image horizontally by a factor of 2 and move the result 1920 pixels to the left:mxtransform -i input.png -o output.png -m 2,0,0,1 -f=-1920,0
Installation
Nix
-
Install Nix by following the instructions on the official website.
-
Get MXTransform from the flake in this repository (you might need to enable flake support):
nix shell github:GGORG0/mxtransform
-
You can now run MXTransform from the shell:
mxtransform --help
Cargo Binstall
Cargo Binstall downloads pre-built binaries from the GitHub releases page and installs them for you. You don't need to have Rust installed to use Cargo Binstall.
-
Install Cargo Binstall by following the instructions in the official repository. TL;DR:
-
Linux/MacOS
curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
-
MacOS
brew install cargo-binstall
-
Windows (in PowerShell)
Set-ExecutionPolicy Unrestricted -Scope Process; iex (iwr "https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.ps1").Content
-
-
If you don't have Rust installed, make sure to add the Cargo bin directory to your PATH.
The Binstall installer will tell you if you need to do this and conveniently print the path in question.-
Linux/MacOS
Temporarily:
export PATH="$HOME/.cargo/bin:$PATH"
Permanently:
echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> ~/.bashrc # or ~/.zshrc if you use zsh (default on MacOS) # Then restart your shell or run source ~/.bashrc # or ~/.zshrc
-
Windows: You'll need to modify the PATH environment variable manually.
- Open the Start Search, type in "env", and choose "Edit the system environment variables".
- Click the "Environment Variables..." button.
- Under "System Variables", find the PATH variable and click "Edit...".
- Add the path to the Cargo bin directory (e.g.
C:\Users\username\.cargo\bin
- the path that was printed by the Binstall installer) to the list of paths. - Click "OK" on all the windows to close them.
- You may need to restart your shell, log out and back in, or restart your computer for the changes to take effect.
-
-
Install MXTransform using Cargo Binstall:
cargo-binstall mxtransform
-
You can now run MXTransform from anywhere in your shell:
mxtransform --help
Getting the binary from the GitHub releases page
-
Go to the releases page.
-
Download the binary for your platform.
-
Extract the binary from the archive.
-
Open a shell in the directory where the binary is located.
-
Run the binary:
-
Linux/MacOS
./mxtransform --help
-
Windows
mxtransform.exe --help
-
Cargo (compiling from crates.io)
Dependencies
~11–19MB
~263K SLoC