生成汉字验证码
@param $font
@param $width
@param $height
@return array
421652
static function verifycode_chinese($font, $width = 180, $height = 60)
    {
        $length = 4;
        $angle = 45;
        $width = ($length * 45) > $width ? $length * 45 : $width;

        $im = imagecreatetruecolor($width, $height);
        $borderColor = imagecolorallocate($im, 100, 100, 100);                    //边框色
        $bkcolor = imagecolorallocate($im, 250, 250, 250);
        imagefill($im, 0, 0, $bkcolor);
        imagerectangle($im, 0, 0, $width - 1, $height - 1, $borderColor);
        // 干扰
        for ($i = 0; $i < 5; $i++)
        {
            $fontcolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
            imagearc($im, mt_rand(-10, $width), mt_rand(-10, $height), mt_rand(30, 300), mt_rand(20, 200), 55, 44,
                $fontcolor);
        }
        for ($i = 0; $i < 255; $i++)
        {
            $fontcolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
            imagesetpixel($im, mt_rand(0, $width), mt_rand(0, $height), $fontcolor);
        }

        $code = '';
        for ($i = 0; $i < $length; $i++)
        {
            $fontcolor = imagecolorallocate($im, mt_rand(0, 120), mt_rand(0, 120), mt_rand(0, 120)); //这样保证随机出来的颜色较深。
            $codex =  RandomKey::getChineseCharacter(1);
            $code .= $codex;
            @imagettftext($im, mt_rand(16, 20), mt_rand(-$angle, $angle), 40 * $i + 20, mt_rand(30, 35), $fontcolor, $font,
                $codex);
        }
        ob_start();
        ImagePng($im);
        $data = ob_get_clean();
        ImageDestroy($im);

        return array('code' => $code, 'image' => $data);
    }
1035304
final protected function _createTrueColor($width,$height){
	    // Format
	    $width=(int)$width;
	    $height=(int)$height;
		// Create image
		$resource=imagecreatetruecolor($width,$height);
		if(!$resource){
			throw new Exception("Failed to create new image");
		}
		// Set alpha channel
		imagealphablending($resource,false);
		$color=imagecolorallocatealpha($resource,0,0,0,127);
		imagecolortransparent($resource,$color);
		imagesavealpha($resource,true);
		return $resource;
	}
853524
public static function create($x, $y, $width, $height) : Box
    {
        return new self($x, $y, $width, $height);
    }
479769
static function createImage( $width, $height, &$useTruecolor )
    {
        if ( $useTruecolor === null )
        {
//             print( "has GD2='" . eZImageInterface::hasGD2() . "'<br/>" );
            $useTruecolor = eZImageInterface::hasGD2();
        }
        if ( $useTruecolor and
             !function_exists( 'ImageCreateTrueColor' ) )
        {
            eZDebug::writeWarning( 'Function ImageCreateTrueColor does not exist, cannot create true color images', __METHOD__ );
            $useTruecolor = false;
        }
        if ( $useTruecolor )
            $imageObject = ImageCreateTrueColor( $width, $height );
        else
            $imageObject = ImageCreate( $width, $height );
        return $imageObject;
    }
314483
protected function urlForSize($width, $height=null)
    {

        if (!$this->sizes) {
            return $this->getUrl();
        }

        $targetSize = $width instanceof Size ? $width : new Size($width, $height);
        $targetKey = "$targetSize";

        if (isset($this->optimalSizeCache[$targetKey])) {
            return $this->optimalSizeCache[$targetKey];
        }

        $optimalSize = $targetSize->findBest($this->sizes());

        if ($this->getSize()->equals($optimalSize)) {
            $this->optimalSizeCache[$targetKey] = $this->getUrl();
            return $this->optimalSizeCache[$targetKey];
        }

        $optimalKey = "$optimalSize";

        if (isset($this->sizeUrls[$optimalKey])) {
            $this->optimalSizeCache[$targetKey] = $this->sizeUrls[$optimalKey];
            return $this->optimalSizeCache[$targetKey];
        }

        return $this->getUrl();

    }
973922
public function resize($width, $height)
    {

        $new = imagecreatetruecolor($width, $height);
        imagealphablending($new, false);
        imagesavealpha($new, true);
        imagecopyresampled($new, $this->image, 0, 0, 0, 0, $width, $height, $this->width, $this->height);

        $this->width = $width;
        $this->height = $height;
        $this->image = $new;

        return $this;

    }
959591
public function getNewDimensions($width, $height)
    {
        $radians = pi() * $this->degrees / 180;

        $NWL = $width * cos($radians);
        $NHL = $width * sin($radians);

        $NHU = $height * cos($radians);
        $NWR = $height * sin($radians);

        return parent::getNewDimensions(ceil(abs($NWL + $NWR)), ceil(abs($NHU + $NHL)));
    }
6047
static function createForText( $text, &$font, $widthAdjustment, $heightAdjustment, $angle,
                             $absoluteWidth = false, $absoluteHeight = false )
    {
        $Return = false;
        if ( !( $font instanceof eZImageFont ) )
            return $Return;
        if ( !function_exists( 'ImageTTFBBox' ) )
        {
            eZDebug::writeError( 'ImageTTFBBox function not in PHP, check PHP compilation', 'ezimagetextlayer.php' );
            return $Return;
        }
        $bbox = ImageTTFBBox( $font->pointSize(), $angle, $font->realFile(), $text );

        if ( !$bbox )
            return $Return;

        $xmin = min( $bbox[0], $bbox[2], $bbox[4], $bbox[6] );
        $xmax = max( $bbox[0], $bbox[2], $bbox[4], $bbox[6] );
        $ymin = min( $bbox[1], $bbox[3], $bbox[5], $bbox[7] );
        $ymax = max( $bbox[1], $bbox[3], $bbox[5], $bbox[7] );

        $width = abs( $xmax - $xmin );
        $height = abs( $ymax - $ymin );
        $width += $widthAdjustment;
        $height += $heightAdjustment;

        if ( $absoluteWidth !== false )
            $width = $absoluteWidth;
        if ( $absoluteHeight !== false)
            $height = $absoluteHeight;

        $layer = new eZImageTextLayer( null, null, $width, $height,
                                       $font, $bbox, $text, $angle );
        $layer->create( $width, $height, null );
        return $layer;
    }
431572
public function newImage($width, $height, $background = null)
    {
        // create empty resource
        $core = imagecreatetruecolor($width, $height);
        $image = new \Intervention\Image\Image(new static, $core);

        // set background color
        $background = new Color($background);
        imagefill($image->getCore(), 0, 0, $background->getInt());

        return $image;
    }
1181232
protected function getTargetDimensions($width, $height, $originalImagePath)
    {
        $originalDimensions = [$width, $height];

        try {
            $dimensions = getimagesize($originalImagePath);
            if (!$dimensions) {
                return $originalDimensions;
            }

            if ($dimensions[0] > $width || $dimensions[1] > $height) {
                return $originalDimensions;
            }

            return $dimensions;
        }
        catch (Exception $ex) {
            return $originalDimensions;
        }
    }
166135
protected function createCanvas($width, $height)
    {
        // Create the canvas element
        $canvas = imagecreatetruecolor( $width, $height );

        // Check if we should preserve the transparency
        if ( $this->imageType == IMAGETYPE_GIF || $this->imageType == IMAGETYPE_PNG ) {
            imagealphablending( $canvas, false );
            imagesavealpha( $canvas, true );
        }

        // Return the canvas
        return $canvas;
    }
314065
public function scaleResize($width, $height) {

        // calculate source coordinates
        $kw = $this->width() / $width;
        $kh = $this->height() / $height;
        if($kh < $kw) {
            $src_h = $this->height();
            $src_y = 0;
            $src_w = round($kh * $width);
            $src_x = round(($this->width() - $src_w) / 2);
        } else {
            $src_h = round($kh * $height);
            $src_y = round(($this->height() - $src_h) / 2);
            $src_w = $this->width();
            $src_x = 0;
        }

        // copy new image
        $new = imagecreatetruecolor($width, $height);
        imagecopyresampled($new, $this->resource, 0, 0, $src_x, $src_y,
            $width, $height, $src_w, $src_h);
        $this->resource = $new;

        // for method chaining
        return $this;
    }
1337131
public function create($width, $height, $index = 0)
    {
        $index = $index % 2;

        $background = Quad::create();
        $background->setSize($width, $height);
        if ($index == 0) {
            $background->setBackgroundColor("eee5");
        } else {
            $background->setBackgroundColor("eee3");
        }
        return $background;
    }
675151
public static function object($width, $height, $data)
    {
        $node = new Node\Object();

        $attributes = array(
            'width' => $width,
            'height' => $height,
            'data' => $data
        );

        return $node->render($attributes);
    }
551337
public function getSVG($width, $height)
    {
        if($this->svgEnvelope === null)
        {
            return null;
        }
        $min_max = explode(" ",
                           preg_replace('/M\s?|\sL|\sZ/', "", $this->svgEnvelope));
        $min_x = floatval($min_max[0]);
        $min_y = floatval($min_max[1]);
        $max_x = floatval($min_max[0]);
        $max_y = floatval($min_max[1]);
        for($i = 1; $i < count($min_max); $i = $i + 2)
        {
            $min_x = min($min_x, floatval($min_max[$i - 1]));
            $max_x = max($max_x, floatval($min_max[$i - 1]));
            $min_y = min($min_y, floatval($min_max[$i]));
            $max_y = max($max_y, floatval($min_max[$i]));
        }
        $vb = $min_x . " " . $min_y . " " . ($max_x - $min_x) . " " . ($max_y - $min_y);

        return '<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="' . $width . 'px" height="' . $height . 'px" viewBox="' . $vb . '" version="1.1" xmlns="http://www.w3.org/2000/svg">
	<path d="' . ($this->svgGeometry === null
                            ? '' : $this->svgGeometry) . '" fill="black" />
</svg>';
    }
57648
public function newImage($width, $height, $background = 'white')
    {
        $this->resource->createNew($width, $height, $background);

        return $this;
    }
997990
public function getNewDimensions($width, $height)
    {
        if(!$this->resizeSmaller && $this->height >= $height && $this->width >= $width)
        {
            return parent::getNewDimensions($width, $height);
        }

        if(in_array($this->resizeMode, array($this::MODE_CROP, $this::MODE_STRETCH, $this::MODE_EXACT)))
        {
            return parent::getNewDimensions($this->width, $this->height);
        }
        elseif($this->resizeMode === $this::MODE_FILL)
        {
            $ratioH = $this->height / $height;
            $ratioW = $this->width / $width;

            $widthFill  = max($width * $ratioH, $width * $ratioW);
            $heightFill = max($height * $ratioH, $height * $ratioW);
            $ratio = max($widthFill / $width, $heightFill / $height);

            return parent::getNewDimensions(round($width * $ratio), round($height * $ratio));
        }
        else
        {
            $pictureWidth  = $this->width;
            $pictureHeight = $this->height;

            if($width > $pictureWidth || $height > $pictureHeight)
            {
                if($width > $height)
                {
                    $pictureHeight = floor(($height / $width) * $pictureWidth);
                }
                elseif($width < $height)
                {
                    $pictureWidth = floor(($width / $height) * $pictureHeight);
                }
            }

            return parent::getNewDimensions($pictureWidth, $pictureHeight);
        }
    }