Skip to content

Instantly share code, notes, and snippets.

@mbeltagy
Created November 30, 2021 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbeltagy/7993dd86d566dc45895a36172d70526d to your computer and use it in GitHub Desktop.
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
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