Kitz Forum
Computer Software => Linux => Topic started by: tickmike on February 10, 2021, 08:56:52 PM
-
My Daughter has downloaded hundreds of Photo's (HEIC) format files to her Linux laptop from her iPhone mixed with other JPG photo files in her Picture Directory.
Without going through each one to covert it to view it she wants to know how can they all be converted in one go to JPG ?.
-
If you know how to manually convert a HEIC format file to a JPEG format file (I don't) then it should be quite simple. Something like --
for I in $(ls -1 *.HEIC)
do convert $I
done
Where convert is the relevant utility to perform the conversion.
-
If you know how to manually convert a HEIC format file to a JPEG format file (I don't) then it should be quite simple. Something like --
for I in $(ls -1 *.HEIC)
do convert $I
done
Where convert is the relevant utility to perform the conversion.
Ironically ImageMagick has a command called convert, so that's more or less correct.
Install ImageMagick and awk (probably already installed) from the package manager then create a script containing the following:
#!/bin/bash
for file in $(ls *.HEIC | awk '{ print substr($1,1,length($1)-5); }')
do
convert -quality 96 $file.HEIC $file.jpg
done
Remember Linux is case sensitive so if the extension is in lower-case then replace HEIC both times above with it in lower-case.
You may also want to tweak the quality of the output image, I think that option is kinda obvious.
-
The extra ls and awk can be done in bash. The double quotation marks allow for spaces in the filenames.
for f in *.HEIC; do convert "$f" -quality 96 "${f%.HEIC}.jpg"; done
-
The extra ls and awk can be done in bash. The double quotation marks allow for spaces in the filenames.
for f in *.HEIC; do convert "$f" -quality 96 "${f%.HEIC}.jpg"; done
Thanks, I knew that was possible but I couldn't remember the specifics.
-
If your daughter needs a tool with a gui then I can recommend digikam which is a photo management program and will convert these files, it has a batch tool which should do it. As long as all the relevant libraries are installed of course ::)
Stuart
-
Thanks all.
What I plan to do as my Daughter lives 160 miles away, her laptop is backed up to my server so once that has been done to extract some of these HEIC files along with a typical mix of her photo directory then put them on my spare laptop and have a play to see what will be the best way for her (or me over 'teamviewer' ) to batch convert them.
@ broadstairs re 'digikam'
Yes that's already installed as with 'GIMP' and 'Gwenview'.
So yes that might be the way forwards as long as they can do them in bulk.
I know she as been using 'GIMP' to convert the odd photo but there are hundreds to convert.
-
I always use batch files as its quicker than GUI where you usually have to click on each one, especially if its spread across multiple folders you can just make a bash alias to the script. Plus its just plain more reliable.
-
Digikam has quite a good batch process where you can give it a pattern to select with. I grant you if you are familiar with the CLI then its fine but if not the extra time using a gui can be safer ;)
Stuart
-
First test, I have placed one heic photo in a test directory, opened 'Konsole' in that directory and tried your scrips, both have the same output.
$ #!/bin/bash
for file in $(ls *.heic | awk '{ print substr($1,1,length($1)-5); }')
do
convert -quality 96 $file.heic $file.jpg
done
convert: no decode delegate for this image format `HEIC' @ error/constitute.c/ReadImage/504.
convert: no images defined `2021-01-02_12-25-13_324.jpg' @ error/convert.c/ConvertImageCommand/3258.
$ #!/bin/bash
for f in *.heic; do convert "$f" -quality 96 "${f%.heic}.jpg"; done
convert: no decode delegate for this image format `HEIC' @ error/constitute.c/ReadImage/504.
convert: no images defined `2021-01-02_12-25-13_324.jpg' @ error/convert.c/ConvertImageCommand/3258
ImageMagick is already installed on this spare laptop.
I also tried opening the test photo with 'ImageMagick' and that also gave error message of ''no decode delegate for this image format''
I do not know what I'm doing with konsole and scrips. Help. :hmm:
-
Sounds like the version of ImageMagick is too old and doesn't have HEIC support, or maybe there's a library missing?
-
This is what I see on openSUSE Tumbleweed.
$ convert --version
Version: ImageMagick 7.0.10-59 Q16 x86_64 2021-01-24 https://imagemagick.org
Copyright: (C) 1999-2021 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules
Delegates (built-in): bzlib cairo djvu fftw fontconfig freetype heic jbig jng jp2 jpeg lcms lqr ltdl lzma openexr pangocairo png rsvg tiff webp wmf x xml zlib
-
https://forums.opensuse.org/showthread.php/549529-HEIC-support-of-imagemagick-gimp-and-krita-not-working-but-showFoto-works
-
I have
$ convert --version
Version: ImageMagick 6.9.9-9 Q16 x86_64 2019-12-15 http://www.imagemagick.org
Copyright: © 1999-2017 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP
Delegates (built-in): bzlib cairo djvu fftw fontconfig freetype gslib gvc jbig jng jp2 jpeg lcms lqr ltdl lzma openexr pangocairo png ps rsvg tiff webp wmf x xml zlib
I use PCLinuxOS and I put a request to have it updated.
-
I have openSUSE Tumbleweed and it has
convert --version
Version: ImageMagick 7.0.10-59 Q16 x86_64 2021-01-24 https://imagemagick.org
Copyright: (C) 1999-2021 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules
Delegates (built-in): bzlib cairo djvu fftw fontconfig freetype heic jbig jng jp2 jpeg lcms lqr ltdl lzma openexr pangocairo png rsvg tiff webp wmf x xml zlib
So PCLinux is some way behind. Even Leap 15.2 has V7.
Stuart
-
I have openSUSE Tumbleweed
So PCLinux is some way behind. Even Leap 15.2 has V7.
Stuart
Yes but they are working on it, it seems to be all the linked packages that goes with imagemagick.
-
I have openSUSE Tumbleweed and it has
convert --version
Version: ImageMagick 7.0.10-59 Q16 x86_64 2021-01-24 https://imagemagick.org
Copyright: (C) 1999-2021 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules
Delegates (built-in): bzlib cairo djvu fftw fontconfig freetype heic jbig jng jp2 jpeg lcms lqr ltdl lzma openexr pangocairo png rsvg tiff webp wmf x xml zlib
So PCLinux is some way behind. Even Leap 15.2 has V7.
Stuart
It might not be the version of ImageMagick perhaps it depends on other third party libraries being installed.
-
It might not be the version of ImageMagick perhaps it depends on other third party libraries being installed.
Indeed my ImageMagick was only able to identify the HEIC file not to convert it.
I added the codecs from the Packman repository and now the convert works.I don't know my way around the PCLinuxOS package ecosystem to recommend a direct answer for the OP. A batch conversion program other than ImageMagick may be the easier approach.
-
I always add packman to my installation. I do not have any HEIC format images available to test.
Stuart
Update:
I just downloaded a sample heic image and converted it to jpg using the batch process in digikam, so this does work in openSUSE Tumbleweed with packman stuff installed. The batch process allows multiple files to be selected and processed in a single run.
-
Found out we have a Lib file "heif-convert" in pclinuxos
So I wondered if I change the script above.
#!/bin/bash
for f in *.heic; do heif-convert "$f" "${f%.heic}.jpg"; done
I then opened 'konsole' in my test directory and run the script.
Much to my surprise it converted each of the photo's :) :thumbs:
Can any of the 'Script' experts have a look at what I have done above please and let me know if it needs to be adjusted at all before I send it to my daughter who has hundreds of these 'heic' photo files.
Thanks to all who have helped.
-
On my system the usage is
USAGE: heif-convert [-q quality 0..100] <filename> <output>
So all I would do is perhaps add the quality to the command as I have no idea what the default might be. Can you view the jpeg OK?
Stuart
-
Hi Stuart,
I did leave that in but it did not seem to like it so I removed it, can you try on that one heic photo you have please.
I will look tonight at the photos as it was past my bed time last night when i got it to work last night.
Just going to do some gardening while the suns out at 12c :)
-
I just issued
heif-convert -q 100 sample.heic sample.jpg
Stuart
-
So this works quite well :)
#!/bin/bash
for f in *.heic; do heif-convert "$f" -q 100 "${f%.heic}.jpg"; done
Edit..
How do I remove the .heic files in the containing directory only ?
If I open a terminal in the test directory and run
rm *.heic
I have to answer 'y' to each file it's removing.
How Do I 'Batch' remove .heic files ?.
-
It's easier using a file manager like dolphin (in KDE) where you can select all the files and just delete them. Using rm try rm --help to see usage. Be careful with rm though it can remove more than you might wish. Normally when converting files to a new format I keep the originals just in case.
Stuart
-
So this works quite well :)
#!/bin/bash
for f in *.heic; do heif-convert "$f" -q 100 "${f%.heic}.jpg"; done
Edit..
How do I remove the .heic files in the containing directory only ?
If I open a terminal in the test directory and run
rm *.heic
I have to answer 'y' to each file it's removing.
How Do I 'Batch' remove .heic files ?.
The standard rm command does not ask. However it is common practice to have an alias. That can be demonstrated
type rm
rm is aliased to `rm -i'
One way to avoid the alias is to stick in a backslash.
r\m *.heic
-
I believe it asks if you send it a list of files such as * but not for individual files.
I'd just use rm -f *.heif.