Skip to content

Commit

Permalink
Changed native functions to accept any parameters that can be referen…
Browse files Browse the repository at this point in the history
…ced as a Path. Functions updated are open_image and save_image. Fixes Issue silvia-odwyer#191
  • Loading branch information
silvia-odwyer committed Oct 31, 2024
1 parent e01c939 commit 941adf9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions crate/src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use image::DynamicImage::ImageRgba8;
use image::{GenericImageView, ImageBuffer};
use std::io;
use std::path::Path;
// use wasm_bindgen::prelude::*;
use crate::PhotonImage;
use thiserror::Error;
Expand Down Expand Up @@ -31,7 +32,10 @@ pub enum Error {
///
/// // ... image editing functionality here ...
/// ```
pub fn open_image(img_path: &str) -> Result<PhotonImage, Error> {
pub fn open_image<P>(img_path: P) -> Result<PhotonImage, Error>
where
P: AsRef<Path>,
{
let img = image::open(img_path)?;

let (width, height) = img.dimensions();
Expand Down Expand Up @@ -87,7 +91,10 @@ pub fn open_image_from_bytes(buffer: &[u8]) -> Result<PhotonImage, Error> {
/// // Save the image at the given path.
/// save_image(img,"manipulated_image.jpg").expect("Save failed");
/// ```
pub fn save_image(img: PhotonImage, img_path: &str) -> Result<(), Error> {
pub fn save_image<P>(img: PhotonImage, img_path: P) -> Result<(), Error>
where
P: AsRef<Path>,
{
let raw_pixels = img.raw_pixels;
let width = img.width;
let height = img.height;
Expand Down

0 comments on commit 941adf9

Please sign in to comment.