AspHEIF - HEIF/HEIC and AVIF Component

Contents

A.1 What is AspHEIF?

The High-Efficiency Image Format (HEIF) is an image format created by Apple. The AV1 image file format (AVIF) is a new open-source image format released in February 2019 by the Alliance for Open Media (AOMedia).

AspHEIF is a COM component for primarily decoding images in the HEIF and AVIF formats, and converting them to PNG and AVIF images for viewing or further processing. Other input formats include PNG and JPEG.

Input FormatsOutput Formats
HEIF
AVIF
JPEG
PNG
PNG
AVIF

This component only has a few properties and methods, and is very easy to use. Therefore, it does not warrant a separate dedicated web site. This web page conveniently combines all the pieces you need to start using AspHEIF immediately: the download and evaluation key panel, purchasing panel, object reference, and user manual with several code samples.

A.2 Download & Request Your Evaluation Key

Request your free 30-day evaluaton key:

AspHEIF requires a registration key even for evaluation purposes. Enter your email address in the box below and click "Request Key" to receive your free 30-day evaluation key via email. The key will be accompanied by installation instructions.

Download your free 30-day evaluation copy of AspPDF:

File:
Version:
1.0.0.38
Size:
6.87 MB
Bits:
32/64
Last Updated:
May 17, 2022

A.3 Purchase

Single Server License
PART NUMBER: ASPHEIF
$195.00
The registration key can be installed on a single production server. Includes one extra developer-box license.
5-Server License
PART NUMBER: ASPHEIF-5
$495.00
The registration key can be installed on up to 5 production servers. Includes 2 extra developer-box licenses.
Site License
PART NUMBER: ASPHEIF-S
$695.00
The registration key can be installed on an unlimited number of production servers and developer boxes within a single physical location or site.
Enterprise License
PART NUMBER: ASPHEIF-E
$895.00
The registration key can be installed on an unlimited number of production servers and developer boxes within the organization regardless of physical location, nationally or internationally.

A.4 Object Reference

AspHEIF Properties


AlphaExists As Boolean (read-only)

Returns True if the image being opened contains an alpha channel, and False otherwise.


Expires As Date (read-only)

Returns the component's expiration date. If a permanent registration key is installed, returns 9/9/9999.


PeekMode As Boolean (read/write)

False by default. If set to True, enables the "peek" mode under which the Open/OpenBinary methods do not throw exceptions even if the file being opened is not in the right format (i.e. not a HEIF or AVIF image), but return a non-zero error code instead. This mode enables your app to "peek" into a file being opened without having to use any exception handling.


RegKey As String (write-only)

Specifies the registration key. If this property is not set, AspHEIF looks for a registration key in the system registry.


Version As String (read-only)

Returns the current version of the component.

AspHEIF Methods


Function Open(Path As String) As Integer

Opens a HEIF or AVIF image specified by Path.

If the peek mode is disabled (PeekMode = False, default) the method throws an exception if the path is invalid, or if the specified file is not an image in a valid format.

If the peek mode is enabled (PeekMode = True) the method does not throw an exception even if the image is not found, or its format not recognized. If the image is opened successfully, the method returns 0. In case of an error the method returns a non-zero error code. The error codes are as follows:

  • 0 - success;
  • 1 - file not found;
  • 2 - invalid input;
  • 3 - unsupported file type;
  • 4 to 10 - other decoding errors;
  • 11 - a non-RGB JPEG image as input.
  • 999 - out of memory while allocating a memory buffer.

Function OpenBinary(Image As Variant) As Integer

Same as Open but opens the image from a memory byte array.


Function Save(Path As String, Optional Overwrite = False) As String

Converts the image previously opened via the Open/Open methods to PNG and saves it to a file specified by Path. If Overwrite is set to True or omitted, and the file already exists, it will be overwritten. If Overwrite is set to False and the file already exists, a unique name is generated to avoid overwriting an existing file by appending a number in parentheses after the filename, such as image(1).png, image(2).png, etc.

The method returns the filename (without a path) under which the image ends up being saved.


Function SaveToMemory() As Variant

Converts the image previously opened via the Open/Open methods to PNG and saves it to a memory byte array. Returns this byte array.


Sub SetOutputFormat(Params As String)

Specifies the output format. If this method is not called, the default output format is PNG. Params is a comma- or semicolon-separated list of parameters. Currently the following parameters are supported:

  • Format (required) - valid values: PNG (1) or AVIF (4).
  • Speed (optional) - specifies the speed / quality tradeoff when encoding if Format is set to AVIF. Valid values: 0 (slowest) to 10 (fastest). 10 by default.
  • MinQuantizer, MaxQuantizer (optional) - specify the quality of the output AVIF image if Format is set to AVIF. Valid values: from 0 (lossless, best quality) to 63 (worst quality). Default values: 0, 0.
  • TileRows, TileCols (optional) - specify the number of tiles the image is to be split into horizontally and vertically, respectively. The actual number of rows is 2TileRows, and number of columns 2TileCols. For example, "TileRows=2; TileCols=1" corresponds to 4 rows and 2 columns of tiles. (0, 0) by default, which corresponds to a single tile. These parameters are only used if Format is set to AVIF.

A.5 User Manual and Code Samples

Installation

The AspHEIF component consists of a singe file, AspHEIF.dll (32-bit version) and AspHEIF64.dll (64-bit version). The DLL is to be registered on your system with the regsvr32 command-line utility. It is recommended that on a 64-bit version of Windows, both DLLs be registered at the same time.

A third DLL included in the download is AspHeifLib.dll which is an interop assembly to be used under the .NET environment. This assembly is to be placed in the /Bin subdirectory of the .NET application. This DLL is not subject to registration by regsvr32.

AspHEIF requires a registration key even for evaluation purposes. A free 30-day evaluation key is sent to the evaluator via email. Request your key at the Download section above. Once a copy of the product is purchased, a permanent registration key is sent to the customer.

The registration key must be put in the system registry under

HKEY_LOCAL_MACHINE\Software\Persits Software\AspHEIF\RegKey

as the default value. That is where both the 32-bit and 64-bit versions of the component look for the key. The Wow6432Node section of the registry is not used by AspHEIF.

Alternatively, the key can be specified via the RegKey property directly in your application's code.

Code Example 1

In classic ASP, an instance of AspHEIF is created via the ProgID "Persits.HEIF". In .NET, the namespace AspHeifLib is imported, and the object is created as follows:

IHeifManager objHeif = new HeifManager();

The method Open (or OpenBinary) is then called on this object, followed by Save (or SaveToMemory), as follows:

Set Heif = Server.CreateObject("Persits.HEIF")
Heif.Open( Server.MapPath("example.avif") )
Heif.Save( Server.MapPath("out.png"), False )
<%@ Import Namespace="AspHeifLib" %>

<script runat="server" LANGUAGE="C#">

void Page_Load(Object Source, EventArgs E)
{
   IHeifManager objHeif = new HeifManager();
   objHeif.Open( Server.MapPath("example.avif") );
   objHeif.Save( Server.MapPath("out.png"), false );
}

</script>

Code Example 2: PeekMode Enabled

<%
Set Heif = Server.CreateObject("Persits.HEIF")
Heif.PeekMode = True

error = Heif.Open( Server.MapPath("example.avif") )
If error = 0 Then
   Filename = Heif.Save( Server.MapPath("out.png"), False )
   Response.Write Filename
Else
   Response.Write "Error: " & error
End If
%>
<%@ Import Namespace="AspHeifLib" %>

<script runat="server" LANGUAGE="C#">

void Page_Load(Object Source, EventArgs E)
{
   IHeifManager objHeif = new HeifManager();
   objHeif.PeekMode = true;

   int error = objHeif.Open( Server.MapPath("example.avif") );
   if( error == 0 )
   {
      string Filename = objHeif.Save(Server.MapPath("out.png"), false);
      Response.Write( Filename );
   }
   else
   {
      Response.Write( "Error: " + error.ToString() );
   }
}

</script>

Code Example 3: AVIF Output

<%
Set Heif = Server.CreateObject("Persits.HEIF")
Heif.Open Server.MapPath("inputimage.jpg")
Heif.SetOutputFormat "format=avif; maxQuantizer=20; minQuantizer=20"
Filename = Heif.Save( Server.MapPath("out.avif"), false )
%>
<%@ Import Namespace="AspHeifLib" %>

<script runat="server" LANGUAGE="C#">

void Page_Load(Object Source, EventArgs E)
{
   IHeifManager objHeif = new HeifManager();
   objHeif.Open( Server.MapPath("inputimage.jpg") );
   objHeif.SetOutputFormat("format=avif;maxQuantizer=20;minQuantizer=20");
   objHeif.Save(Server.MapPath("out.avif"), false);
}

</script>