打开一张图像
@param  string $imgname 图像路径
972572
public function open($imgname){
        //检测图像文件
        if(!is_file($imgname)) E('不存在的图像文件');

        //销毁已存在的图像
        empty($this->img) || $this->img->destroy();

        //载入图像
        $this->img = new \Imagick(realpath($imgname));

        //设置图像信息
        $this->info = array(
            'width'  => $this->img->getImageWidth(),
            'height' => $this->img->getImageHeight(),
            'type'   => strtolower($this->img->getImageFormat()),
            'mime'   => $this->img->getImageMimeType(),
        );
    }
1233057
private static function _getJsonView($param, bool $haveQuotation, int $indent, string $symbol, bool $isPHP)
    {
        // 1. 定义变量
        $param = self::toObject($param);
        $response = [];
        $indentStr = '';
        for ($i = 0; $i < $indent; $i++) {
            $indentStr .= ' ';
        }

        // 2. 判断是对象还是数组
        if (is_array($param) || $isPHP) {
            $response[] = "[";
        } else {
            $response[] = "{";
        }
        foreach ($param as $key => $value) {
            // 3. 子元素是否为 复合数据类型
            if (is_array($value) || is_object($value)) {
                $view = self::_getJsonView($value, $haveQuotation, $indent, $symbol, $isPHP);
                if (is_object($param)) {
                    $view[0] = "\"$key\"$symbol " . $view[0];
                }
                $view = array_map(function ($item) use ($indentStr) {
                    return $indentStr . $item;
                }, $view);
                $view[count($view) - 1] .= ',';
                $response = array_merge($response, $view);
            } else if (is_array($param)) {
                // 4. 是否为数组
                $response[] = $indentStr . StringTool::valueView($value) . ',';
            } else if (is_object($param)) {
                // 5. 是否为对象
                $response[] = $indentStr . "\"$key\"{$symbol} " . StringTool::valueView($value) . ",";
            }
        }
        // 6. 去除最后一个元素的逗号
        $response[count($response) - 1] = trim($response[count($response) - 1], ',');
        // 2. 判断是对象还是数组
        if (is_array($param) || $isPHP) {
            $response[] = "]";
        } else {
            $response[] = "}";
        }
        return $response;
    }
842304
public function save($imgname, $type = null, $quality=80,$interlace = true){
        if(empty($this->img)) $this->throwError('没有可以被保存的图像资源');

        //自动获取图像类型
        if(is_null($type)){
            $type = $this->info['type'];
        } else {
            $type = strtolower($type);
        }

        //保存图像
        if('jpeg' == $type || 'jpg' == $type){
            //JPEG图像设置隔行扫描
            imageinterlace($this->img, $interlace);
            imagejpeg($this->img, $imgname,$quality);
        }elseif('gif' == $type && !empty($this->gif)){
            $this->gif->save($imgname);
        }else{
            $fun  =   'image'.$type;
            $fun($this->img, $imgname);
        }
    }
948185
protected function applyWatermark($im) {
	    
	    // text to watermark with	    
	    if(method_exists($this->media, 'getWatermarkText')) {
	       $word1_text = $this->media->getWatermarkText();
	    }
	    else {
	        $word1_text = $this->media->getTitle();
	    }
	
	    $this->embedText(
	        $im, 
	        $word1_text, 
	        $this->font_max_size,
	        $this->font_color,
	        WT_ROOT . Config::FONT_DEJAVU_SANS_TTF,
	        'top', 
	        'left'
	     );
	
	    return ($im);
	}
735939
public function output(string $mime)
    {
        $output = $this->getOutput($mime);
        if (empty($output))
            $output = "Unknown mime type requested";

        echo $output;
        return $this;
    }
248200
public function draw($im) {
        $this->drawChar($im, $this->text, true);
        $this->drawText($im, 0, 0, $this->positionX, $this->thickness);
    }
703437
public function constructAmpImg($oneImgWithContent, $height, $width, $imgSrc, $imgAlt) {
        $ampImgTagOpen = "<amp-img height=$height width=$width src='$imgSrc' alt='$imgAlt' media='(min-width: 775px)' >"; // fully constructed amp img opening tag
        
        $ampImgTagOpenResponsive = "<amp-img height=$height width=$width src='$imgSrc' alt='$imgAlt' media='(max-width: 775px)' layout='responsive'>"; // fully constructed amp img opening tag - RESPONSIVE version
        
        // Fully replace the img tag with the constructed amp-img tag
        $oneAmpImgWithContent = preg_replace("/<img(.*?)>/", "$ampImgTagOpen</amp-img>$ampImgTagOpenResponsive</amp-img>", $oneImgWithContent);
        
        return $oneAmpImgWithContent;
    }
737836
public function transmute($inFilename, Specification $targetFormat, $outFilename)
    {
        $extractedFile = $this->extractor->extract($inFilename, $targetFormat);

        if (!$extractedFile) {
            return null;
        }

        $this->converter->convert($extractedFile, $targetFormat, $outFilename);

        return $outFilename;
    }
635985
public function saveConfigName($configName, $configId = false)
    {
        $this->em->getRepository('KunstmaanDashboardBundle:AnalyticsConfig')->saveConfigName($configName, $configId);
    }
108312
public function saveAttachmentsMessagesBySubject($subject, $dir = null, $charset = null)
    {
        $criteria = 'SUBJECT "'.$subject.'"';
        $ids = imap_search($this->imap, $criteria, null, $charset);
        if(!$ids){
            throw new ImapClientException('Messages not found. Or this criteria not supported on your email server.');
        };
        foreach ($ids as $id) {
            $this->getMessage($id);
            if(isset($dir)){
                $dir = ['dir'=>$dir];
            };
            $this->saveAttachments($dir);
        };
    }
1234189
protected function drawText($im, $x1, $y1, $x2, $y2) {
        foreach ($this->labels as $label) {
            $label->draw($im,
                ($x1 + $this->offsetX) * $this->scale + $this->pushLabel[0],
                ($y1 + $this->offsetY) * $this->scale + $this->pushLabel[1],
                ($x2 + $this->offsetX) * $this->scale + $this->pushLabel[0],
                ($y2 + $this->offsetY) * $this->scale + $this->pushLabel[1]);
        }
    }
491567
public function draw($im) {
        // Starting *
        $this->drawChar($im, $this->code[$this->starting], true);
        $c = count($this->data);
        for ($i = 0; $i < $c; $i++) {
            $this->drawChar($im, $this->data[$i], true);
        }

        // Checksum
        $c = count($this->checksumValue);
        for ($i = 0; $i < $c; $i++) {
            $this->drawChar($im, $this->code[$this->checksumValue[$i]], true);
        }

        // Ending *
        $this->drawChar($im, $this->code[$this->ending], true);

        // Draw a Final Bar
        $this->drawChar($im, '0', true);
        $this->drawText($im, 0, 0, $this->positionX, $this->thickness);
    }
739338
function run($num=1)
    {
        //初始化事件系统
        if (!($this->protocol instanceof Swoole\Server\UDP_Server_Protocol))
        {
            return error(902);
        }
        //建立服务器端Socket
        $this->server_sock = $this->create("udp://{$this->host}:{$this->port}");
        stream_set_blocking($this->server_sock,$this->server_block);
        $this->server_socket_id = (int)$this->server_sock;
        //设置事件监听，监听到服务器端socket可读，则有连接请求
        $this->protocol->onStart();
        $this->server_loop();
    }
876501
public function watermark($img, $outPath = '', $pos = '', $waterImg = '', $alpha = '', $text = '')
    {
        // 验证原图像 和 是否已有错误
        if (false === $this->_checkImage($img) || $this->hasError()) {
            return $this;
        }

        $imgInfo = pathinfo($img);
        $imgType = $this->_handleImageType($imgInfo['extension']);
        $outPath = $outPath ?: ($this->waterOptions['path'] ?: \dirname($img));
        $pos = $pos ?: $this->waterOptions['pos'];
        $alpha = $alpha ?: $this->waterOptions['alpha'];
        $waterImg = $waterImg ?: $this->waterOptions['img'];
        $waterImgType = $resWaterImg = null;

        list($imgWidth, $imgHeight) = getimagesize($img);

        if ($waterImg) {

            // 验证水印图像
            if (false === $this->_checkImage($waterImg)) {
                return $this;
            }

            $waterImgType = $this->_handleImageType(pathinfo($waterImg, PATHINFO_EXTENSION));
            list($waterWidth, $waterHeight) = getimagesize($waterImg);

            if ($imgHeight < $waterHeight || $imgWidth < $waterWidth) {
                $this->_error = 'The image is too small.';

                return $this;
            }

            // create water image resource
            $resWaterImg = \call_user_func("imagecreatefrom{$waterImgType}", $waterImg);
        } else {
            //水印文字
            $text = $text ?: $this->waterOptions['text'];

            if (!is_file($this->waterOptions['fontFile'])) {
                throw new InvalidConfigException('请配置正确的水印文字资源路径');
            }

            if (!$text || \strlen($this->waterOptions['fontColor']) !== 6) {
                throw new InvalidConfigException('The watermark font color length must equal to 6.');
            }

            $textInfo = imagettfbbox($this->waterOptions['fontSize'], 0, $this->waterOptions['fontFile'], $text);
            $waterWidth = $textInfo[2] - $textInfo[6];
            $waterHeight = $textInfo[3] - $textInfo[7];
        }

        // create image resource 建立原图资源
        $method = "imagecreatefrom{$imgType}";
        $resImg = $method($img);

        //水印位置处理
        list($x, $y) = $this->_calcWaterCoords($pos, $imgWidth, $waterWidth, $imgHeight, $waterHeight);

        if ($waterImg && $resWaterImg && $waterImgType) {

            // is png image. 'IMAGETYPE_PNG' === 3
            if ($waterImgType === self::IMAGE_PNG) {
                imagecopy($resImg, $resWaterImg, $x, $y, 0, 0, $waterWidth, $waterHeight);
            } else {
                imagecopymerge($resImg, $resWaterImg, $x, $y, 0, 0, $waterWidth, $waterHeight, $alpha);
            }
        } else {
            $r = hexdec(substr($this->waterOptions['fontColor'], 0, 2));
            $g = hexdec(substr($this->waterOptions['fontColor'], 2, 2));
            $b = hexdec(substr($this->waterOptions['fontColor'], 4, 2));
            $color = imagecolorallocate($resImg, $r, $g, $b);
            $charset = 'UTF-8';

            imagettftext(
                $resImg, $this->waterOptions['fontSize'], 0, $x, $y,
                $color, $this->waterOptions['fontFile'], iconv($charset, 'utf-8', $text)
            );
        }

        if (!Directory::create($outPath)) {
            $this->_error = 'Failed to create the output directory path!. OUT-PATH: ' . $outPath;

            return $this;
        }

        $outFile = $outPath . '/' . $imgInfo['basename'];

        if ($imgType === self::IMAGE_JPEG) {
            imagejpeg($resImg, $outFile, $this->waterOptions['quality']);
        } elseif ($imgType === self::IMAGE_PNG) {
            imagepng($resImg, $outFile, ceil($this->waterOptions['quality'] / 10));
        } else {
            \call_user_func("image{$imgType}", $resImg, $outFile);
        }

        imagedestroy($resImg);

        $this->working = [
            'raw' => $img,
            'out' => $outFile,
        ];

        $this->_result['workWater']['rawFile'] = $img;
        $this->_result['workWater']['outFile'] = $outFile;

        return $this;
    }
1101335
public static String getImgStr(String imgFile) {
        //将图片文件转化为字节数组字符串，并对其进行Base64编码处理

        InputStream in;
        byte[] data = null;
        //读取图片字节数组
        try {
            in = new FileInputStream(imgFile);
            data = new byte[in.available()];
            in.read(data);
            in.close();

        } catch (IOException e) {
            e.printStackTrace();

        }
        return new String(Base64.encodeBase64(data));

    }
902109
public function draw($im) {
        // Checksum
        $checksum = 0;
        $c = strlen($this->text);
        for ($i = 0; $i < $c; $i++) {
            $checksum += intval($this->text[$i]);
        }

        $checksum = 10 - ($checksum % 10);

        // Starting Code
        $this->drawChar($im, '1');

        // Code
        for ($i = 0; $i < $c; $i++) {
            $this->drawChar($im, $this->findCode($this->text[$i]));
        }

        // Checksum
        $this->drawChar($im, $this->findCode($checksum));

        // Ending Code
        $this->drawChar($im, '1');
        $this->drawText($im, 0, 0, $this->positionX, $this->thickness);
    }
778112
function imgName() {
    var date = new Date(),
        pad = function (n) { return n < 10 ? '0' + n : n; };
    return 'IMG_' + date.getFullYear() + pad(date.getMonth() + 1) + pad(date.getDate()) + '_' +
            pad(date.getHours()) + pad(date.getMinutes()) + pad(date.getSeconds()) + '.png';
}