> For AI agents: the complete documentation index is available at /apps-plugin/docs/llms.txt, the full documentation bundle is available at /apps-plugin/docs/llms-full.txt.

# getImageInfo

获取图片信息。

## 扫码预览

![扫码预览 getImageInfo](https://api.qrserver.com/v1/create-qr-code/?size=200x200\&data=doubao%3A%2F%2Fdoubao_apps%3Fapp_id%3Ddb_1McM5Ni%26path%3D%252Fpages%252Fapi%252Fmedia%252Fget-image-info%252Findex)

## 支持版本

前端库版本不低于 `0.0.26`。

## 支持平台

<table>
<thead>
<tr><th>平台</th><th>支持情况</th></tr>
</thead>
<tbody>
<tr><td>Android</td><td>支持</td></tr>
<tr><td>iOS</td><td>支持</td></tr>
<tr><td>PC</td><td>不支持</td></tr>
<tr><td>HarmonyOS</td><td>不支持</td></tr>
</tbody>
</table>

## 支持场景

<table>
<thead>
<tr><th>场景</th><th>支持情况</th></tr>
</thead>
<tbody>
<tr><td>页面</td><td>支持</td></tr>
<tr><td>卡片</td><td>不支持</td></tr>
</tbody>
</table>

## 接入准备

### 前置条件

- src 为豆包应用插件可访问的本地图片路径，或可直接下载的 HTTP、HTTPS 图片地址

## 使用说明

- 网络图片会产生下载流量；如需重复读取，建议先下载为本地临时文件。

## 调用方式

### 异步 API

```typescript
getImageInfo(params: GetImageInfoParams): Promise<GetImageInfoResult>
```

## 入参

<table>
<thead>
<tr><th>名称</th><th>类型</th><th>必填</th><th>默认值</th><th>约束</th><th>说明</th></tr>
</thead>
<tbody>
<tr><td><code>src</code></td><td><code>string</code></td><td>是</td><td>-</td><td>-</td><td>图片路径，可以是相对路径、临时文件路径、存储文件路径或网络图片路径。</td></tr>
</tbody>
</table>

## 调用示例

```typescript
import { getImageInfo } from '@doubao-dev/framework/api';

const { width, height, path } = await getImageInfo({
  src: '/tmp/image.png'
});

console.log(width, height, path);
```

## 成功返回

<table>
<thead>
<tr><th>名称</th><th>类型</th><th>必返</th><th>说明</th></tr>
</thead>
<tbody>
<tr><td><code>height</code></td><td><code>number</code></td><td>是</td><td>图片原始高度，单位 px，不考虑旋转。</td></tr>
<tr><td><code>orientation</code></td><td><code>ImageOrientation</code></td><td>是</td><td>图片方向。</td></tr>
<tr><td><code>path</code></td><td><code>string</code></td><td>是</td><td>图片路径；网络图片返回原始网络地址，本地图片返回可访问的本地路径。</td></tr>
<tr><td><code>type</code></td><td><code>string</code></td><td>是</td><td>图片格式。</td></tr>
<tr><td><code>width</code></td><td><code>number</code></td><td>是</td><td>图片原始宽度，单位 px，不考虑旋转。</td></tr>
</tbody>
</table>

### 返回示例

```json
{
  "height": 1080,
  "orientation": "up",
  "path": "appletfile://temp/example.jpg",
  "type": "jpeg",
  "width": 1920
}
```

## 错误处理

错误对象和通用错误码见 [通用错误处理](/apps-plugin/docs/js-api/common-errors.md#错误返回)。

### 失败示例

```json
{
  "errNo": 104,
  "errMsg": "src cannot be empty"
}
```

### 错误码

<table>
<thead>
<tr><th>errNo</th><th>errMsg</th><th>平台</th><th>触发条件</th><th>处理建议</th></tr>
</thead>
<tbody>
<tr><td><code>104</code></td><td><code>src cannot be empty</code></td><td>Android</td><td>src 为空字符串</td><td>传入非空的本地图片路径或 HTTP、HTTPS 地址。</td></tr>
<tr><td><code>104</code></td><td><code>src must not be empty</code></td><td>iOS</td><td>src 为空字符串</td><td>传入非空的本地图片路径或 HTTP、HTTPS 地址。</td></tr>
<tr><td><code>203</code></td><td><code>file does not exist</code></td><td>Android</td><td>本地图片文件不存在</td><td>检查路径仍在有效期内并重新获取文件。</td></tr>
<tr><td><code>203</code></td><td><code>file not found</code></td><td>iOS</td><td>本地图片文件不存在</td><td>检查路径仍在有效期内并重新获取文件。</td></tr>
</tbody>
</table>

## 平台差异

- **iOS**：网络图片下载到临时目录时不保留扩展名，type 可能返回 unknown；如需稳定识别格式，请以图片内容自行判断。
