Usage Overview
Basic Usage
Method Chaining(Recommend)
Not Method Chaining
The above two examples are equivalent.
Reading Images
Using ImGo to read an image is very simple. You just call imgo.Load()
method.
This method can not only read local files, but also support the following input formats.
Path of the image in filesystem.
URL of an image.
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
.
Creating Images
Use the Canvas
method to create a canvas with a specified width, height and color.
Editing Images
After using the Load
or Canvas
method to obtain an image instance, now you can call the method to edit the image.
Methods for editing images will return instances of *imgo.Image
, so they can be called in a chain.
Image Output
Output as a file
You can save the edited image as a file by calling the Save
method.
The Save
method receives a string parameter as file path, which can be either an absolute path or a relative path. The file path parameter needs to have an image format suffix, such as out.png
。ImGo will output the image in the corresponding format according to the image format suffix, and no other operation is required.
The supported image formats to save are as follows.
jpg
image/jpeg
png
image/png
bmp
image/x-ms-bmp
tiff
image/tiff
Webp format is not supported to output because the golang.org/x/image/webp
package only provides the Decode
method, not the Encode
method.
HTTP Response
ImGo supports directly using the edited image as an HTTP response as follows.
Run the above example on the local computer, and access http://localhost/gopher
in browser, you will see gopher.png
image.
Last updated