How to set grid of heif file when convert jpg to heic?

275 Views Asked by At

I tried to convert jpg to heic with ispe of grid.

I used heif-enc in Ubuntu, like below.

heif-enc -o output.heic input.jpg

It is converted without error, but "output.heic" metadata doesn't have ispe(image spatial extent) of grid. It only has ispe of image itself. By heif-enc, it is possible to add thumbnail ispe, but I cannot find way to set ispe of grid.

How can I set ispe of grid as 512x512(usual type)? It is best if there is a way using 'heif-enc' or any things else is ok.

2

There are 2 best solutions below

0
Tahir Bin Bashir On

Title: How to set the grid of a HEIF file when converting JPG to HEIC?

Converting JPG images to HEIC (High-Efficiency Image File Format) can significantly reduce file sizes while maintaining image quality. To set the grid of a HEIF file during the conversion process, you can use the libheif library along with libjpeg to handle the conversion. I'll guide you through the steps to achieve this on a Unix-like system (Linux, macOS) as well as Windows.

Step 1: Install necessary libraries and tools

Ensure you have libheif and libjpeg installed on your system:

Linux (Ubuntu/Debian):

sudo apt-get update
sudo apt-get install libheif-dev libjpeg-dev

macOS (Homebrew):

brew install libheif
brew install jpeg

Windows: Download and install precompiled binaries of libheif and libjpeg from their respective official websites. Make sure to include the necessary header files.

Step 2: Writing the C code

Create a C program that uses libheif and libjpeg to perform the conversion and set the grid size.

Step 3: Compiling the code

Compile the C code using a C compiler. Make sure to link the required libraries.

Linux/macOS:

gcc -o jpg_to_heic jpg_to_heic.c -lheif -ljpeg

Windows (assuming MinGW):

gcc -o jpg_to_heic.exe jpg_to_heic.c -lheif -ljpeg

Step 4: Running the converter

Run the converter with the input JPEG file, desired output HEIF file, and the grid size you want to set. For example:

./jpg_to_heic input.jpg output.heic 16

This will convert input.jpg to output.heic with a grid size of 16. Adjust the grid size according to your preference or requirements.

Remember that libheif is a powerful library that provides many other options for configuring HEIF output. This example focuses on setting the grid size, but you can explore other settings and functionalities offered by the library.

Note: Always make sure to respect licensing terms and conditions of the libraries used. Proper error handling and resource management are essential for production code but might have been omitted in this simplified example.

0
Devon Sookhoo On

Unfortunately, the heif-enc program does not yet support encoding images to HEIFs with a grid. It also does not allow the user to specify an ispe box.

These are features that you can request on the libheif github here: https://github.com/strukturag/libheif