Captcha::getImage

Gets CAPTCHA protection token image.

@return string Base64 image string.
@throws \O2System\Spl\Exceptions\RuntimeException
188243
public function getImage()
    {
        if (class_exists('O2System\Framework') or class_exists('\O2System\Reactor', false)) {
            $tempFilePath = @tempnam(PATH_CACHE, 'captcha');
        } else {
            $tempFilePath = @tempnam(
                sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'o2system' . DIRECTORY_SEPARATOR,
                'captcha'
            );
        }

        if ($image = imagecreatetruecolor(200, 50)) {
            $backgroundColor = imagecolorallocate($image, 255, 255, 255);
            $lineColor = imagecolorallocate($image, 64, 64, 64);
            $pixelColor = imagecolorallocate($image, 0, 0, 255);

            imagefilledrectangle($image, 0, 0, 200, 50, $backgroundColor);

            for ($i = 0; $i < 3; $i++) {
                imageline($image, 0, rand() % 50, 200, rand() % 50, $lineColor);
            }

            for ($i = 0; $i < 1000; $i++) {
                imagesetpixel($image, rand() % 200, rand() % 50, $pixelColor);
            }

            $textColor = imagecolorallocate($image, 0, 0, 0);

            for ($i = 0; $i < 6; $i++) {
                imagestring($image, 10, 20 + ($i * 30), 20, substr($this->getToken(), $i, 1), $textColor);
            }

            imagepng($image, $tempFilePath);

            $base64Image = base64_encode(file_get_contents($tempFilePath));
            @unlink($tempFilePath);

            return 'data:image/png;base64,' . $base64Image;
        }

        // Cannot Initialize new GD image stream
        throw new RuntimeException('SECURITY_E_CAPTCHA_GD_IMAGE_STREAM');
    }
1337828
public function getImageHandler()
    {
        if (!$this->imageHandler) {
            $this->imageHandler = new CaptchaImage();
            
            $object = $this->imageHandler;
            $object->width = 90;
            $object->height = 26;
            $object->background = 1;
            $object->adulterate = 1;
            $object->scatter = '';
            $object->color = 1;
            $object->size = 0;
            $object->shadow = 1;
            $object->animator = 0;
        }
        
        return $this->imageHandler;
    }
561452
public function getImageCode($appKey) {
    	try{
			if (empty($appKey))
				throw new Exception('Paramer "appKey" is required');


    		$params = array (
    		'appKey' => $appKey
    		);

    		$ret = $this->SendRequest->curl('/getImgCode.json',$params,'urlencoded','sms','GET');
    		if(empty($ret))
    			throw new Exception('bad request');
    		return $ret;

    	}catch (Exception $e) {
    		print_r($e->getMessage());
    	}
   }
316334
private function getImage()
    {
        $image = $this->_parser->find('#content table tr', 0)->find('td', 0)->find('img', 0);

        return $image ? $image->src : '';
    }
422851
public function getMainImage()
    {
        $imgUrl = false;

        if ($this->getImage() !== null) {
            $imgUrl = $this->getImage();
        }

        if (!$imgUrl) {
            foreach ($this->dom->getElementsByTagName('link') as $link) {
                /** @var \DOMElement $link */
                /*
                 * Check for the rel attribute, then check if the rel attribute is either img_src or image_src, and
                 * finally check for the existence of the href attribute, which should hold the image url.
                 */
                if ($link->hasAttribute('rel') && ($link->getAttribute('rel') === 'img_src' || $link->getAttribute('rel') === 'image_src') && $link->hasAttribute('href')) {
                    $imgUrl = $link->getAttribute('href');
                    break;
                }
            }
        }

        if (!empty($imgUrl) && $this->configuration->getFixRelativeURLs()) {
            $this->setImage($this->toAbsoluteURI($imgUrl));
        }
    }
336736
public function getDataUri()
    {
        if (empty($this->image)) {
            $this->create();
        }

        ob_start();
        call_user_func('image'.$this->image_type, $this->image);
        $contents = ob_get_clean();

        return 'data:image/'.$this->image_type.';base64,'.base64_encode($contents);
    }
491590
public function display()
    {
        $image = Image::create(
            $this->urlResolver->resolve(['/ccm/system/captcha/picture'])->setQuery('nocache=' . round(microtime(true) * 1000)),
            t('Captcha Code'),
            [
                'class' => 'ccm-captcha-image',
                'onclick' => h('this.src = this.src.replace(/([?&]nocache=)(\d+)/, \'$1\' + ((new Date()).getTime()))'),
                'width' => $this->securimage->image_width,
                'height' => $this->securimage->image_height,
            ]
        );
        foreach ($this->getPictureAttributes() as $attributeName => $attributeValue) {
            if ($attributeValue === null) {
                $image->removeAttribute($attributeName);
            } else {
                switch ($attributeName) {
                    case 'class':
                        $image->addClass($attributeValue);
                        break;
                    default:
                        $image->setAttribute($attributeName, $attributeValue);
                        break;
                }
            }
        }
        echo '<div>', (string) $image, '</div>';
    }
773540
public function getCaptcha($path)
    {
        $url = Config::get('url.login_captcha');
        $cookie = new CookieJar();
        $codePath = $path . sha1($this->getUsername() . '-' . microtime(true)) . '.gif';
        $options = ['cookies' => $cookie, 'save_to' => $codePath];

        $response = $this->request('get', [$url, [], $options]);

        // Check the StatusCode
        if ($response->getStatusCode() == 200) {
            throw new HttpException('get the captcha failed!', 10005);
        }

        return $codePath;
    }
981835
public function image() {
		if (Request::hasFile('image') && Request::has('table_name') && Request::has('field_name')) {
			return json_encode(self::saveImage(
				Request::input('table_name'), 
				Request::input('field_name'), 
				Request::file('image'),
				null,
				Request::file('image')->getClientOriginalExtension()
			));
		} elseif (!Request::hasFile('image')) {
			return 'no image';
		} elseif (!Request::hasFile('table_name')) {
			return 'no table_name';
		} elseif (!Request::hasFile('field_name')) {
			return 'no field_name';
		}
	}
114183
public function getMetaImage()
    {
        $metaImage = $this->getTranslationAttribute('meta_image');

        if ($metaImage = get_nuclear_cover($metaImage))
        {
            return $metaImage;
        }

        if ($coverImage = $this->getCoverImage())
        {
            return $coverImage;
        }

        return null;
    }
828009
function captcha($font,$size=24,$len=5,
		$key=NULL,$path='',$fg=0xFFFFFF,$bg=0x000000) {
		if ((!$ssl=extension_loaded('openssl')) && ($len<4 || $len>13)) {
			user_error(sprintf(self::E_Length,$len),E_USER_ERROR);
			return FALSE;
		}
		if (!function_exists('imagettftext')) {
			user_error(self::E_TTF,E_USER_ERROR);
			return FALSE;
		}
		$fw=Base::instance();
		foreach ($fw->split($path?:$fw->UI.';./') as $dir)
			if (is_file($path=$dir.$font)) {
				$seed=strtoupper(substr(
					$ssl?bin2hex(openssl_random_pseudo_bytes($len)):uniqid(),
					-$len));
				$block=$size*3;
				$tmp=[];
				for ($i=0,$width=0,$height=0;$i<$len;$i++) {
					// Process at 2x magnification
					$box=imagettfbbox($size*2,0,$path,$seed[$i]);
					$w=$box[2]-$box[0];
					$h=$box[1]-$box[5];
					$char=imagecreatetruecolor($block,$block);
					imagefill($char,0,0,$bg);
					imagettftext($char,$size*2,0,
						($block-$w)/2,$block-($block-$h)/2,
						$fg,$path,$seed[$i]);
					$char=imagerotate($char,mt_rand(-30,30),
						imagecolorallocatealpha($char,0,0,0,127));
					// Reduce to normal size
					$tmp[$i]=imagecreatetruecolor(
						($w=imagesx($char))/2,($h=imagesy($char))/2);
					imagefill($tmp[$i],0,0,IMG_COLOR_TRANSPARENT);
					imagecopyresampled($tmp[$i],
						$char,0,0,0,0,$w/2,$h/2,$w,$h);
					imagedestroy($char);
					$width+=$i+1<$len?$block/2:$w/2;
					$height=max($height,$h/2);
				}
				$this->data=imagecreatetruecolor($width,$height);
				imagefill($this->data,0,0,IMG_COLOR_TRANSPARENT);
				for ($i=0;$i<$len;$i++) {
					imagecopy($this->data,$tmp[$i],
						$i*$block/2,($height-imagesy($tmp[$i]))/2,0,0,
						imagesx($tmp[$i]),imagesy($tmp[$i]));
					imagedestroy($tmp[$i]);
				}
				imagesavealpha($this->data,TRUE);
				if ($key)
					$fw->$key=$seed;
				return $this->save();
			}
		user_error(self::E_Font,E_USER_ERROR);
		return FALSE;
	}
595610
protected function GetCSRFToken()
	{
		$token = $this->Context->Get('X-CSRFToken');
	
		if (!$token)
		{
			$token = md5(rand(1111111111,9999999999).microtime());
			$this->Context->Set('X-CSRFToken',$token);
		}
	
		return $token;
	}
1250005
function toHTML()
    {

        return '<div class="captcha-container"><img src="' . $this->form_properties['assets_url'] . 'process.php?captcha=' . ($this->form_properties['captcha_storage'] == 'session' ? 2 : 1) . '&amp;nocache=' . time() . '" alt=""' . ($this->form_properties['doctype'] == 'xhtml' ? '/' : '') . '><a href="javascript:void(0)" title="' . $this->form_properties['language']['new_captcha'] . '">' . $this->form_properties['language']['new_captcha'] . '</a></div>';
    
    }
154730
private function checkForMetaTag(): ?Image {
        $image = $this->checkForTwitterTag();

        if ($image) {
            return $image;
        }

        $image = $this->checkForOpenGraphTag();

        if ($image) {
            return $image;
        }

        $image = $this->checkForLinkTag();

        if ($image) {
            return $image;
        }

        return null;
    }
1133729
public function getImageAttribute()
    {
        // It should have image
        if ($this->exists) {
            return $this->image();
        }

        return isset($this->attributes['image']) ? $this->attributes['image'] : null;
    }
1152966
public static function getCodeImage($id, $config = array())
    {
        $key = self::getKey($id);
        
        return captcha($key, $config);
    }
768860
public function screenshotAsImage($asBase64 = false)
    {
        $image = $this->getDriver()->curl(
            $this->getDriver()->factoryCommand('screenshot', WebDriver_Command::METHOD_GET)
        );
        $image = $image['value'];
        if (!$asBase64) {
            $image = base64_decode($image);
        }
        return $image;
    }