Rust bindings to libgphoto2
What about gphoto-rs?
I know about the other crate (gphoto and gphoto2-sys which was created by @dcuddeback, but it is missing a lot of features which make the crate unusable for me, most notably the ability to change camera settings and in memory file download.
The author hasn't been active since 2017 regardless of numerous pull- and feature requests, so I made a new project with a more up to date rust code and all the features from libgphoto2.
- Camera
- Capture images
- Capture preview images
- Download images
- Get port information
- Get abilities (model, driver stability, permissions, ...)
- Read configuration
- Set configuration
- Interact with filesystem on camera
- Camera events
- Usb port information
- Context
- Autodetect camera
- Get list of available cameras
- Get camera by model and port
Run cargo add gphoto2
to add gphoto2 to your project or add this to your Cargo.toml
:
[dependencies]
gphoto2 = "1"
The libgphoto2
library must be installed on your system to use this library.
To install libgphoto2 on Debian based systems run:
sudo apt install libgphoto2-dev
On Arch systems run:
sudo pacman -S libgphoto2
On MacOS systems with Homebrew run:
homebrew install libgphoto2
There is no official way to install libgphoto2 on windows, but you can install it with MSYS2 (link to the package: mingw-w64-libgphoto2).
This example takes a picture and saves it to disk
use gphoto2::{Context, Result};
use std::path::Path;
fn main() -> Result<()> {
// Create a new context and detect the first camera from it
let camera = Context::new()?.autodetect_camera().expect("Failed to autodetect camera");
let camera_fs = camera.fs();
// And take pictures
let file_path = camera.capture_image().expect("Could not capture image");
camera_fs.download_to(&file_path.name(), &file_path.folder(), Path::new(&file_path.name().to_string()))?;
// For more advanced examples take a look at the examples/ folder
Ok(())
}
You can find more examples here
In general all all APIs should be stable, I've tested the ones my camera supported and found no bugs so far.
If you encounter an error like BAD_PARAMETERS
or found a bug, please create an issue on GitHub.
Copyright © 2022 Maxicarlos08 maxicarlos08@gmail.com
This library uses the libgphoto2
library, which is
licensed under the LGPL version 2.1.