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 hidden or 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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");
}
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.