世界线变动率测试仪v2

2018年06月11日 2042点热度 1人点赞 0条评论

[title]简介[/title]

世界线变动率探测仪是未来(2021年)的冈部伦太郎开发制作的一种仪器,可以用于在世界线发生变动后,探测到世界线的变动率。

详情请看>>世界线变动率探测仪-萌娘百科

当然本文这个是假的

首图链接: https://cloud.aikamino.cn/worldline?width=1920&height=500

格式: image/jpg

查看变动率方式: GET

参数:
  • line={世界线变动率}
  • size={字体大小}
  • width={背景宽度}
  • height={背景高度}
  • bgc={背景颜色}

程序: PHP、GD2

当前版本: v2.0

变动率算法: "1.".substr(time(),0,6);

[title]源码[/title]

<?php
/**
 * Author: kamino
 * CreateTime: 2018/6/10,下午 07:33
 * Description: 世界线变动率测试仪
 * Version: v2
 */

class worldline {
	public $config = array(
		"width"            => 1920,
		"height"           => 1080,
		"font-size"        => 200,
		"background-color" => "000000",
		"font-family"      => array(
			"frame" => __DIR__ . "/font/BONX-Frame.ttf",
			"text"  => __DIR__ . "/font/BONX-Medium.ttf",
			"ette"  => __DIR__ . "/font/BONX-Silhouette.ttf"
		)
	);
	private $set = array();
	private $image;

	/*
	 * 初始化
	 */
	function __construct( $text, $config = array() ) {
		foreach ( $config AS $item => $value ) {
			$this->config[ $item ] = $value;
		}
		$this->set["length"] = strlen( $text );
		$this->set["text"]   = $text;
		$this->set["size"]   = $this->config["font-size"];
		$this->set["bgc"]    = self::hex2rgb( $this->config["background-color"] );
		$this->set["width"]  = $this->config["width"];
		$this->set["height"] = $this->config["height"];
	}

	/*
	 * 计算文字位置
	 */
	private function countValue() {
		$this->set["floatX"] = $this->set["width"] / 2 - ( 0.71 * $this->set["size"] * $this->set["length"] ) / 2;
		$this->set["floatY"] = ( $this->set["height"] + $this->set["size"] ) / 2;

		return $this;
	}

	/*
    * 十六进制转RGB
    */
	static function hex2rgb( $hex ) {
		$hex = str_replace( "#", "", $hex );

		if ( strlen( $hex ) == 3 ) {
			$r = hexdec( substr( $hex, 0, 1 ) . substr( $hex, 0, 1 ) );
			$g = hexdec( substr( $hex, 1, 1 ) . substr( $hex, 1, 1 ) );
			$b = hexdec( substr( $hex, 2, 1 ) . substr( $hex, 2, 1 ) );
		} else {
			$r = hexdec( substr( $hex, 0, 2 ) );
			$g = hexdec( substr( $hex, 2, 2 ) );
			$b = hexdec( substr( $hex, 4, 2 ) );
		}

		return array( $r, $g, $b );
	}

	/*
	 * 准备颜色
	 */
	private function prepareColor() {
		$this->set["bgColor"] = imagecolorallocate( $this->image, $this->set["bgc"][0], $this->set["bgc"][1], $this->set["bgc"][2] );
		@imagefill( $this->image, 0, 0, $this->set["bgColor"] );
		$this->set["textColor"] = array(
			"frame" => imagecolorallocatealpha( $this->image, 0, 0, 0, 0 ),
			"text"  => imagecolorallocatealpha( $this->image, 255, 117, 0, 0 ),
			"ette"  => imagecolorallocatealpha( $this->image, 110, 0, 0, 50 )
		);

		return $this;
	}

	/*
	 * 画背景
	 */
	private function createImage() {
		$this->image = imagecreatetruecolor( $this->set["width"], $this->set["height"] );

		return $this;
	}

	/*
	 * 画上内容
     */
	private function writeText() {
		$str = "";
		for ( $i = 0; $i < $this->set["length"]; $i ++ ) {
			$str .= "1";
		}
		imagettftext( $this->image, $this->set["size"], 0, $this->set["floatX"], $this->set["floatY"], $this->set["textColor"]["ette"], $this->config["font-family"]["ette"], $str );
		imagettftext( $this->image, $this->set["size"], 0, $this->set["floatX"], $this->set["floatY"], $this->set["textColor"]["text"], $this->config["font-family"]["text"], $this->set["text"] );
		imagettftext( $this->image, $this->set["size"], 0.001, $this->set["floatX"], $this->set["floatY"], $this->set["textColor"]["frame"], $this->config["font-family"]["frame"], $str );

		return $this;
	}

	/*
	 * 输出图片
	 */
	public function showImage() {
		$this->countValue()->createImage()->prepareColor()->writeText();
		header( "Content-type: image/jpeg" );
		imagejpeg( $this->image );
		imagedestroy( $this->image );
	}

	public function printThis() {
		print_r( $this );
	}
}

[title][/title]

[title]字体+源码[/title]

立即下载

AIKAMINO

暂无