@atlas-viewer/iiif-image-api

中文文档
2.2.2发布于 2025/03/24MITTypeScriptESM + CJS近 30 天下载 3543

A series of helpers for working with the IIIF Image API.

原始使用文档
文档目录24 节
  1. Compatibility
  2. Documentation
  3. Image service loader
  4. Service profiles
  5. isImageService
  6. canonicalServiceUrl
  7. extractFixedSizeScales
  8. fixedSizesFromScales
  9. getCustomSizeFromService
  10. getFixedSizeFromImage
  11. getFixedSizesFromService
  12. getImageCandidates
  13. getImageCandidatesFromService
  14. getImageFromTileSource
  15. getImageServerFromId
  16. getImageServices
  17. getSmallestScaleFactorAsSingleImage
  18. inferSizeFromUrl
  19. isBestMatch
  20. isImageService
  21. pickBestFromCandidates
  22. sampledTilesToTiles
  23. sizesMatch
  24. supportsCustomSizes

IIIF Image API

A series of helpers for working with the IIIF Image API.

Compatibility

IIIF Specifications

IIIF Profile levels

Check out the Compliance version for more information. This library supports detection of levels 0 to 2 up to IIIF Image API 3.0.

Documentation

This library is a toolbox to be used as a part of a larger application or library. The documentation is still in progress, but there are typescript definitions shipped so you can explore the API in your IDE or editor.

Image service loader

This is the primary part of the library. It uses all the components to create a single image service loading library.

import { ImageServiceLoader } from '@atlas-viewer/iiif-image-api';

const loader = new ImageServiceLoader();

loader.loadService({
  id: 'http://some-service/some-path',
  width: 1000,
  height: 1000,
}).then(service => {
  // full image service available
  // service
});

loader.getThumbnailFromResource(
  // Content resource.
  {
    id: 'http://some-service/some-image/default.jpg',
    width: 1000,
    height: 2000,
    service: [
      {
       id: 'http://some-service/some-path',
        type: 'Service',
        profile: 'level0',
      }
    ]
  }, 
  // Thumbnail options.
  {
    maxWidth: 200,
    maxHeight: 200,
    preferFixedSize: true,
  }, 
  // Dereference image service.
  true
);

Service profiles

The following profiles will be matched and mapped to the conformance level in IIIF:

isImageService

Takes in an image service object and returns true if it is a supported image service.

import { isImageService } from '@atlas-viewer/iiif-image-api';

isImageService({
  id: 'http://some-service/some-path',
  type: 'Service',
  profile: 'level0',
}); // true

canonicalServiceUrl

Normalises an image service endpoint to ensure it has the info.json appended.

import { canonicalServiceUrl } from '@atlas-viewer/iiif-image-api';

canonicalServiceUrl('http://some-service/some-path'); // http://some-service/some-path/info.json

extractFixedSizeScales

Given a list of image sizes and a height and width, this returns the scale of each size in the same order as the input.

import { extractFixedSizeScales } from '@atlas-viewer/iiif-image-api';

extractFixedSizeScales(1000, 2000, [
  { width: 100, height: 200 },
  { width: 500, height: 1000 }
]); // [ 10, 2 ]

fixedSizesFromScales

The opposite operation to extractFixedSizeScales returning a list of sizes from a list of scales.

import { extractFixedSizeScales } from '@atlas-viewer/iiif-image-api';

extractFixedSizeScales(1000, 2000, [10, 2]);
// returns:
// [ { width: 100, height: 200 }, { width: 500, height: 1000 } ]

getCustomSizeFromService

Given a service, this will return an object giving the constraints for generating images from the service using the profile and the max width and max height properties if they are available. If the service contains tiles, it will use the definition of the tiles.

The return value used across this library is for describing an image candidate that can be used to create a real image.

import { getCustomSizeFromService } from '@atlas-viewer/iiif-image-api';

getCustomSizeFromService({
  id: 'http://some-service/some-path',
  profile: 'image2',
  tiles: [
    { width: 256, height: 256 },
    { width: 512, height: 512 },
  ]
});

const returns = [
  {
    id: 'http://some-service/some-path',
    type: 'variable',
    minHeight: 0,
    minWidth: 0,
    maxHeight: 256,
    maxWidth: 256,
  },
  {
    id: 'http://some-service/some-path',
    type: 'variable',
    minHeight: 0,
    minWidth: 0,
    maxHeight: 512,
    maxWidth: 512,
  }
];

getFixedSizeFromImage

This takes in a content resource – usually in the body of an annotation or thumbnail property in IIIF Presentation manifest – and tries to find the size of that resource. This is only an indication of the size of a resource and shouldn't be used as a source of truth. Internally this is used to detect potentially very large images and avoid rendering them.

import { getFixedSizeFromImage } from '@atlas-viewer/iiif-image-api';

// Normal image resources.
getFixedSizeFromImage({
  id: 'http://some-service/some-path/image.jpg',
  type: 'Image',
  width: 100,
  height: 200,
});

const returns = {
  id: 'http://some-service/some-path/image.jpg',
  type: 'fixed',
  width: 100,
  height: 200,
};

// Unknown size.
getFixedSizeFromImage('http://some-service/some-path/image.jpg');

const returns = {
  id: 'http://some-service/some-path/image.jpg',
  type: 'unknown',
};

getFixedSizesFromService

getImageCandidates

getImageCandidatesFromService

getImageFromTileSource

getImageServerFromId

getImageServices

getSmallestScaleFactorAsSingleImage

inferSizeFromUrl

isBestMatch

isImageService

pickBestFromCandidates

sampledTilesToTiles

sizesMatch

supportsCustomSizes

版本与发布记录

@atlas-viewer/iiif-image-api 共发布 32 个版本,首次发布于 2020/04/11;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.2.2latest2025/03/241.6 年前
2.2.12024/06/272 年前
2.2.02024/04/102 年前
2.1.22024/03/152 年前
2.1.12023/02/023 年前
2.1.02022/12/203 年前

关于 @atlas-viewer/iiif-image-api 的常见问题

@atlas-viewer/iiif-image-api 是什么?

A series of helpers for working with the IIIF Image API.

如何安装 @atlas-viewer/iiif-image-api?

在项目目录运行 npm install @atlas-viewer/iiif-image-api,或使用 pnpm add / yarn add / bun add。

@atlas-viewer/iiif-image-api 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@atlas-viewer/iiif-image-api 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@atlas-viewer/iiif-image-api 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18.14.1。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@atlas-viewer/iiif-image-api 可以商用吗?

@atlas-viewer/iiif-image-api 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@atlas-viewer/iiif-image-api 的下载量有多少?

根据 npm 官方下载统计,@atlas-viewer/iiif-image-api 在 2026/10/07 – 2026/11/05 这 30 天内被下载 3,543 次,日均约 118 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@atlas-viewer/iiif-image-api 还在维护吗?

最新版本 2.2.2 发布于 2025/03/24(1.6 年前);至今共发布 32 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/04/11。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。