Introduction
The way we manage documents and media files has significantly evolved. Many of us have transitioned to using online document management systems to organize our work more efficiently. However, these systems are not always compatible with every file type.
Recently, I ran into an issue while using my online document management system; it couldn’t recognize the HEIC file format, a popular image file format used by Apple devices. As a result, I was unable to view these images from my browser.
The solution? Convert HEIC files to a more universally accepted format, like JPG. Fortunately, macOS provides an easy way to perform this conversion using a built-in command-line utility called `sips`. Here’s how to do it.
Step 1: Open Terminal
The first step is to open the Terminal application. You can do this by searching for Terminal in Spotlight (press Command+Space and type ‘Terminal’).
Step 2: Create a Bash Script
A Bash script is a plain text file which contains a series of commands. These commands are a sequence of orders that a user can give to a computer’s operating system.
Open a text editor of your choice (like nano, vim, or Atom), and create a new file with a `.sh` extension (for instance, `convert_heic_to_jpg.sh`). Then, copy and paste the following code into your new file:
#!/bin/bash
# Folder where the HEIC files are located
input_folder="/path/to/your/input/folder"
# Folder where you want the JPG files to be saved
output_folder="/path/to/your/output/folder"
# Loop over the files in the input folder
for file in "$input_folder"/*.heic
do
# Extract the file name
filename=$(basename "$file")
base="${filename%.heic}"
# Convert the file to JPG
sips -s format jpeg "$file" --out "$output_folder/$base.jpg"
done
Don’t forget to replace `”/path/to/your/input/folder”` and `”/path/to/your/output/folder”` with the actual paths to your folders.
Step 3: Make the Script Executable
Save the file and close your text editor. Then, go back to your Terminal window.
We’ll need to make the script executable, which you can do with the `chmod` command:
chmod +x /path/to/your/script/convert_heic_to_jpg.sh
Replace ”/path/to/your/script/convert_heic_to_jpg.sh” with the actual path to your script file.
Step 4: Run the Script
Now you’re ready to run the script. In your Terminal, execute the following command:
/path/to/your/script/convert_heic_to_jpg.sh
Again, replace ”/path/to/your/script/convert_heic_to_jpg.sh” with the actual path to your script file.
The script will now go through your specified input folder and convert all HEIC files to JPG, saving the converted images in your specified output folder.
Conclusion
There you have it! You’ve just converted your HEIC files to JPG format using a simple bash script on macOS. This solution is particularly helpful when working with online systems that do not recognize the HEIC file format, allowing you to view and manage your images directly from your browser.
Remember to always back up your original images before running any conversion scripts to prevent any accidental data loss.