heic-convert vs heic2any
HEIC画像変換ライブラリ
heic-convertheic2any

HEIC画像変換ライブラリ

HEIC(High Efficiency Image Coding)フォーマットは、特にAppleデバイスで広く使用されている画像フォーマットです。これらのライブラリは、HEIC画像を他の一般的な画像フォーマット(例えばJPEGやPNG)に変換するためのツールを提供します。これにより、HEICフォーマットをサポートしていない環境でも画像を表示したり、利用したりすることが可能になります。

npmのダウンロードトレンド

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
heic-convert03117.92 kB102年前ISC
heic2any08252.72 MB243年前MIT

機能比較: heic-convert vs heic2any

変換機能

  • heic-convert:

    heic-convertは、HEIC画像をJPEG、PNG、GIFなどの一般的なフォーマットに変換する機能を提供します。変換時に画質を調整するオプションもあり、ユーザーは必要に応じて画質を選択できます。

  • heic2any:

    heic2anyは、HEIC画像をJPEGやPNGなどの他のフォーマットに変換するためのシンプルなAPIを提供します。このライブラリは、ブラウザで直接動作するため、ユーザーはサーバーサイドの処理を必要とせず、クライアントサイドで画像を変換できます。

使用シナリオ

  • heic-convert:

    heic-convertは、Node.jsアプリケーションでHEIC画像を処理する必要がある場合に最適です。特に、サーバーサイドでのバッチ処理や、画像の一括変換が必要なシナリオに適しています。

  • heic2any:

    heic2anyは、ユーザーがブラウザでHEIC画像をアップロードし、即座に他のフォーマットに変換したい場合に最適です。特に、ウェブアプリケーションでのユーザーインターフェースに組み込むのに便利です。

パフォーマンス

  • heic-convert:

    heic-convertは、Node.jsの非同期処理を活用しており、大量のHEIC画像を効率的に処理できます。変換速度は、使用するハードウェアや画像のサイズによって異なりますが、一般的には高速です。

  • heic2any:

    heic2anyは、ブラウザでのパフォーマンスを最適化するために設計されており、軽量な変換処理を提供します。ただし、ブラウザの性能やユーザーのデバイスによって変換速度が影響を受ける可能性があります。

依存関係

  • heic-convert:

    heic-convertは、Node.js環境で動作するため、特定のNode.jsバージョンや他のライブラリに依存しています。これにより、サーバーサイドでの使用が前提となります。

  • heic2any:

    heic2anyは、ブラウザベースのライブラリであり、特に外部の依存関係が少ないため、簡単にプロジェクトに組み込むことができます。

学習曲線

  • heic-convert:

    heic-convertは、Node.jsの知識が必要であり、初心者には少し学習曲線があるかもしれません。しかし、APIは直感的であり、ドキュメントも充実しています。

  • heic2any:

    heic2anyは、シンプルなAPIを提供しているため、比較的簡単に学習できます。特に、フロントエンド開発者にとっては、使いやすいライブラリです。

選び方: heic-convert vs heic2any

  • heic-convert:

    heic-convertは、Node.js環境でのHEIC画像の変換を簡単に行うためのライブラリです。特に、変換プロセスをカスタマイズしたい場合や、複数のHEICファイルを一度に処理したい場合に適しています。

  • heic2any:

    heic2anyは、HEIC画像を他のフォーマットに変換するためのシンプルで直感的なAPIを提供します。特に、ブラウザ環境での使用を重視しており、クライアントサイドでの変換が必要な場合に適しています。

heic-convert のREADME

heic-convert

Convert HEIC/HEIF images to JPEG and PNG

ci npm-downloads npm-version

Install

npm install heic-convert

Usage in NodeJS

Convert the main image in a HEIC to JPEG

const { promisify } = require('util');
const fs = require('fs');
const convert = require('heic-convert');

(async () => {
  const inputBuffer = await promisify(fs.readFile)('/path/to/my/image.heic');
  const outputBuffer = await convert({
    buffer: inputBuffer, // the HEIC file buffer
    format: 'JPEG',      // output format
    quality: 1           // the jpeg compression quality, between 0 and 1
  });

  await promisify(fs.writeFile)('./result.jpg', outputBuffer);
})();

Convert the main image in a HEIC to PNG

const { promisify } = require('util');
const fs = require('fs');
const convert = require('heic-convert');

(async () => {
  const inputBuffer = await promisify(fs.readFile)('/path/to/my/image.heic');
  const outputBuffer = await convert({
    buffer: inputBuffer, // the HEIC file buffer
    format: 'PNG'        // output format
  });

  await promisify(fs.writeFile)('./result.png', outputBuffer);
})();

Convert all images in a HEIC

const { promisify } = require('util');
const fs = require('fs');
const convert = require('heic-convert');

(async () => {
  const inputBuffer = await promisify(fs.readFile)('/path/to/my/image.heic');
  const images = await convert.all({
    buffer: inputBuffer, // the HEIC file buffer
    format: 'JPEG'       // output format
  });

  for (let idx in images) {
    const image = images[idx];
    const outputBuffer = await image.convert();
    await promisify(fs.writeFile)(`./result-${idx}.jpg`, outputBuffer);
  }
})();

The work to convert an image is done when calling image.convert(), so if you only need one of the images in a multi-image file, you can convert just that one from the images array and skip doing any work for the remaining images.

Note that while the converter returns a Promise and is overall asynchronous, a lot of work is still done synchronously, so you should consider using a worker thread in order to not block the main thread in highly concurrent production environments.

Usage in the browser

While the NodeJS version of heic-convert may be compiled for use in the browser with something like webpack, not all build tools necessarily like to compile all modules well. However, what further complicates things is that this module uses pure-javascript implementations of a jpeg and png encoder. But the browser has its own native encoders! Let's just use those instead of including a ton of extra code in your bundle.

When compiling a client-side project, use:

const convert = require('heic-convert/browser');

This is currently only supported in the main thread. Support for workers may be added in the future, but if you need it sooner, please create an issue or even a PR!

Related

  • heic-cli - convert heic/heif images to jpeg or png from the command line
  • heic-decode - decode heic images to raw image data
  • libheif-js - libheif as a pure-javascript npm module