nlfiedler / magick-rust Goto Github PK
View Code? Open in Web Editor NEWRust bindings for ImageMagick
Home Page: https://crates.io/crates/magick_rust
License: Apache License 2.0
Rust bindings for ImageMagick
Home Page: https://crates.io/crates/magick_rust
License: Apache License 2.0
when installed ImageMagick and successfully build it on my windows pc, the final Rust executable worked anywhere
but then transfer the final executable to another PC, it does not work:
failed to read image
when how should I distribute the final executable?
First of all thx for your great lib here.
I am basically trying to compare two images
and afterwards use TransparentPaintImage to make the white parts in the diff transparent .
Thats the part that is not working..
The code snippet here works perfect ... it only seems it has no effect on the image reference.
I somehow suppose the line with PixelGetPixel .. does not what i think.
I tried alot but as a full noop i somehow cant exchange white with transparent pixel
On commandline or with go bindings it works ... just here i cant get it running
Do you have any idea what could be done ?
Thx in advance c
See here my codesnippet:
let mut left = MagickWand::new();
let right = MagickWand::new();
let left_binary: Binary = args[0].decode_as_binary()?;
let right_binary: Binary = args[1].decode_as_binary()?;
left.set_option("fuzz","10%").unwrap();
left.set_option("highlight-color","red").unwrap();
left.set_option("compose","Copy").unwrap();
right.read_image_blob(right_binary.as_slice());
left.read_image_blob(left_binary.as_slice());
let (distortion, diff) =
left.compare_images(&right, bindings::MetricType_FuzzErrorMetric);
let diff_image = diff.unwrap();
diff_image.set_image_alpha_channel(bindings::AlphaChannelOption_OpaqueAlphaChannel).unwrap();
let fuzz: f64 = 25.0;
let mut filter2 = PixelWand::new();
filter2.set_fuzz(fuzz);
filter2.set_color("#FFFFFF").unwrap();
filter2.set_alpha(1.0);
let ei = unsafe { bindings::AcquireExceptionInfo() };
let image = unsafe { bindings::GetImageFromMagickWand(diff_image.wand) };
let mut pixel_info = unsafe { bindings::PixelGetPixel(filter2.wand)};
let result = unsafe { bindings::TransparentPaintImage(image,&pixel_info,1.0,0,ei) };
let resultwand = unsafe { bindings::NewMagickWandFromImage(image)};
Recent versions of rust-bindgen produce a different module prefix for the C library types. Previously it would default to libc::
, but now it uses std::os::raw
instead. To fix this, remove the --ctypes-prefix=libc
option from the build.rs
build script and fix the compiler errors. There are only a few places in the code that need fixing, so this is an easy one.
This library is several years old, maybe now is as good a time as any to prepare for a 1.0 release. After that, any breaking changes means bumping the major version, and that seems a better approach for the long run. As it is now, a minor bump at pre-1.0 looks deceptively minor when in fact it may not be minor at all.
@5ohue Thoughts? My role on this repository is primarily that of curator, and given your many recent significant contributions of late, you are as qualified as any to decide the appropriate time for the next release. Do you have more changes planned, or is now a good time to ship 1.0?
And thank you again for your many contributions.
Since this is published on crates.io, really should have a brief section in the README that describes how to use the crate rather than cloning and building from scratch.
People using magick-rust
and anyhow
would suffer from error transform like this
fn foo() -> anyhow::Result<()> [
magick_wand.some_method().map_err(|e|anyhow!())?
Ok(())
}
If we are using Result
type like this, things would be easier:
struct MagickError(&'static str);
impl From<&'static str> for MagickError {
fn from(s: &'static str) -> Self {
MagickError(s)
}
}
fn foo1() -> Result<(), MagickError> {
Err("something went wrong")?;
Ok(())
}
fn foo2() -> Result<(), MagickError> {
foo1()?;
Ok(())
}
fn foo3() -> anyhow::Result<()> {
foo2()?;
Ok(())
}
I do believe there would be a lot of boring work, I'd like to handle this, since I really like this.
I'm using MagickSetPointsize to set the font size and I would prefer not having unsafe code on my side.
It seems set_font_size() is only for when using DrawingWand but I'm not using one. I generate text like this:
let mut wand = MagickWand::new();
wand.set_option("background", "black")
.map_err(magick_error)?;
wand.set_option("fill", color).map_err(magick_error)?;
wand.set_gravity(GravityType::CenterGravity)
.map_err(magick_error)?;
unsafe {
magick_rust::bindings::MagickSetPointsize(wand.wand, 20.0);
}
wand.read_image(&format!("caption:{}", text))
.map_err(magick_error)?;
I followed installation instructions and when I try to build the library I get:
Unable to find libclang: "couldn't find any valid shared libraries matching: ['clang.dll', 'libclang.dll'], set the
LIBCLANG_PATH
environment variable to a path where one of these files can be found (invalid: [])"
So I tried setting LIBCLANG_PATH
to the lib folder inside the folder LLVM gets installed to. Now when I build I get:
imagemagick\include\MagickWand/MagickWand.h:59:10: fatal error: 'stdio.h' file not found
Any idea how to fix it?
I spun up a fresh Ubuntu 20.04 VM, and built ImageMagick manually:
sudo apt install build-essential pkgconf clang lldb
sudo ln -s /usr/bin/llvm-config-10 /usr/local/bin/llvm-config
wget http://www.imagemagick.org/download/ImageMagick.tar.gz
tar -xzvf ImageMagick.tar.gz
cd ImageMagick-7.0.10-33/
./configure
make
sudo make install
I then tried to build magick-rust
:
git clone https://github.com/nlfiedler/magick-rust.git
cd magick-rust/
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
cargo build --release
And got this output:
$ cargo build --release
Compiling magick_rust v0.14.0 (/home/ubuntu/magick-rust)
error: failed to run custom build command for `magick_rust v0.14.0 (/home/ubuntu/magick-rust)`
Caused by:
process didn't exit successfully: `/home/ubuntu/magick-rust/target/release/build/magick_rust-95e13b5e81b2af38/build-script-build` (exit code: 101)
--- stdout
cargo:rerun-if-env-changed=IMAGE_MAGICK_LIB_DIRS
cargo:rerun-if-env-changed=IMAGE_MAGICK_DIR
cargo:rerun-if-env-changed=MAGICKWAND_NO_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG
cargo:rerun-if-env-changed=MAGICKWAND_STATIC
cargo:rerun-if-env-changed=MAGICKWAND_DYNAMIC
cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
... snip lots of similar lines ...
--- stderr
/usr/local/include/ImageMagick-7/MagickCore/magick-config.h:63:3: warning: "you should set MAGICKCORE_QUANTUM_DEPTH to sensible default set it to configure time default" [-W#warnings]
/usr/local/include/ImageMagick-7/MagickCore/magick-config.h:64:3: warning: "this is an obsolete behavior please fix your makefile" [-W#warnings]
/usr/local/include/ImageMagick-7/MagickCore/magick-config.h:74:5: error: invalid token at start of a preprocessor expression
/usr/local/include/ImageMagick-7/MagickCore/magick-config.h:86:3: warning: "you should set MAGICKCORE_HDRI_ENABLE to sensible default set it to configure time default" [-W#warnings]
/usr/local/include/ImageMagick-7/MagickCore/magick-config.h:87:3: warning: "this is an obsolete behavior please fix yours makefile" [-W#warnings]
/usr/local/include/ImageMagick-7/MagickCore/magick-config.h:113:5: error: invalid token at start of a preprocessor expression
/usr/local/include/ImageMagick-7/MagickCore/magick-type.h:64:6: error: invalid token at start of a preprocessor expression
/usr/local/include/ImageMagick-7/MagickCore/magick-type.h:77:8: error: invalid token at start of a preprocessor expression
/usr/local/include/ImageMagick-7/MagickCore/magick-type.h:90:8: error: invalid token at start of a preprocessor expression
/usr/local/include/ImageMagick-7/MagickCore/magick-type.h:103:8: error: invalid token at start of a preprocessor expression
/usr/local/include/ImageMagick-7/MagickCore/magick-type.h:112:2: error: "MAGICKCORE_QUANTUM_DEPTH must be one of 8, 16, 32, or 64"
/usr/local/include/ImageMagick-7/MagickCore/pixel.h:230:18: error: unknown type name 'Quantum'
/usr/local/include/ImageMagick-7/MagickCore/pixel.h:234:47: error: unknown type name 'Quantum'
/usr/local/include/ImageMagick-7/MagickCore/pixel.h:235:11: error: unknown type name 'Quantum'
/usr/local/include/ImageMagick-7/MagickCore/pixel.h:244:11: error: unknown type name 'Quantum'
/usr/local/include/ImageMagick-7/MagickCore/cache-view.h:66:27: error: unknown type name 'Quantum'
/usr/local/include/ImageMagick-7/MagickCore/cache-view.h:69:52: error: expected ';' after top level declarator
/usr/local/include/ImageMagick-7/MagickCore/cache-view.h:69:53: warning: declaration does not declare anything [-Wmissing-declarations]
/usr/local/include/ImageMagick-7/MagickCore/cache-view.h:77:5: error: unknown type name 'Quantum'
/usr/local/include/ImageMagick-7/MagickCore/cache-view.h:79:33: error: unknown type name 'Quantum'
/usr/local/include/ImageMagick-7/MagickCore/cache-view.h:81:5: error: unknown type name 'Quantum'
/usr/local/include/ImageMagick-7/MagickCore/cache-view.h:93:21: error: unknown type name 'Quantum'
/usr/local/include/ImageMagick-7/MagickCore/cache-view.h:96:47: error: expected ';' after top level declarator
/usr/local/include/ImageMagick-7/MagickCore/cache-view.h:96:63: error: expected identifier or '('
fatal error: too many errors emitted, stopping now [-ferror-limit=]
/usr/local/include/ImageMagick-7/MagickCore/magick-config.h:63:3: warning: "you should set MAGICKCORE_QUANTUM_DEPTH to sensible default set it to configure time default" [-W#warnings], err
: false
/usr/local/include/ImageMagick-7/MagickCore/magick-config.h:64:3: warning: "this is an obsolete behavior please fix your makefile" [-W#warnings], err: false
/usr/local/include/ImageMagick-7/MagickCore/magick-config.h:74:5: error: invalid token at start of a preprocessor expression, err: true
/usr/local/include/ImageMagick-7/MagickCore/magick-config.h:86:3: warning: "you should set MAGICKCORE_HDRI_ENABLE to sensible default set it to configure time default" [-W#warnings], err:
false
/usr/local/include/ImageMagick-7/MagickCore/magick-config.h:87:3: warning: "this is an obsolete behavior please fix yours makefile" [-W#warnings], err: false
/usr/local/include/ImageMagick-7/MagickCore/magick-config.h:113:5: error: invalid token at start of a preprocessor expression, err: true
/usr/local/include/ImageMagick-7/MagickCore/magick-type.h:64:6: error: invalid token at start of a preprocessor expression, err: true
/usr/local/include/ImageMagick-7/MagickCore/magick-type.h:77:8: error: invalid token at start of a preprocessor expression, err: true
/usr/local/include/ImageMagick-7/MagickCore/magick-type.h:90:8: error: invalid token at start of a preprocessor expression, err: true
/usr/local/include/ImageMagick-7/MagickCore/magick-type.h:103:8: error: invalid token at start of a preprocessor expression, err: true
/usr/local/include/ImageMagick-7/MagickCore/magick-type.h:112:2: error: "MAGICKCORE_QUANTUM_DEPTH must be one of 8, 16, 32, or 64", err: true
/usr/local/include/ImageMagick-7/MagickCore/pixel.h:230:18: error: unknown type name 'Quantum', err: true
/usr/local/include/ImageMagick-7/MagickCore/pixel.h:234:47: error: unknown type name 'Quantum', err: true
/usr/local/include/ImageMagick-7/MagickCore/pixel.h:235:11: error: unknown type name 'Quantum', err: true
/usr/local/include/ImageMagick-7/MagickCore/pixel.h:244:11: error: unknown type name 'Quantum', err: true
/usr/local/include/ImageMagick-7/MagickCore/cache-view.h:66:27: error: unknown type name 'Quantum', err: true
/usr/local/include/ImageMagick-7/MagickCore/cache-view.h:69:52: error: expected ';' after top level declarator, err: true
/usr/local/include/ImageMagick-7/MagickCore/cache-view.h:69:53: warning: declaration does not declare anything [-Wmissing-declarations], err: false
/usr/local/include/ImageMagick-7/MagickCore/cache-view.h:77:5: error: unknown type name 'Quantum', err: true
/usr/local/include/ImageMagick-7/MagickCore/cache-view.h:79:33: error: unknown type name 'Quantum', err: true
/usr/local/include/ImageMagick-7/MagickCore/cache-view.h:81:5: error: unknown type name 'Quantum', err: true
/usr/local/include/ImageMagick-7/MagickCore/cache-view.h:93:21: error: unknown type name 'Quantum', err: true
/usr/local/include/ImageMagick-7/MagickCore/cache-view.h:96:47: error: expected ';' after top level declarator, err: true
/usr/local/include/ImageMagick-7/MagickCore/cache-view.h:96:63: error: expected identifier or '(', err: true
fatal error: too many errors emitted, stopping now [-ferror-limit=], err: true
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ()', build.rs:144:43
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
If I edit /usr/local/include/ImageMagick-7/MagickCore/magick-config.h
to include this line:
#define MAGICKCORE_QUANTUM_DEPTH 8
Then it compilation works fine. I'm not sure how to best handle that without manual editing, however.
Hi there! Thanks for maintaining this crate!
How would I go about building a crate that depends on this one for the x86_64-unknown-linux-musl target? Is that something that is supported currently?
Works fine in 7.1.1.15, but compiling with 7.1.1.17 fails with this error:
error[E0425]: cannot find value `QuantumRange` in module `bindings`
--> src/wand/magick.rs:341:22
|
341 | Ok(bindings::QuantumRange)
| ^^^^^^^^^^^^ not found in `bindings`
For more information about this error, try `rustc --explain E0425`.
error: could not compile `magick_rust` (lib) due to previous error
Looks like #40, but in this case both versions were compiled with hdri enabled
Hey there, trying to read the docs at https://docs.rs/crate/magick_rust/0.7.0 results in a weird error message that I didn't know existed:
docs.rs failed to build magick_rust-0.7.0
Please check build logs and if you believe this is docs.rs' fault, report into this issue report.
It seems not to be able to build at all because of not finding imagemagick 7. Some way you can get around that to make the docs work again?
In Rust lang, each type is marked Send
or !Send
, in magick-rust
, I noticed that DrawingWand
, MagickWand
And PixedWand
is !Send
, is that correct?
Currently the {{build.rs}} "script" fails in a less than obvious fashion when the {{MagickWand-config}} command is not found. Would be good if the build script could detect this case and report it a little more clearly.
Building magick-rust out of the box on ubuntu/bionic64 is not working. Seems like several problems at once:
/usr/lib/llvm-6.0/lib/clang/6.0.0/include
).pkg-config
correctly (or at all) to get ImageMagick flags.On Debian 12
I cloned the repository and ran cargo
build`
magick-rust$ PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig cargo build
I get the error:
thread 'main' panicked at build.rs:288:10:
called `Result::unwrap()` on an `Err` value:
pkg-config exited with status code 1
> PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 pkg-config --libs --cflags MagickWand MagickWand >= 7.0
The system library `MagickWand` required by crate `magick_rust` was not found.
The file `MagickWand.pc` needs to be installed and the PKG_CONFIG_PATH environment variable must contain its parent directory.
PKG_CONFIG_PATH contains the following:
- /usr/lib/x86_64-linux-gnu/pkgconfig
But:
magick-rust$ ls -l /usr/lib/x86_64-linux-gnu/pkgconfig/MagickWand.pc
lrwxrwxrwx 1 root root 21 Feb 13 09:15 /usr/lib/x86_64-linux-gnu/pkgconfig/MagickWand.pc -> MagickWand-im6.q16.pc
magick-rust$ aptitude search magickwand
i A libmagickwand-6-headers - image manipulation library - headers files
v libmagickwand-6.defaultquantum-dev -
i A libmagickwand-6.q16-6 - image manipulation library -- quantum depth Q16
i A libmagickwand-6.q16-dev - image manipulation library - development files (Q16)
i A libmagickwand-6.q16hdri-6 - image manipulation library -- quantum depth Q16HDRI
i libmagickwand-6.q16hdri-dev - image manipulation library - development files (Q16HDRI)
i libmagickwand-dev - image manipulation library -- dummy package
Error message:
C:\Program Files\ImageMagick-7.1.1-Q8\include\MagickCore/magick-baseconfig.h:279:6: error: ImageMagick was build with a 64 channel bit mask and that requires a C++ compiler
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ClangDiagnostic("C:\\Program Files\\ImageMagick-7.1.1-Q8\\include\\MagickCore/magick-baseconfig.h:279:6: error: ImageMagick was build with a 64 channel bit mask and that requires a C++ compiler\n")', C:\Users\Dell\.cargo\registry\src\index.crates.io-6f17d22bba15001f\magick_rust-0.19.1\build.rs:145:43
The same code builds without a problem when $env:IMAGE_MAGICK_DIR
points to the installation path of ImageMagick v7.1.1-4.
Also,
cd 'C:\Program Files\ImageMagick-7.1.1-Q8\include'
# failed
bindgen MagickWand/MagickWand.h -o $OUT\magick.rs -- -I .
# succeeded
bindgen MagickWand/MagickWand.h -o $OUT\magick.rs -- -I . -x c++
It appears to be due to a recent change to VisualMagick.
build failed with Link Error 1120, with ImageMagick-7.0.11-Q16-HDRI on Windows 11.
full output:
error: linking with
link.exe
failed: exit code: 1120
|
= note: "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.31.31103\bin\HostX64\x64\link.exe" "/NOLOGO" "c:\Users\username\cargo_target_dir\debug\deps\get_colorspace.10v6bpuf3qi3s9wb.rcgu.o" "c:\Users\username\cargo_target_dir\debug\deps\get_colorspace.20wphgq7yzel1dvq.rcgu.o" "c:\Users\username\cargo_target_dir\debug\deps\get_colorspace.2d5b07kvx5m576z1.rcgu.o" "c:\Users\username\cargo_target_dir\debug\deps\get_colorspace.2di36doxcjpfqhw5.rcgu.o" "c:\Users\username\cargo_target_dir\debug\deps\get_colorspace.2f4aop8i2yt0inw5.rcgu.o" "c:\Users\username\cargo_target_dir\debug\deps\get_colorspace.2p5fjqh913yiwgks.rcgu.o" "c:\Users\username\cargo_target_dir\debug\deps\get_colorspace.31p0ky0plw70fawk.rcgu.o" "c:\Users\username\cargo_target_dir\debug\deps\get_colorspace.37wiekeicx5a4zch.rcgu.o" "c:\Users\username\cargo_target_dir\debug\deps\get_colorspace.3ny4vgohjuj6k767.rcgu.o" "c:\Users\username\cargo_target_dir\debug\deps\get_colorspace.3ovwk4tv7u8xbvdt.rcgu.o" "c:\Users\username\cargo_target_dir\debug\deps\get_colorspace.3uko6j6618irq2pg.rcgu.o" "c:\Users\username\cargo_target_dir\debug\deps\get_colorspace.45645ret6pyksr1q.rcgu.o" "c:\Users\username\cargo_target_dir\debug\deps\get_colorspace.4bvzjyulhnn9adq7.rcgu.o" "c:\Users\username\cargo_target_dir\debug\deps\get_colorspace.4oo73ps4klho4w2t.rcgu.o" "c:\Users\username\cargo_target_dir\debug\deps\get_colorspace.5b0bne1hskgc7naw.rcgu.o" "c:\Users\username\cargo_target_dir\debug\deps\get_colorspace.5f4bglcpf1imhpha.rcgu.o" "c:\Users\username\cargo_target_dir\debug\deps\get_colorspace.81a26skokhmwehw.rcgu.o" "c:\Users\username\cargo_target_dir\debug\deps\get_colorspace.za4p28hg9y16iqn.rcgu.o" "c:\Users\username\cargo_target_dir\debug\deps\get_colorspace.1g45lxx20rdvqoa6.rcgu.o" "/LIBPATH:c:\Users\username\cargo_target_dir\debug\deps" "/LIBPATH:C:\Program Files\ImageMagick-7.0.11-Q16-HDRI\lib" "/LIBPATH:C:\Users\username\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib" "C:\Users\username\cargo_target_dir\debug\deps\libmagick_rust-eafa453c03e29a83.rlib" "C:\Users\username\cargo_target_dir\debug\deps\liblibc-bca145ffaa3cfaad.rlib" "C:\Users\username\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\libstd-c2061a8c4363ad39.rlib" "C:\Users\username\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\libpanic_unwind-8f8123f3df81d084.rlib" "C:\Users\username\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\librustc_demangle-b25b7b3cabf04f79.rlib" "C:\Users\username\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\libstd_detect-844c1d68b208e8c3.rlib" "C:\Users\username\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\libhashbrown-9715294e33005e45.rlib" "C:\Users\username\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\libminiz_oxide-ab777c9ef4ab46ea.rlib" "C:\Users\username\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\libadler-2163bb13d93657e2.rlib" "C:\Users\username\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\librustc_std_workspace_alloc-a23614ca81dcf6e6.rlib" "C:\Users\username\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\libunwind-6a453694c0b8f4bc.rlib" "C:\Users\username\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\libcfg_if-bafbc7d22d1290b3.rlib" "C:\Users\username\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\liblibc-b3f04308174fa2f6.rlib" "C:\Users\username\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\liballoc-9e7c4059b4444380.rlib" "C:\Users\username\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\librustc_std_workspace_core-3469c9a2a5a61b94.rlib" "C:\Users\username\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\libcore-5c32adea4bb22d70.rlib" "C:\Users\username\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\libcompiler_builtins-c9e4ee006e473c58.rlib" "kernel32.lib" "ws2_32.lib" "bcrypt.lib" "advapi32.lib" "userenv.lib" "kernel32.lib" "msvcrt.lib" "/NXCOMPAT" "/LIBPATH:C:\Users\username\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib" "/OUT:c:\Users\username\cargo_target_dir\debug\deps\get_colorspace.exe" "/OPT:REF,NOICF" "/DEBUG" "/NATVIS:C:\Users\username\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\etc\intrinsic.natvis" "/NATVIS:C:\Users\username\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\etc\liballoc.natvis" "/NATVIS:C:\Users\username\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\etc\libcore.natvis" "/NATVIS:C:\Users\username\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\etc\libstd.natvis" "-fuse-ld=lld"
= note: Non-UTF-8 output: LINK : warning LNK4044: \xce\xde\xb7\xa8\xca\xb6\xb1\xf0\xb5\xc4\xd1\xa1\xcf\xee\xa1\xb0/fuse-ld=lld\xa1\xb1\xa3\xbb\xd2\xd1\xba\xf6\xc2\xd4\r\nlibmagick_rust-eafa453c03e29a83.rlib(magick_rust-eafa453c03e29a83.magick_rust.01cfdc8e-cgu.1.rcgu.o) : error LNK2019: \xce\xde\xb7\xa8\xbd\xe2\xce\xf6\xb5\xc4\xcd\xe2\xb2\xbf\xb7\xfb\xba\xc5 SetMagickResourceLimit\xa3\xac\xba\xaf\xca\xfd _ZN11magick_rust4wand6magick10MagickWand18set_resource_limit17h31d530d13a9f0a41E \xd6\xd0\xd2\xfd\xd3\xc3\xc1\xcb\xb8\xc3\xb7\xfb\xba\xc5\r\nc:\Users\username\cargo_target_dir\debug\deps\get_colorspace.exe : fatal error LNK1120: 1 \xb8\xf6\xce\xde\xb7\xa8\xbd\xe2\xce\xf6\xb5\xc4\xcd\xe2\xb2\xbf\xc3\xfc\xc1\xee\r\nwarning:
get_colorspace
(bin "get_colorspace") generated 1 warning
error: could not compileget_colorspace
due to previous error; 1 warning emitted
So I decoded the last part of note
with gbk encoding, which says something like:
libmagick_rust-eafa453c03e29a83.rlib(magick_rust-eafa453c03e29a83.magick_rust.01cfdc8e-cgu.1.rcgu.o) : error LNK2019:
unresolved external symbol SetMagickResourceLimit
,function _ZN11magick_rust4wand6magick10MagickWand18set_resource_limit17h31d530d13a9f0a41E refer to this sumbol\r\nc:\Users\username\cargo_target_dir\debug\deps\get_colorspace.exe : fatal error LNK1120: 1 unresolved external command\r\n
Hello, I am on Windows and use the gnu toolchain for multiple reasons, but when I try to compile I get this panic :
thread 'main' panicked at 'ImageMagick libdirs at `["D:/msys/mingw64/bin/../lib"]` do not contain the required files to either statically
or dynamically link ImageMagick', D:\.cargo\registry\src\github.com-1ecc6299db9ec823\magick_rust-0.14.0\build.rs:220:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
How can I fix this?
Write some documentation on how to use the library, with complete, compilable examples.
Might be an easily answered question if I looked harder, but is it possible to take a raw RGBA buffer and pass it to ImageMagick using this crate?
I imagine it will be some mixture of read_image_blob
, but I need some way to tell ImageMagick the dimensions of the image. Am I on the right track, or is this not possible at the moment?
Supporting both ImageMagick 6.x and 7.x will likely be difficult, as the API has changed in many places. The header file layout has also changed. The build.rs
must generate a gen.h
that includes MagickWand/MagickWand.h
rather than wand/MagickWand.h
, as in 6.x.
Other functions have changed or been removed (see deprecated.h
).
As such, once 7.x becomes widespread (i.e. FreeBSD and Homebrew) then switch to the new version and update all of the code.
Hello, i have recently started working on a wallpaper daemon and had to deal with resizing GIFs. Using the other crates resulted in a long, resource-consuming process, I didn't want to deal with. So I am trying to use magick-rust instead.
Now the normal read_image
+ resize
+ write
doesn't seem to work, and results in a static image instead. If i even just read a image, and write it instantly, it still results in a static image. So i am curious on how i can resize a gif image?
Thats all, thanks.
What is the equivalent functions of --draw
, --fill
or --stroke
commands and so on? I looked up the source code but didn't understand how can I use it.
Is there any plan to add this crates.io? I would rather not pin a specific commit so we can get upstream patches in the future.
Everything compiles fine, but 5 out of 6 tests fail. Example:
---- test_read_from_blob stdout ----
thread 'test_read_from_blob' panicked at 'assertion failed: wand.read_image_blob(data).is_ok()', tests/lib.rs:80
stack backtrace:
1: 0x7f6dc27511e0 - sys::backtrace::tracing::imp::write::hdd9eea771561f811lbu
...
Note: test_new_drop() does succeed.
I tried with a Dec 21 nightly. Should I use a different Rust version?
I compiled/tested against ImageMagick libMagickCore-6.Q16.so.2.0.0
Thanks!
cargo build
Compiling magick_rust v0.5.2
error[E0425]: unresolved name `bindings::MagickAutoOrientImage`
--> /Users/gjtorikian/.cargo/registry/src/github.com-1ecc6299db9ec823/magick_rust-0.5.2/src/wand/magick.rs:184:13
|
184 | bindings::MagickAutoOrientImage(self.wand) == bindings::MagickTrue
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unresolved name
error: aborting due to previous error
error: Could not compile `magick_rust`.
cargo -V
cargo 0.13.0-nightly (26dcd3e 2016-09-26)
rustc -V
rustc 1.13.0-beta.1 (cbbeba430 2016-09-28)
Using the rust-bindgen
crate in build.rs
to generate the MagickWand bindings on FreeBSD 11 causes cargo test
to fail miserably. It looks as though the linker does not like the Dwarf file format.
/usr/bin/ld: Dwarf Error: found dwarf version '4', this reader only handles version 2 information.
However, that may be a red herring, and something else entirely is causing the problem.
The new release of ImageMagick 7 changes the structure of the header files. The gen.h
file that is created using build.rs
does not reflect that new structure. The build will fail because #include <wand/MagickWand.h>
is no longer correct.
Also, https://github.com/nlfiedler/magick-rust/blob/master/vagrant/ubuntu14/fabfile.py currently downloads the latest stable build. This transparently switched from ImageMagick 6.9 to ImageMagick 7. We may want to consider being more explicit with the version.
The old rust-bindgen crate (https://github.com/Yamakaky/rust-bindgen) has been deprecated, and Mozilla has taken over development. The new crate is at https://github.com/servo/rust-bindgen and a tutorial of sorts is available here: http://fitzgeraldnick.com/2016/12/14/using-libbindgen-in-build-rs.html
Note that we need to set environment variables in order to build the ImageMagick bindings, so using the library may not be feasible. But at least we can switch to the new crate.
This may help with issue #16.
Not sure what I'm doing wrong here, but it looks like bindgen is spitting out some duplicate definitions when I'm trying to link against ImageMagick 7.0.7-11. Any thoughts? Thanks!
error[E0428]: the name `FP_INT_UPWARD` is defined multiple times
--> /home/nprice/Projects/wallaby/target/debug/build/magick_rust-3098943e623803c3/out/bindings.rs:3353:1
|
748 | pub const FP_INT_UPWARD: libc::c_uint = 0;
| ------------------------------------------ previous definition of the value `FP_INT_UPWARD` here
...
3353 | pub const FP_INT_UPWARD: _bindgen_ty_1 = _bindgen_ty_1::FP_INT_UPWARD;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `FP_INT_UPWARD` redefined here
|
= note: `FP_INT_UPWARD` must be defined only once in the value namespace of this module
error[E0428]: the name `FP_INT_DOWNWARD` is defined multiple times
--> /home/nprice/Projects/wallaby/target/debug/build/magick_rust-3098943e623803c3/out/bindings.rs:3354:1
|
749 | pub const FP_INT_DOWNWARD: libc::c_uint = 1;
| -------------------------------------------- previous definition of the value `FP_INT_DOWNWARD` here
...
3354 | pub const FP_INT_DOWNWARD: _bindgen_ty_1 = _bindgen_ty_1::FP_INT_DOWNWARD;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `FP_INT_DOWNWARD` redefined here
|
= note: `FP_INT_DOWNWARD` must be defined only once in the value namespace of this module
error[E0428]: the name `FP_INT_TOWARDZERO` is defined multiple times
--> /home/nprice/Projects/wallaby/target/debug/build/magick_rust-3098943e623803c3/out/bindings.rs:3355:1
|
750 | pub const FP_INT_TOWARDZERO: libc::c_uint = 2;
| ---------------------------------------------- previous definition of the value `FP_INT_TOWARDZERO` here
...
3355 | pub const FP_INT_TOWARDZERO: _bindgen_ty_1 = _bindgen_ty_1::FP_INT_TOWARDZERO;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `FP_INT_TOWARDZERO` redefined here
|
= note: `FP_INT_TOWARDZERO` must be defined only once in the value namespace of this module
error[E0428]: the name `FP_INT_TONEARESTFROMZERO` is defined multiple times
--> /home/nprice/Projects/wallaby/target/debug/build/magick_rust-3098943e623803c3/out/bindings.rs:3356:1
|
751 | pub const FP_INT_TONEARESTFROMZERO: libc::c_uint = 3;
| ----------------------------------------------------- previous definition of the value `FP_INT_TONEARESTFROMZERO` here
...
3356 | / pub const FP_INT_TONEARESTFROMZERO: _bindgen_ty_1 =
3357 | | _bindgen_ty_1::FP_INT_TONEARESTFROMZERO;
| |____________________________________________^ `FP_INT_TONEARESTFROMZERO` redefined here
|
= note: `FP_INT_TONEARESTFROMZERO` must be defined only once in the value namespace of this module
error[E0428]: the name `FP_INT_TONEAREST` is defined multiple times
--> /home/nprice/Projects/wallaby/target/debug/build/magick_rust-3098943e623803c3/out/bindings.rs:3358:1
|
752 | pub const FP_INT_TONEAREST: libc::c_uint = 4;
| --------------------------------------------- previous definition of the value `FP_INT_TONEAREST` here
...
3358 | pub const FP_INT_TONEAREST: _bindgen_ty_1 = _bindgen_ty_1::FP_INT_TONEAREST;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `FP_INT_TONEAREST` redefined here
|
= note: `FP_INT_TONEAREST` must be defined only once in the value namespace of this module
error: aborting due to 5 previous errors
error: Could not compile `magick_rust`.
To learn more, run the command again with --verbose.
Is it possible to embed image magick ? (I mean having all the lib statically linked in the binary)
How would I go about doing this?
magick $1 -crop \
`magick $1 -virtual-pixel edge -blur 0x15 -fuzz 15% \
-trim -format '%wx%h%O' info:` +repage $2
I'm not looking for an exact answer, just how to approach the problem. I assume two distinct wand, but I'd like to see an example.
More recent versions of rust-bindgen have added support for proper Rust enums. As such, the wrapper code could be made more Rustic (Rust idiomatic). This would be achieved by removing the --no-rust-enums
option in the build.rs
build script, and then fixing all of the compiler errors.
I have this error with magick-rust 0.9. 0.8 seems fine.
Windows
ImageMagick-7.0.7-31
nightly-x86_64-pc-windows-msvc (default)
rustc 1.27.0-nightly (428ea5f6b 2018-05-06)
error[E0425]: cannot find value `QuantumRange` in module `bindings`
--> C:\Users\bbigras\.cargo\registry\src\github.com-1ecc6299db9ec823\magick_rust-0.9.0\src\wand\magick.rs:337:80
|
337 | if bindings::MagickSepiaToneImage(self.wand, threshold * bindings::QuantumRange) == bindings::MagickBooleanType::MagickTrue {
|
^^^^^^^^^^^^ not found in `bindings`
error: aborting due to previous error
The MagickWand API supports image lists. For example, opening a GIF animation puts each frame into a list attached to that wand. List items can be deleted, edited individually, and even composited into a single image.
Looking through the code, this seems partially supported, but difficult to use. A caller would have to manually manipulate the wand's image iterator with getters and setters without any external state consistency. (One function could change the iterator's position and not clean it up before another unrelated call, resulting in unexpected outcomes.)
It would be nice if the internal iterator could be borrowed and reset automatically, more like this:
let w = MagickWand::new(...);
w.read_image("input.gif")?
{
let last_frame = w.images().last(); // moves the iterator to the last image and returns a borrow
let also_last_frame = w.images().index(w.images().count()); // same as above
let last_dim = last_frame.get_image_size(); // this != the frame size for an optimized GIF
println!("The last image is {} pixels wide and {} pixels high", last_dim.0, last_dim.1);
}
{
// Make a message appear for one frame
let first_frame = w.images_mut().first(); // same construction as above, but returns mutable borrows
let draw = DrawingWand::new()?
draw.set_size(12)?
draw.draw_annotation("Behold!", 0, 0)?
first_frame.draw_image(draw)?
}
// Now make a second message scroll down the image
let (ww, wh, wx, wy) = w.get_image_page();
let nframes = w.images().count();
for (n, &mut frame) in w.images_mut().enumerate() {
let draw = DrawingWand::new()?
draw.set_size(12)?
draw.draw_annotation("Moving text", 0, ((wh as f32) * (n as f32) / (nframes as f32)) / 2)?
frame.draw_image(draw)?
}
// We're done, write it out
w.write_image("output.gif")?
EDIT: fixed a bug in my example code
Currently, is there a way to accomplish that? In order words, is there a way to replicate this?
#!/bin/bash
for f in *.png; do
# Remove background
magick "$f" \
-fill none -fuzz 75% -draw "alpha 0,0 floodfill" \
"temp_no_background_$f"
done
I asked this question on Reddit:
https://www.reddit.com/r/learnrust/comments/12ql8hi/removing_background_of_image_using_magickrust/
When trying to compile magic_rust 0.4.0, I get an internal compiler error. I am using CentOS 6.7 and see this error on both Rust stable (1.9) and nightly.
$ cargo build
Updating registry `https://github.com/rust-lang/crates.io-index`
Compiling libc v0.2.12
Compiling magick_rust v0.4.0 (file:///home/vagrant/magick-rust)
src/wand/macros.rs:7:28: 20:16 error: type name `bindings::MagickWand` is undefined or not in scope [E0412]
(internal compiler error: unprintable span)
src/wand/magick.rs:19:1: 23:3 note: in this expansion of wand_common! (defined in src/wand/macros.rs)
src/wand/macros.rs:7:28: 20:16 help: run `rustc --explain E0412` to see a detailed explanation
src/wand/macros.rs:7:28: 20:16 help: you can import it into scope: `use wand::magick::MagickWand;`.
cargo build --verbose
,get some errors like below:[root@localhost magick-rust]# cargo build --verbose
Compiling libc v0.2.10
Running rustc /root/.cargo/registry/src/github.com-88ac128001ac3a9a/libc-0.2.10/src/lib.rs --crate-name libc --crate-type lib -g --cfg feature=\"default\" --cfg feature=\"use_std\" -C metadata=12d5d911cf5411c3 -C extra-filename=-12d5d911cf5411c3 --out-dir /root/projects/magick-rust/target/debug/deps --emit=dep-info,link -L dependency=/root/projects/magick-rust/target/debug/deps -L dependency=/root/projects/magick-rust/target/debug/deps --cap-lints allow
Compiling magick_rust v0.4.0 (file:///root/projects/magick-rust)
Running rustc build.rs --crate-name build_script_build --crate-type bin -g --out-dir /root/projects/magick-rust/target/debug/build/magick_rust-69f577ee4bd14cfc --emit=dep-info,link -L dependency=/root/projects/magick-rust/target/debug -L dependency=/root/projects/magick-rust/target/debug/deps
Running /root/projects/magick-rust/target/debug/build/magick_rust-69f577ee4bd14cfc/build-script-build
Build failed, waiting for other jobs to finish...
failed to run custom build command for magick_rust v0.4.0 (file:///root/projects/magick-rust)
Process didn't exit successfully: /root/projects/magick-rust/target/debug/build/magick_rust-69f577ee4bd14cfc/build-script-build
(exit code: 101)
--- stdout
/usr/bin/MagickWand-config
--- stderr
thread '
Result::unwrap()
on an Err
value: Error { repr: Os { code: 2, message: "No such file or directory" } }', ../src/libcore/result.rs:688It seems like the rust-bindgen tool does not like certain C types in the FreeBSD headers. In particular, it seems to choke on the structs. While this is well hidden when invoking cargo build
, it is possible to see the output when invoking bindgen
directly.
I'm using a cargo-cross setup to compile a project that uses magick-rust
in a docker container. But while the other -sys
crates can be built, magick-rust fails with this error:
error: failed to run custom build command for `magick_rust v0.8.0`
process didn't exit successfully: `/target/debug/build/magick_rust-d97c639e6e935b43/build-script-build`
(exit code: 101)
--- stdout
cargo:rerun-if-env-changed=IMAGE_MAGICK_LIB_DIRS
cargo:rerun-if-env-changed=IMAGE_MAGICK_DIR
cargo:rustc-link-search=native=/usr/local/lib
cargo:rerun-if-env-changed=IMAGE_MAGICK_INCLUDE_DIRS
cargo:rerun-if-env-changed=IMAGE_MAGICK_DIR
cargo:include=/usr/local/include/ImageMagick-7
cargo:rerun-if-env-changed=IMAGE_MAGICK_LIBS
cargo:rerun-if-env-changed=IMAGE_MAGICK_STATIC
cargo:rustc-link-lib=dylib=MagickWand-7.Q16HDRI
cargo:rustc-link-lib=dylib=MagickCore-7.Q16HDRI
--- stderr
thread 'main' panicked at 'Unable to find libclang: "couldn\'t find any of [\'libclang.so\', \'libclang.so.*\',
\'libclang-*.so\'], set the LIBCLANG_PATH environment variable to a path where one of these files
can be found (skipped: [(/usr/lib/arm-linux-gnueabihf/libclang-3.8.so: invalid ELF class (32-bit)),
(/usr/lib/llvm-3.8/lib/libclang-3.8.1.so: invalid ELF class (32-bit))])"',
libcore/result.rs:945:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.
Not really sure what to do here? The library it needs is installed, even for armhf. But I think magick-rust
doesn't realise this? Because it just skips the library it should link against 😞
Like the rust-rocksdb crate, should have a "sys" crate for the native library, imagemagick. This would make the setup and build a little easier, and may help with generating the API docs on docs.rs (it works for rust-rocksdb, so maybe there is hope).
I have ImageMagick 7.1.0-4
installed and get the message MagickWand version must be no higher than 7.1
when building the library.
❯ magick --version
Version: ImageMagick 7.1.0-4 Q16 x86_64 2021-07-18 https://imagemagick.org
❯ cargo build
...
--- stderr
thread 'main' panicked at 'MagickWand version must be no higher than 7.1', /Users/dansandland/.cargo/registry/src/github.com-1ecc6299db9ec823/magick_rust-0.14.0/build.rs:252:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
The functions in this crate return very generic error messages, like "failed to write image". Would it be possible to give more information about exactly what failed?
The most recent bindgen release (0.42.0) causes many compiler warnings and errors with magick-rust. These are probably pretty easy to fix, so now's a good time to take care of that, before we fall too far behind to be manageable.
$ RUST_BACKTRACE=1 cargo build
Compiling magick_rust v0.6.1 (file:///home/zz/src/external/magick-rust)
error: failed to run custom build command for magick_rust v0.6.1 (file:///home/zz/src/external/magick-rust)
process didn't exit successfully: /home/zz/src/external/magick-rust/target/debug/build/magick_rust-79a7ed904c8f6b4d/build-script-build
(exit code: 101)
--- stderr
thread 'main' panicked at 'called Result::unwrap()
on an Err
value: Error { repr: Os { code: 2, message: "No such file or directory" } }', ../src/libcore/result.rs:783
stack backtrace:
11: 0x55c980e2d36b - build_script_build::assert_mw_version::h77cf9f50013c43d3
at /home/sc/src/external/magick-rust/build.rs:125
System: Ubuntu 14
Solution:
sudo apt-get install pkg-config
Maybe add that to the list of dependencies that must be installed?
Thanks for all of your effort with magick-rust!
Is there a way to limit the number of allowed threads to use?
Command Line client supports that through -limit thread 1
argument
Is it possible to set the interlace scheme?
I only found this option in the source code:
use magick_rust::{MagickWand};
fn main {
START.call_once(|| {
magick_wand_genesis();
});
let mut wand = MagickWand::new();
wand.read_image(image_path)?;
wand.set_interlace_scheme(1)?;
}
What about magick input.jpg -interlace [SCHEME] output.jpg
?
Schemes:
Line
None
Plane
Partition
GIF
JPEG
PNG
I tried to use wand.set_option("interlace", "Plane")
, but that didn't work either.
Could you please tell what the u32
in set_interlace_scheme
is supposed to do?
They didn't mention that in their docs.
Thank you! 🦀
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.