private function applyBackgroundColor(&$imageInstance, $bgColor)
    {
        $palette = new RGB();
        $color = $palette->color($bgColor);

        try {
            $topLeft = new Point(0, 0);
        } catch (InvalidArgumentException $e) {
            Craft::error($e->getMessage(), __METHOD__);
            throw new ImagerException($e->getMessage(), $e->getCode(), $e);
        }

        if ($this->imagineInstance !== null) {
            $backgroundImage = $this->imagineInstance->create($imageInstance->getSize(), $color);
            $backgroundImage->paste($imageInstance, $topLeft);
            $imageInstance = $backgroundImage;
        }
    }