Compare commits
2 changed files with 54 additions and 19 deletions
21
flake.nix
21
flake.nix
|
|
@ -20,9 +20,6 @@
|
|||
name = cargoToml.package.name;
|
||||
|
||||
dlDeps = with pkgs; [
|
||||
# libdbus, for rfd
|
||||
dbus
|
||||
|
||||
# needed for both x11 and wayland
|
||||
libxkbcommon
|
||||
libGL
|
||||
|
|
@ -80,13 +77,19 @@
|
|||
// {
|
||||
inherit cargoArtifacts;
|
||||
|
||||
nativeBuildInputs = commonArgs.nativeBuildInputs ++ [
|
||||
nativeBuildInputs =
|
||||
commonArgs.nativeBuildInputs
|
||||
++ [
|
||||
pkgs.autoPatchelfHook
|
||||
];
|
||||
]
|
||||
++ lib.optional pkgs.stdenv.hostPlatform.isLinux pkgs.makeBinaryWrapper;
|
||||
|
||||
buildInputs = commonArgs.buildInputs ++ [
|
||||
buildInputs =
|
||||
commonArgs.buildInputs
|
||||
++ [
|
||||
pkgs.libgcc
|
||||
];
|
||||
]
|
||||
++ lib.optional pkgs.stdenv.hostPlatform.isLinux pkgs.zenity;
|
||||
|
||||
runtimeDependencies = dlDeps;
|
||||
|
||||
|
|
@ -95,6 +98,10 @@
|
|||
postFixup = ''
|
||||
mkdir -p "$out/share/applications"
|
||||
ln -s "${desktopItem}"/share/applications/* "$out/share/applications/"
|
||||
''
|
||||
+ lib.optionalString pkgs.stdenv.hostPlatform.isLinux /* sh */ ''
|
||||
wrapProgram $out/bin/${name} \
|
||||
--prefix PATH : ${lib.makeBinPath [ pkgs.zenity ]}
|
||||
'';
|
||||
}
|
||||
);
|
||||
|
|
|
|||
48
src/utils.rs
48
src/utils.rs
|
|
@ -1,20 +1,48 @@
|
|||
use std::path::{Path, PathBuf};
|
||||
|
||||
use iced::widget;
|
||||
use image::{DynamicImage, ImageDecoder, ImageReader, ImageResult, RgbaImage};
|
||||
use image::{DynamicImage, ImageDecoder, ImageReader, RgbaImage};
|
||||
use rfd::FileDialog;
|
||||
|
||||
pub fn load_image(path: impl AsRef<Path>) -> Result<RgbaImage, String> {
|
||||
_load_image(path).map_err(|e| e.to_string())
|
||||
}
|
||||
fn _load_image(path: impl AsRef<Path>) -> ImageResult<RgbaImage> {
|
||||
let mut decoder = ImageReader::open(path)?
|
||||
.with_guessed_format()?
|
||||
.into_decoder()?;
|
||||
let path = path.as_ref();
|
||||
|
||||
let oreintation = decoder.orientation()?;
|
||||
let image_reader = match ImageReader::open(path).and_then(|r| r.with_guessed_format()) {
|
||||
Ok(r) => r,
|
||||
Err(e) => {
|
||||
return Err(format!(
|
||||
"failed to create image reader for '{}': {e}",
|
||||
path.display()
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
let mut decoded_image = DynamicImage::from_decoder(decoder)?;
|
||||
let mut decoder = match image_reader.into_decoder() {
|
||||
Ok(d) => d,
|
||||
Err(e) => {
|
||||
return Err(format!(
|
||||
"failed to create decoder for '{}': {e}",
|
||||
path.display()
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
let oreintation = match decoder.orientation() {
|
||||
Ok(o) => o,
|
||||
Err(e) => {
|
||||
return Err(format!(
|
||||
"failed to get oreintation of '{}': {e}",
|
||||
path.display()
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
let mut decoded_image = match DynamicImage::from_decoder(decoder) {
|
||||
Ok(i) => i,
|
||||
Err(e) => {
|
||||
return Err(format!("failed to decode image '{}': {e}", path.display()));
|
||||
}
|
||||
};
|
||||
|
||||
decoded_image.apply_orientation(oreintation);
|
||||
|
||||
|
|
@ -47,7 +75,7 @@ pub fn save_image(image: Option<&RgbaImage>) -> Result<(), String> {
|
|||
};
|
||||
|
||||
if let Err(e) = image.save(&path) {
|
||||
return Err(e.to_string());
|
||||
return Err(format!("failed to save '{}': {e}", path.display()));
|
||||
};
|
||||
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Reference in a new issue