38

I'd like to batch convert .heic images (e.g. iPhone photograph) to .jpg files with imagemagick, with the goal of retaining as much of the quality from the original image as possible. To be clear, the resulting output size is not a concern.

I've been using

magick input.heic -quality 100% output.jpg

Is it possible to do better?

11
  • Quality 100% in JPEG isn't any better than quality 95% and takes a lot more space. And to be realistic, since we are talking about overprocessed pictures from a smartphone, 85% should be enough...
    – xenoid
    Commented Dec 7, 2021 at 7:21
  • 1
    At 85-90% yoyu already preserving the "quality". For what it's worth, on expensive DLSRs, the JPEG quality is around 97%.
    – xenoid
    Commented Dec 8, 2021 at 8:28
  • 2
    @MarkSetchell One reason for wanting to avoid HEIC is that it's still less widely supported than JPEG. For example, to preview these files in Windows 10 File Explorer/open them in the Photos app, I would need to purchase a 0,99€ "extension" from Microsoft, in their App Store. :-/ Commented Jan 6, 2022 at 19:10
  • 1
    HEIC is lossless, but JPG is a lossy compression even at 100% quality. The -quality parameter is for writing the output not reading the input. So it only affects the output JPG. Bottom line, you will always lose quality when writing to JPG whether you start with HEIC or PNG or any lossless format input.
    – fmw42
    Commented Mar 17, 2022 at 19:33
  • 4
    @fmw42 HEIC is a higher quality than JPEG but it is a compressed format (using HEVC en.wikipedia.org/wiki/High_Efficiency_Video_Coding), not a lossless format.
    – ajgryc
    Commented Jun 26, 2023 at 22:17

2 Answers 2

26

You can batch convert HEIC to jpg with the following, but you'll lose quality:

magick mogrify -format jpg *.HEIC
5
  • 1
    I think you need the magick command before mogrify, is that right? So it's magick mogrify ....
    – Simon E.
    Commented Sep 5, 2023 at 0:43
  • usually one sets up one's path to include all the commands in the imagemagic bin directory, so you can just call mogrify directly, as that should be a command in that bin directory
    – duhaime
    Commented Sep 7, 2023 at 11:14
  • Oh I see. Perhaps that might be the case on Mac/Linux, but the official Windows binary I downloaded a couple of days ago is just a single magick.exe, which requires you to enter that first before any of the sub-utils. Hence your answer didn’t work for me initially.
    – Simon E.
    Commented Sep 8, 2023 at 0:39
  • ah yeah, the Windows port may require some additional care :)
    – duhaime
    Commented Sep 11, 2023 at 13:02
  • Pardon, I just edited it without reading all the comments. However I guess this way it's still better for others. Thanks for the answer, it helped me.
    – Til
    Commented Jun 18 at 19:47
6

No, its not possible to do better per ImageMagick's website for -quality switch. In 'Supported Image Formats' section scroll to JPEG as maybe there are other options that can be sure to limit any other quality changes inherit to converting.

Apparently HEIC & JPEG are both lossy compression image types. According to Adobe editing JPEG numerous times could slowly erode its quality whereas HEIC doesn't do that.

Because JPEG is a lossy file format, the files lose data each time you edit and resave an image. This means the quality of a file can degrade over time as you edit and re-edit, destroying more data each time.

HEICs, while also a lossy file format, tend to retain better image quality over time. They also store editing information, so even once you’ve saved edits to an image, you can reverse them in the future.

This quora answer says you may lose colors:

HEIF is also 16 bit colour depth as opposed to JPEGs 8 bit colour depth I can't quickly find an official industry specification page confirming that. HEIC can contain different files types inside it making it confusing.

2
  • Just a note: the original poster wants to output JPG images. The source format is HEIC but the output should be JPG. So the quote you provided from the website is not really relevant.
    – Simon E.
    Commented Sep 3, 2023 at 6:21
  • 1
    @SimonEast thank you for pointing out my glaring oversight. I changed my answer significantly. Over 2yr & no one mentioned & still upvoted, I guess we're all skimming or wanting answers that may not be true.
    – gregg
    Commented Sep 5, 2023 at 17:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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