Created
August 4, 2023 09:34
-
-
Save prgrmr-yn/a556592ee8a8235c94811afafd3a5254 to your computer and use it in GitHub Desktop.
Instantly convert heic to jpg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'shellwords' | |
files = `find . -iname '*.heic'`.split("\n") | |
files.each do |original_file| | |
output_file = original_file.gsub(/\.heic\z/i, ' Converted.jpg') | |
if File.exist?(output_file) | |
STDERR.puts "Skipping output #{output_file} exists." | |
else | |
cmd = "convert #{Shellwords.escape(original_file)} #{Shellwords.escape(output_file)}" | |
puts cmd | |
success = system(cmd) | |
if success | |
File.delete(original_file) # Deletes the original file if the conversion was successful | |
puts "Deleted original file: #{original_file}" | |
else | |
puts "Conversion failed for file: #{original_file}" | |
end | |
end | |
end |
If you would like to make it a c executable and click the program instead
make a c file called heic-to-jpg.c and in that file add the code
C Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main() {
// Use the system function to execute the Ruby script
int result = system("ruby heictojpg.rb");
if (result == -1) {
perror("Error executing Ruby script");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
END C Code
Now compile the c code by typing in terminal:
gcc -o heic-to-jpg heic-to-jpg.c
now you have the executable file that you can just double click to open.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Most of the time when you airdrop image, it goes to downloads, so what you wanna do is open your terminal
Step 1-cd /Users/${your computer name}/Downloads
Step 2- touch heic-to-jpg.rb
Step 3- Open that file in text editor and paste the above code
Step 4- Now in your terminal type chmod 755 ./heic-to-jpg.rb
Step 5- Simply run ./heic-to-jpg.rb and see the magic