Kitz Forum

Computer Software => Linux => Topic started by: tickmike on February 10, 2021, 08:56:52 PM

Title: High Efficiency Image File Format (HEIC)
Post 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 ?.

Title: Re: High Efficiency Image File Format (HEIC)
Post by: burakkucat on February 10, 2021, 10:16:56 PM
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.
Title: Re: High Efficiency Image File Format (HEIC)
Post by: Alex Atkin UK on February 10, 2021, 10:43:26 PM
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:
Code: [Select]
#!/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.
Title: Re: High Efficiency Image File Format (HEIC)
Post by: petef on February 10, 2021, 11:38:53 PM
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
Title: Re: High Efficiency Image File Format (HEIC)
Post by: Alex Atkin UK on February 11, 2021, 01:39:13 PM
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.
Title: Re: High Efficiency Image File Format (HEIC)
Post by: broadstairs on February 11, 2021, 04:09:50 PM
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
Title: Re: High Efficiency Image File Format (HEIC)
Post by: tickmike on February 12, 2021, 04:34:41 PM
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.
Title: Re: High Efficiency Image File Format (HEIC)
Post by: Alex Atkin UK on February 12, 2021, 05:14:05 PM
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.
Title: Re: High Efficiency Image File Format (HEIC)
Post by: broadstairs on February 12, 2021, 08:15:25 PM
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
Title: Re: High Efficiency Image File Format (HEIC)
Post by: tickmike on February 12, 2021, 09:33:27 PM
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:
Title: Re: High Efficiency Image File Format (HEIC)
Post by: Alex Atkin UK on February 12, 2021, 10:09:25 PM
Sounds like the version of ImageMagick is too old and doesn't have HEIC support, or maybe there's a library missing?
Title: Re: High Efficiency Image File Format (HEIC)
Post by: petef on February 15, 2021, 12:04:03 AM
This is what I see on openSUSE Tumbleweed.

Code: [Select]
$ 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
Title: Re: High Efficiency Image File Format (HEIC)
Post by: Alex Atkin UK on February 15, 2021, 06:20:12 AM
https://forums.opensuse.org/showthread.php/549529-HEIC-support-of-imagemagick-gimp-and-krita-not-working-but-showFoto-works
Title: Re: High Efficiency Image File Format (HEIC)
Post by: tickmike on February 15, 2021, 10:14:07 PM
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.
Title: Re: High Efficiency Image File Format (HEIC)
Post by: broadstairs on February 16, 2021, 09:36:05 AM
I have openSUSE Tumbleweed and it has

Code: [Select]
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
Title: Re: High Efficiency Image File Format (HEIC)
Post by: tickmike on February 16, 2021, 02:35:32 PM
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.
Title: Re: High Efficiency Image File Format (HEIC)
Post by: petef on February 16, 2021, 03:47:19 PM
I have openSUSE Tumbleweed and it has

Code: [Select]
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.
Title: Re: High Efficiency Image File Format (HEIC)
Post by: petef on February 16, 2021, 11:29:58 PM
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.
Title: Re: High Efficiency Image File Format (HEIC)
Post by: broadstairs on February 17, 2021, 09:51:04 AM
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.
Title: Re: High Efficiency Image File Format (HEIC)
Post by: tickmike on February 17, 2021, 12:23:46 PM
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.


Title: Re: High Efficiency Image File Format (HEIC)
Post by: broadstairs on February 17, 2021, 02:09:04 PM
On my system the usage is

Code: [Select]
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
Title: Re: High Efficiency Image File Format (HEIC)
Post by: tickmike on February 17, 2021, 02:16:29 PM
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 :)
Title: Re: High Efficiency Image File Format (HEIC)
Post by: broadstairs on February 17, 2021, 03:14:12 PM
I just issued

Code: [Select]
heif-convert -q 100 sample.heic sample.jpg

Stuart
Title: Re: High Efficiency Image File Format (HEIC)
Post by: tickmike on February 17, 2021, 08:50:08 PM
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 ?.
Title: Re: High Efficiency Image File Format (HEIC)
Post by: broadstairs on February 17, 2021, 10:06:21 PM
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
Title: Re: High Efficiency Image File Format (HEIC)
Post by: petef on February 17, 2021, 11:41:56 PM
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

Code: [Select]
type rm
rm is aliased to `rm -i'

One way to avoid the alias is to stick in a backslash.

Code: [Select]
r\m *.heic
Title: Re: High Efficiency Image File Format (HEIC)
Post by: Alex Atkin UK on February 18, 2021, 01:24:59 AM
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.