> For the complete documentation index, see [llms.txt](https://docs.gpmautomate.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gpmautomate.com/automate-zh/cao-zuo-zhi-nan/image-search/image-to-base64.md).

# 图像转Base64

此操作可以将计算机上的图像文件编码为一串文本字符（Base64字符串）。

* 作用：在需要通过网络命令如`HTTP Request`发送图像时极为有用。例如：您想将图像发送到AI服务以解码验证码，或将图像上传到服务器而不想以常规方式传输文件。

#### 配置参数：

* 图像路径：指向需要转换的计算机上图像文件的绝对路径（例如：`D:\GPM_Data\captcha.png`）。
* 输出变量：成功编码后保存Base64字符串的变量名称。

#### 实际示例：转换验证码图像以通过API发送到自动解码系统

当您导航到一个网站并遇到图像验证码时。您已经使用截图操作捕捉到包含验证码的区域，并将其保存为`D:\GPM_Data\captcha.png`的图像文件。现在，您想将此图像发送到第三方API（如2Captcha，Anti-Captcha）以请求他们代为解码。由于他们的API要求图像数据必须以Base64文本字符串的形式提供，您将进行如下配置：

* 步骤1：调用图像转Base64操作。
  * 图像路径：填写`D:\GPM_Data\captcha.png`。
  * 输出变量：将变量命名为`base64String`。
* 步骤2：调用HTTP请求操作（方法POST）以将数据发送到解码验证码的服务器。在数据（主体）部分，您将变量`$base64String`传入符合他们API文档的JSON结构中。

结果：图像文件`captcha.png`将被转换为一串长长的字符编码，形式为`data:image/png;base64,iVBORw0KGgoAAAANSU...`，并存储在变量`$base64String`中。后续的HTTP请求只需将此字符串整齐地发送出去，帮助自动脚本轻松绕过验证码的安全层。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.gpmautomate.com/automate-zh/cao-zuo-zhi-nan/image-search/image-to-base64.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
