生成验证码使用GD
@param $img_width
@param $img_height
@return array
972295
static function verifycode_gd($img_width = 80, $img_height = 30)
    {
        $code = strtoupper(RandomKey::string(self::$verifyCodeLength));

        $aimg = imageCreate($img_width, $img_height);       //生成图片
        ImageColorAllocate($aimg, 255, 255, 255);            //图片底色，ImageColorAllocate第1次定义颜色PHP就认为是底色了

        for ($i = 1; $i <= 128; $i++)
        {
            imageString($aimg, 1, mt_rand(1, $img_width), mt_rand(1, $img_height), "*",
                imageColorAllocate($aimg, mt_rand(200, 255), mt_rand(200, 255), mt_rand(200, 255)));
        }
        for ($i = 0; $i < strlen($code); $i++)
        {
            imageString($aimg, mt_rand(8, 12), $i * $img_width / 4 + mt_rand(1, 8), mt_rand(1, $img_height / 4),
                $code[$i],
                imageColorAllocate($aimg, mt_rand(0, 100), mt_rand(0, 150), mt_rand(0, 200)));
        }

        ob_start();
        ImagePng($aimg);
        $data = ob_get_clean();
        ImageDestroy($aimg);
        return array('code' => $code, 'image' => $data);
    }
172221
private function GD2BMPstring(&$gd_image)
		# Author:     James Heinrich
		# Purpose:    Save file as type bmp
		# Param in:   The image canvas (passed as ref)
		# Param out:
		# Reference:
		# Notes:    This code was stripped out of two external files
		#       (phpthumb.bmp.php,phpthumb.functions.php) and added below to
		#       avoid dependancies.
		#
	{
		$imageX = ImageSX($gd_image);
		$imageY = ImageSY($gd_image);

		$BMP = '';
		for ($y = ($imageY - 1); $y >= 0; $y--)
		{
			$thisline = '';
			for ($x = 0; $x < $imageX; $x++)
			{
				$argb = $this->GetPixelColor($gd_image, $x, $y);
				$thisline .= chr($argb['blue']) . chr($argb['green']) . chr($argb['red']);
			}
			while (strlen($thisline) % 4)
			{
				$thisline .= "\x00";
			}
			$BMP .= $thisline;
		}

		$bmpSize = strlen($BMP) + 14 + 40;
		// BITMAPFILEHEADER [14 bytes] - http://msdn.microsoft.com/library/en-us/gdi/bitmaps_62uq.asp
		$BITMAPFILEHEADER = 'BM';                                    // WORD    bfType;
		$BITMAPFILEHEADER .= $this->LittleEndian2String($bmpSize, 4); // DWORD   bfSize;
		$BITMAPFILEHEADER .= $this->LittleEndian2String(0, 2); // WORD    bfReserved1;
		$BITMAPFILEHEADER .= $this->LittleEndian2String(0, 2); // WORD    bfReserved2;
		$BITMAPFILEHEADER .= $this->LittleEndian2String(54, 4); // DWORD   bfOffBits;

		// BITMAPINFOHEADER - [40 bytes] http://msdn.microsoft.com/library/en-us/gdi/bitmaps_1rw2.asp
		$BITMAPINFOHEADER = $this->LittleEndian2String(40, 4); // DWORD  biSize;
		$BITMAPINFOHEADER .= $this->LittleEndian2String($imageX, 4); // LONG   biWidth;
		$BITMAPINFOHEADER .= $this->LittleEndian2String($imageY, 4); // LONG   biHeight;
		$BITMAPINFOHEADER .= $this->LittleEndian2String(1, 2); // WORD   biPlanes;
		$BITMAPINFOHEADER .= $this->LittleEndian2String(24, 2); // WORD   biBitCount;
		$BITMAPINFOHEADER .= $this->LittleEndian2String(0, 4); // DWORD  biCompression;
		$BITMAPINFOHEADER .= $this->LittleEndian2String(0, 4); // DWORD  biSizeImage;
		$BITMAPINFOHEADER .= $this->LittleEndian2String(2835, 4); // LONG   biXPelsPerMeter;
		$BITMAPINFOHEADER .= $this->LittleEndian2String(2835, 4); // LONG   biYPelsPerMeter;
		$BITMAPINFOHEADER .= $this->LittleEndian2String(0, 4); // DWORD  biClrUsed;
		$BITMAPINFOHEADER .= $this->LittleEndian2String(0, 4); // DWORD  biClrImportant;

		return $BITMAPFILEHEADER . $BITMAPINFOHEADER . $BMP;
	}
827030
def create_thumbnail(img, width, height):
    
    size = (width, height)
    img.thumbnail(size)
    return img
731427
protected function calcImageSize($imageData, $maxWidth, $maxHeight)
    {
        $pdf = $this->getPdf();

        list($width, $height) = getimagesizefromstring($imageData);
        $width = $pdf->pixelsToUnits($width);
        $height = $pdf->pixelsToUnits($height);

        list($newWidth, $newHeight) = ImageResize::getCalculatedSize($width, $height, $maxWidth, $maxHeight);

        return [
            $newWidth,
            $newHeight,
        ];
    }
415242
private function getAdjustedImageDimensions(Image $image, int $width, int $height, bool $crop = false): array
    {
        if ($image->getWidth() / $image->getHeight() > $width / $height) {		// current is wider than new
            if (true === $crop) {	// upscale prevention
                return [
                    'width' => $this->getImageWidth($image, $height),
                    'height' => $height,
                ];
            } else {
                return [
                    'width' => $width,
                    'height' => $this->getImageHeight($image, $width),
                ];
            }
        } elseif ($image->getWidth() / $image->getHeight() < $width / $height) {	// current is taller than new
            if (true === $crop) {	// upscale prevention
                return [
                    'width' => $width,
                    'height' => $this->getImageHeight($image, $width),
                ];
            } else {
                return [
                    'width' => $this->getImageWidth($image, $height),
                    'height' => $height,
                ];
            }
        } else {									// current has same aspect ratio as new
            return [
                'width' => $width,
                'height' => $height,
            ];
        }
    }
1371464
public static BufferedImage createBufferedImage(int width, int height,
			String imageFormat) {

		int imageType;

		switch (imageFormat.toLowerCase()) {
		case IMAGE_FORMAT_JPG:
		case IMAGE_FORMAT_JPEG:
			imageType = BufferedImage.TYPE_INT_RGB;
			break;
		default:
			imageType = BufferedImage.TYPE_INT_ARGB;
		}

		BufferedImage image = new BufferedImage(width, height, imageType);

		return image;
	}
1220437
function getNewImageDimentions(img, width, height) {
    var detImg = img.width / img.height;
    if (width > 0 && height > 0) {
      // 同时指定了宽高，按原图缩放
      if (width / height > detImg) {
        height = width / detImg;
      } else {
        width = height * detImg;
      }
      return [ width, height ];
    } else if (width > 0) {
      // 只指定宽度的情况
      return [ width, width / detImg ];
    } else if (height > 0) {
      // 只指定高度的情况
      return [ height * detImg, height ];
    } else {
      // 否则原 size 返回
      return [ img.width, img.height ];
    }
  }
1073663
public function imageGetIntermediateSize($data, $post_id, $size) {
	    $result = $this->buildImgixImage($post_id, $size);

	    if (is_array($result) && !empty($result)) {
            $data['url'] = $result[0];
        }

		return $data;
	}
3623
public function limitImageSize($width, $height)
    {
        if ($this->maxImageSize !== null) {
            $imageSize = $width * $height;

            if ($imageSize > $this->maxImageSize) {
                $width = $width / sqrt($imageSize / $this->maxImageSize);
                $height = $height / sqrt($imageSize / $this->maxImageSize);
            }
        }

        return [
            (int) $width,
            (int) $height,
        ];
    }
932623
private function createBlank($width, $height)
    {
        $blank = imagecreatetruecolor($width, $height);

        /**
         * This is not ideal when converting png to jpeg as instead of a default
         * black background we end up with a white one.
         * This is alleviated by additional use of imagecopyresampled() before
         * outputting jpegs.
         */
        if ($this->getMime() === 'image/png') {
            imagealphablending($blank, false);
            imagesavealpha($blank, true);
        }

        return $blank;
    }
731539
public function resolveMissingDimensions(Image $image, $width, $height)
    {
        if (is_null($width) and is_null($height)) {
            $width = $image->width();
            $height = $image->height();
        }

        if (is_null($width)) {
            $width = $height * ($image->width() / $image->height());
        }

        if (is_null($height)) {
            $height = $width / ($image->width() / $image->height());
        }

        return [
            (int) $width,
            (int) $height,
        ];
    }
835993
public function canvas($width, $height = NULL, $rgb = 'transparent', $real = false) : GD
    {   
        if( $this->mime->type($width, 0) === 'image' )
        {
            $this->createImageCanvas($width);
        }
        else
        {
            $this->createEmptyCanvas($width, $height, $rgb, $real, $p1);
        }
        
        $this->defaultRevolvingVariables();

        return $this;
    }
102517
function (src, x, y, width, height) {
		var obj = this.createElement('img')
			.attr({ src: src });

		if (arguments.length > 1) {
			obj.attr({
				x: x,
				y: y,
				width: width,
				height: height
			});
		}
		return obj;
	}
809262
public function generateThumbnail($id, $width, $height = null)
	{
		if ($height === null)
		{
			$height = $width;
		}

		$temp = $this->container->download($id);

		$img = new \Imagick($temp->getPath());
		$img->cropThumbnailImage($width, $height);
		$img->writeImage();

		return $this->container->upload($temp);
	}
433022
public static BufferedImage createErrorImage (int width, int height)
    {
        BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_INDEXED);
        Graphics2D g = (Graphics2D)img.getGraphics();
        g.setColor(Color.red);
        Label l = new Label("Error");
        l.layout(g);
        Dimension d = l.getSize();
        // fill that sucker with errors
        for (int yy = 0; yy < height; yy += d.height) {
            for (int xx = 0; xx < width; xx += (d.width+5)) {
                l.render(g, xx, yy);
            }
        }
        g.dispose();
        return img;
    }
291445
private function getAdjustedImageCropDimensions(
        Image $image,
        int $width,
        int $height,
        bool $relative = false
    ): array {
        $w = $image->getWidth() / $width;
        $h = $image->getHeight() / $height;

        if ($w < 1 || $h < 1) {
            if ($w < $h) {
                return [
                    'width' => $width * $w,
                    'height' => $height * $w,
                ];
            } else {
                return [
                    'width' => $width * $h,
                    'height' => $height * $h,
                ];
            }
        } else {
            if ($w < $h) {
                return [
                    'width' => $width * (true === $relative ? $w : 1),
                    'height' => $height * (true === $relative ? $w : 1),
                ];
            } else {
                return [
                    'width' => $width * (true === $relative ? $h : 1),
                    'height' => $height * (true === $relative ? $h : 1),
                ];
            }
        }
    }
352409
static function verifycode_imagick($img_width = 80, $img_height = 30, $addRandomLines = true, $swirl = true)
    {
        $fontSize = 24;

        /* imagick对象 */
        $Imagick = new \Imagick();

         /* 背景对象 */
        $bg = new \ImagickPixel();

        /* Set the pixel color to white */
        $bg->setColor('rgb(235,235,235)');

        /* 画刷 */
        $ImagickDraw = new \ImagickDraw();

        if (is_file(self::$verifyCodeFontFile))
        {
            $ImagickDraw->setFont(self::$verifyCodeFontFile);
        }

        $ImagickDraw->setFontSize($fontSize);
        $ImagickDraw->setFillColor('black');

        $code = strtoupper(RandomKey::string(self::$verifyCodeLength));

        /* Create new empty image */
        $Imagick->newImage($img_width, $img_height, $bg);

        /* Write the text on the image */
        $Imagick->annotateImage($ImagickDraw, 4, 20, 0, $code);

        /* 变形 */
        if ($swirl)
        {
            $Imagick->swirlImage(10);
        }

        /* 随即线条 */
        if ($addRandomLines)
        {
            $ImagickDraw->line(rand(0, 70), rand(0, 30), rand(0, 70), rand(0, 30));
            $ImagickDraw->line(rand(0, 70), rand(0, 30), rand(0, 70), rand(0, 30));
            $ImagickDraw->line(rand(0, 70), rand(0, 30), rand(0, 70), rand(0, 30));
            $ImagickDraw->line(rand(0, 70), rand(0, 30), rand(0, 70), rand(0, 30));
            $ImagickDraw->line(rand(0, 70), rand(0, 30), rand(0, 70), rand(0, 30));
        }

        /* Draw the ImagickDraw object contents to the image. */
        $Imagick->drawImage($ImagickDraw);

        /* Give the image a format */
        $Imagick->setImageFormat('png');

        /* Send headers and output the image */
        return array('image' => $Imagick->getImageBlob(), 'code' => $code);
    }