Skip to content

Configuration ​

Introduction ​

Laravel Go Image has three settings. They control how the manager decodes images and which color fills new areas. The package reads them from the environment when the application starts. They mirror the options in intervention/image-laravel's config/intervention-image.php, which sets them as fixed values.

The package has a single Go driver, so it has no driver setting. Go encoders never write metadata, so it has no strip setting either.

Environment variables ​

VariableDefaultDescription
IMAGE_AUTO_ORIENTATIONtrueRotate decoded images upright by their Exif orientation.
IMAGE_DECODE_ANIMATIONtrueKeep every frame of animated GIFs. When false, the manager keeps only the first frame.
IMAGE_BACKGROUND_COLORffffffThe color that fills new canvas areas and replaces transparency in formats without it, such as JPEG.

IMAGE_BACKGROUND_COLOR accepts any color that image.ParseColor reads. If the color doesn't parse, the application refuses to start and names the setting to fix.

Overriding settings in code ​

You may pass configure functions to image.New. Each one changes the settings after the package reads the environment, so code wins over environment variables:

go
image.New(func(cfg *image.Config) {
	cfg.DecodeAnimation = false
	cfg.BackgroundColor = "#0b1118"
})

Reading the settings ​

The manager returns its settings with Config:

go
cfg := image.From(r).Config()

if cfg.AutoOrientation {
	// ...
}

Each image also keeps the background color it was created with. You may change it for one image with SetBackground:

go
img.SetBackground("transparent").Rotate(30)

Released under the MIT License.