Created
November 30, 2021 12:26
-
-
Save mbeltagy/7993dd86d566dc45895a36172d70526d to your computer and use it in GitHub Desktop.
Using Julia and ImageMagick to convert an directory of images from png 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
input_dir = "images_need_fix/" | |
output_dir = "images_fixed/" | |
input_files = readdir(input_dir) | |
filter!(x->endswith(x,"png"),input_files) | |
for f in input_files | |
input_base_name = splitext(f)[1] | |
output_file_name = input_base_name*".jpg" | |
from = joinpath(input_dir,f) | |
to = joinpath(output_dir,output_file_name) | |
println("converting $from to $to") | |
run(`convert -strip -interlace Plane -gaussian-blur 0.05 -quality 85% $from $to`) | |
if filesize(from) < filesize(to) | |
println("re-writing $from to $to") | |
cp(from,to,force=true) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment