Now I want you to write another script, based on this one. With the following improvements.
- I want to provide a directory, so the script would work through all images files (jpg or png) inside.
- Backup the original directory (name_original).
- No need to rename the smallest image as featured, just keep the smallest image, I don’t need other images
- you can work with temporary storage on Linux {XDG_RUNTIME_DIR:-/tmp}, so you can copy only the smallest image to the new directory
- I want the new file (the smallest one that you copy from tmp to the directory) to keep the modification or creation date (whatever is the oldest) of the original file.
- if the provided argument is not a directory, but just a file (jpg or png), everything stays the same, but no need to
Better make it two iterations:
- Just a file
Now I want you to write another script, based on this one. With the following improvements.
- No need to rename the smallest image as
featured_
, just keep the smallest image, I don’t need other images - you can work with temporary storage on Linux {XDG_RUNTIME_DIR:-/tmp} and keep those other files there. Better create a new directory there, named %Y-%m-%d-%H%M (e.g. 2024-09-28-1640). No need to keep the original file in the provided to the script directory, you can move it to the new temporary directory.
- I want the new file to keep the modification time of the original file. Or creation time, whatever is the oldest.
I expect to provide my script a file (jpg or png) and it should replace it with the new file, of the smallest size.
- Directories
- I want to provide a directory, so the script would work through all images files (jpg or png) inside.
- Backup the original directory (name_original).
- if the provided argument is not a directory, but just a file (jpg or png), do as in the previous script
Great job! Now, I want to apply the script to the entire directory of images too.
- I want to provide a directory, so the script would work through all images files (jpg or png) inside.
- Leave the original directory as it is, and move the smallest files to the new directory, its name should be
original_dir_name
_compressed, e.g. screenshots_compressed. - All the processed files may stay at the tmp location, only the smallest files to the new directory.
- I don’t care about the directory timestamp, but I want all the new smallest files to keep the timestamp, as in the previous script.
- if the provided argument is not a directory, but just a single file (jpg or png), do as in the previous script too.
I want the script to work both ways, for a single file or entire directory.