src/Leevel/Seccode/Seccode.php
protected function makeBackgroundWithImage(&$resImage): bool
    {
        $findBackground = false;
        $backgroundPath = $this->option['background_path'];
        $width = $this->normalizeWidth();
        $height = $this->normalizeHeight();

        if ($this->option['background'] &&
            function_exists('imagecreatefromjpeg') &&
            function_exists('imagecolorat') &&
            function_exists('imagecopymerge') &&
            function_exists('imagesetpixel') &&
            function_exists('imageSX') &&
            function_exists('imageSY')) {
            if (!is_dir($backgroundPath)) {
                $e = sprintf('Background path %s is not exists.', $backgroundPath);

                throw new InvalidArgumentException($e);
            }

            $background = glob($backgroundPath.'/*.*');

            if ($background) {
                $resBackground = imagecreatefromjpeg($background[array_rand($background)]);
                $resColorIndex = imagecolorat($resBackground, 0, 0);
                $color = imagecolorsforindex($resBackground, $resColorIndex);
                $resColorIndex = imagecolorat($resBackground, 1, 0);

                imagesetpixel($resBackground, 0, 0, $resColorIndex);

                $color[0] = (int) ($color['red']);
                $color[1] = (int) ($color['green']);
                $color[2] = (int) ($color['blue']);

                imagecopymerge(
                    $resImage,
                    $resBackground,
                    0,
                    0,
                    $this->mtRand(0, 200 - $width),
                    $this->mtRand(0, 80 - $height),
                    imagesx($resBackground),
                    imagesy($resBackground),
                    100
                );

                imagedestroy($resBackground);

                $findBackground = true;

                $this->fontColor = $color;
            }
        }

        return $findBackground;
    }
protected function makeBackgroundWithImage(&$resImage): bool
    {
        $findBackground = false;
        $backgroundPath = $this->option['background_path'];
        $width = $this->normalizeWidth();
        $height = $this->normalizeHeight();

        if ($this->option['background'] &&
            function_exists('imagecreatefromjpeg') &&
            function_exists('imagecolorat') &&
            function_exists('imagecopymerge') &&
            function_exists('imagesetpixel') &&
            function_exists('imageSX') &&
            function_exists('imageSY')) {
            if (!is_dir($backgroundPath)) {
                $e = sprintf('Background path %s is not exists.', $backgroundPath);

                throw new InvalidArgumentException($e);
            }

            $background = glob($backgroundPath.'/*.*');

            if ($background) {
                $resBackground = imagecreatefromjpeg($background[array_rand($background)]);
                $resColorIndex = imagecolorat($resBackground, 0, 0);
                $color = imagecolorsforindex($resBackground, $resColorIndex);
                $resColorIndex = imagecolorat($resBackground, 1, 0);

                imagesetpixel($resBackground, 0, 0, $resColorIndex);

                $color[0] = (int) ($color['red']);
                $color[1] = (int) ($color['green']);
                $color[2] = (int) ($color['blue']);

                imagecopymerge(
                    $resImage,
                    $resBackground,
                    0,
                    0,
                    $this->mtRand(0, 200 - $width),
                    $this->mtRand(0, 80 - $height),
                    imagesx($resBackground),
                    imagesy($resBackground),
                    100
                );

                imagedestroy($resBackground);

                $findBackground = true;

                $this->fontColor = $color;
            }
        }

        return $findBackground;
    }
创建图片背景图像.

@param resource $resImage

@return bool