Open Source Image Resizing Server that Provides Faster Processing
Picfit is an image resizing server developed in Pure Go that takes care of storage part of image processing no matter the storage engine used.
Image processing, particularly resizing can be a long process if your image is stored on different engines as it can take time for the application to remove codes of avatars and avoid synchronous calls to retrieve the generated image.
Picfit resolves these issues, by acting as a proxy between your storage engine and the HTTP cache system. While it is free to download, open source and provides faster processing, it also avoids generating the same image twice and taking up too much space.
You can store images on Amazon S3, DigitalOcean S3, your file system and more.
Getting Started with Picfit
The easiest and recommend way to install Picfit is via GitHub. Please use the following command for an easy and smooth installation.
Install Picfit via GitHub
git clone https://github.com/thoas/picfit.git
Resize Images via Free GO Library
The open source picfit library enables software developers to programmatically resize images inside their own application using Go commands. One of the main function of Picfit is the ability to resize images according to the height and width of your choice. Simply provide the w (the desired image’s width) and h (the desired image’s height) values.
Resize Image via Free GO Library
func (e *GoImageEngine) Resize(img *imagefile.ImageFile, width int, height int, options *Options) ([]byte, error) {
if options.Format == imaging.GIF {
content, err := e.TransformGIF(img, width, height, options, imaging.Resize)
if err != nil {
return nil, err
}
return content, nil
}
image, err := e.Source(img)
if err != nil {
return nil, err
}
return e.resize(image, width, height, options)
}
Free Go Library to Genrate Thumbnails
You can use this function to generate a new image with a resampled filter either scaled up or down, and crops it to a specified height and width. Again in this function you have to provide the w and h values.
How to Genrate GIF Thumbnails inside GO Apps?
func (e *GoImageEngine) Thumbnail(img *imagefile.ImageFile, width int, height int, options *Options) ([]byte, error) {
if options.Format == imaging.GIF {
content, err := e.TransformGIF(img, width, height, options, imaging.Thumbnail)
if err != nil {
return nil, err
}
return content, nil
}
image, err := e.Source(img)
if err != nil {
return nil, err
}
return e.thumbnail(image, width, height, options)
}
Reterive Image Infomation via Go API
Apart from resizing functions, Picfit also has some important functions to retrieve file information like Get, as well as storage or uploading commands. With the Get function you will get the following parameters as a result:
- File name: name of the generated file
- Path: this will be the path of your generated file on your storage engine
- URL: if the base_url is present then you will receive a full URL of your generated file