> For the complete documentation index, see [llms.txt](https://imgo.gitbook.io/en/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://imgo.gitbook.io/en/api/insert.md).

# 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")
}
```
