📖
ImGo Documentation
  • GETTING STARTED
    • Introduction
    • Coordinate Axis
    • Supported Formats
    • Update Logs
  • Usage
    • Usage Overview
    • Errors handling
  • API
    • Blur
    • Bounds
    • Canvas
    • Circle
    • Color2Hex
    • Crop
    • Ellipse
    • Extension
    • Filesize
    • Flip
    • GaussianBlur
    • Grayscale
    • Height
    • HttpHandler
    • Insert
    • Load
    • LoadFromBase64
    • LoadFromFile
    • LoadFromImage
    • LoadFromImgo
    • LoadFromPath
    • LoadFromUrl
    • Line
    • MainColor
    • Mimetype
    • Mosaic
    • PickColor
    • Pixel
    • Pixelate
    • RadiusBorder
    • Rectangle
    • Resize
    • Rotate
    • Save
    • String
    • Text
    • Thumbnail
    • ToBase64
    • ToImage
    • Width
Powered by GitBook
On this page
  • Parameters
  • Return Values
  • Examples
  • Image Filepath
  • Image URL
  • Base64 encoded image data
  • The instance of *os.File
  • The instance of the types that implement the image.Image interface
  • The instance of *imgo.Image
  1. API

Load

Load an image。

Parameters

Parameter
Type
Description

source

interface{}

Image resource.

source parameters support the following types:

Support type
Data type

Path of the image in filesystem.

string 或 []byte

URL of an image.

string 或 []byte

Base64 encoded image data.

string 或 []byte

The instance of *os.File .

*os.File

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

image.Image and the types that implement the image.Image interface.

The instance of *imgo.Image .

*imgo.Image

Return Values

The instance of *imgo.Image .

Examples

Image Filepath

package main

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

func main() {
    imgo.Load("gopher.png").
        Save("out.png")
}

Image URL

package main

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

func main() {
    url := "https://www.baidu.com/img/flexible/logo/pc/result.png"
    imgo.Load(url).
        Save("out.png")
}

Base64 encoded image data

package main

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

func main() {
    base64Img := imgo.Load("gopher.png").ToBase64()
    imgo.Load(base64Img).Save("out.png")
}

The instance of *os.File

package main

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

func main() {
    file, err := os.Open("gopher.png")
    if err != nil {
        panic(err)
    }
    defer file.Close()

    imgo.Load(file).
        Save("out.png")
}

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

package main

import (
    "github.com/fishtailstudio/imgo"
    "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.Load(img).
        Save("out.png")
}

The instance of *imgo.Image

package main

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

func main() {
    img := imgo.Load("gopher.png")
    imgo.Load(img).
        Save("out.png")
}
PreviousInsertNextLoadFromBase64

Last updated 2 years ago