I have a folder where there are many pictures taken with my iPhone. Turns out that half of them are JPGs and half of them were supposed to be HEIC format.

For some reason, all pictures in this folder are with JPG extension, check this image: https://imgur.com/a/9D6ScZ4

First, I thought that other JPGs were corrupted files, as you can see in the image above that I got an error when I try to open them. Then, I realized they were supposed to be HEIC and not JPG, because they were Apple Live Photos. When I manually renamed couple of those JPG files that were not opening to HEIC format, they could open correctly as a short video, because they were live photos.

My question is: Is there a way to find all these false JPG files that do not open and rename them from .JPG to .HEIC? I can't just rename all JPGs to HEIC because the other pictures are not live photos.

1 Answer 1


If you have a command line program that can open JPG files but not HEIC you could run this program and use its exit code to determine if the file was a valid JPG or not.

You can try the convert program from imagemagick.

untested example:

for jpg in *.jpg
    heic="${jpg%.jpg}.heic"    # construct HEIC file name
    tmp="$jpg.png"             # temporary PNG file
    if ! convert "$jpg" "$tmp" # try to convert
        mv "$jpg" "$heic"      # rename if conversion failed
    rm -f "$tmp"               # PNG no longer needed

Of course this doesn't work if the convert program accepts HEIC files as input.

The example code was inspred by this: https://github.com/williamthing/Scripts/blob/master/Shell/jpg2png.sh


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.