Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(camera-app): Snapshot will get saved in the ~/Pictures directory. #178

Merged
merged 3 commits into from
Feb 6, 2025

Conversation

namana-mecha
Copy link
Contributor

Objective

Fixes #177

Solution

  • After taking the photo the app will save the photo in the ~/Pictures directory.
  • Pictures are saved in the format Snapshot_Ymd_HMS.jpg

Showcase

  • We get the local time using the chrono crate and the use the format function to correctly name the file.
  • We get the home directory using the environment variable HOME and create a Pictures directory in the home folder if it doesn't exist.
  • Then save the snapshot with the filename in the pictures directory.

The following code is added to contexts::camera::save_frame()

Click to view code
let now = chrono::Local::now();
let formatted_time = now.format("%Y%m%d_%H%M%S").to_string();
let mut pictures_dir = std::path::PathBuf::from(
    std::env::var("HOME").unwrap_or_else(|_| "/tmp".to_string()),
);
pictures_dir.push("Pictures");

if !pictures_dir.exists() {
    std::fs::create_dir_all(&pictures_dir)
        .expect("Couldn't create directory `Pictures`");
}

let filename = format!("Snapshot_{}.jpg", formatted_time);
let filepath = pictures_dir.join(&filename);
frame.save(filepath).unwrap();

- After taking the photo the app will save the photo in the `~/Pictures`
directory.
- Pictures are saved in the format `Snapshot_Ymd_HMS.jpg`
@akshayr-mecha akshayr-mecha merged commit 4d4547d into mecha-org:dev Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pictures taken from the camera are saved in the working directory itself.
2 participants