# Insert

inserts a image into the current image.

## Parameters

<table><thead><tr><th width="198.4826833846656">Parameter</th><th width="208.18338610093963">Type</th><th>Description</th></tr></thead><tbody><tr><td>source</td><td><code>interface{}</code></td><td>image to be inserted</td></tr><tr><td>x</td><td><code>int</code></td><td>X-Coordinate of the top-left corner of <code>source</code>.</td></tr><tr><td>y</td><td><code>int</code></td><td>Y-Coordinate of the top-left corner of <code>source</code>.</td></tr></tbody></table>

`source` parameters support the following types:

<table><thead><tr><th width="236.7279029462738">Support type</th><th>Data type</th></tr></thead><tbody><tr><td>Path of the image in filesystem.</td><td><code>string</code> 或 <code>[]byte</code></td></tr><tr><td>URL of an image.</td><td><code>string</code> 或 <code>[]byte</code></td></tr><tr><td>Base64 encoded image data.</td><td><code>string</code> 或 <code>[]byte</code></td></tr><tr><td>The instance of <code>*os.File</code> .</td><td><code>*os.File</code></td></tr><tr><td>The instance of the types that implement the <code>image.Image</code> interface.</td><td><code>image.Image</code> and the types that implement the <code>image.Image</code> interface.</td></tr><tr><td>The instance of <code>*imgo.Image</code> .</td><td><code>*imgo.Image</code></td></tr></tbody></table>

## Return Values

The instance of `*imgo.Image` .

## Examples

### Image Filepath

```go
package main

import (
    "github.com/fishtailstudio/imgo"
    "image/color"
)

func main() {
    imgo.Canvas(500, 500, color.Black).
        Insert("gopher.png", 100, 100).
        Save("out.png")
}
```

### Image URL

```go
package main

import (
    "github.com/fishtailstudio/imgo"
    "image/color"
)

func main() {
    url := "https://www.baidu.com/img/flexible/logo/pc/result.png"
    imgo.Canvas(500, 500, color.Black).
        Insert(url, 100, 100).
        Save("out.png")
}
```

### Base64 encoded image data

```go
package main

import (
    "github.com/fishtailstudio/imgo"
    "image/color"
)

func main() {
    base64Img := imgo.Load("gopher.png").ToBase64()
    imgo.Canvas(500, 500, color.Black).
        Insert(base64Img, 50, 50).
        Save("out.png")
}
```

### The instance of `*os.File`

```go
package main

import (
    "github.com/fishtailstudio/imgo"
    "image/color"
    "os"
)

func main() {
    file, err := os.Open("gopher.png")
    if err != nil {
        panic(err)
    }
    defer file.Close()
    
    imgo.Canvas(500, 500, color.Black).
        Insert(file, 100, 100).
        Save("out.png")
}
```

### The instance of the types that implement the `image.Image` interface

```go
package main

import (
    "github.com/fishtailstudio/imgo"
    "image/color"
    "image/png"
    "os"
)

func main() {
    file, err := os.Open("gopher.png")
    if err != nil {
        panic(err)
    }
    defer file.Close()
    
    img, err := png.Decode(file)
    if err != nil {
        panic(err)
    }
    
    imgo.Canvas(500, 500, color.Black).
        Insert(img, 100, 100).
        Save("out.png")
}
```

### The instance of `*imgo.Image`

```go
package main

import (
    "github.com/fishtailstudio/imgo"
    "image/color"
)

func main() {
    img := imgo.Load("gopher.png")
    imgo.Canvas(500, 500, color.Black).
        Insert(img, 100, 100).
        Save("out.png")
}
```


---

# Agent Instructions: 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:

```
GET https://imgo.gitbook.io/en/api/insert.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
