Browse Source

文字图片

Erasin 4 years ago
parent
commit
ba9b9bdd0c
15 changed files with 1926 additions and 4 deletions
  1. 4 1
      composer.json
  2. 1776 2
      composer.lock
  3. 13 1
      src/Dy/Image.php
  4. 29 0
      tests/RandTest.php
  5. BIN
      tests/a.png
  6. BIN
      tests/b.png
  7. BIN
      tests/c.png
  8. 8 0
      tests/crypt_test.php
  9. 7 0
      tests/fenci.php
  10. 8 0
      tests/shell.php
  11. 28 0
      tests/test.php
  12. 32 0
      tests/test_image.php
  13. 10 0
      tests/test_map.php
  14. 8 0
      tests/test_otp.php
  15. 3 0
      tests/time.php

+ 4 - 1
composer.json

@@ -18,5 +18,8 @@
         "psr-4": {
             "Dy\\": "src/"
         }
+    },
+    "require-dev": {
+        "phpunit/phpunit": "^8.5"
     }
-}
+}

File diff suppressed because it is too large
+ 1776 - 2
composer.lock


+ 13 - 1
src/Dy/Image.php

@@ -4,7 +4,6 @@ namespace Dy;
 
 class Image
 {
-
     /**
      * new Image
      *
@@ -27,6 +26,19 @@ class Image
     }
 
     /**
+     * 文字处理
+     *
+     * @param integer $x 坐标
+     * @param integer $y 坐标
+     * @param string $content 内容
+     * @param font $font 字体路径
+     * @return Image|ErrorException
+     */
+    public function text(int $x, int $y, string $content, string $font)
+    {
+    }
+
+    /**
      * 尺寸缩放
      *
      * @param integer $width 长度

+ 29 - 0
tests/RandTest.php

@@ -0,0 +1,29 @@
+<?php
+
+use PHPUnit\Framework\TestCase;
+
+final class RandTest extends TestCase
+{
+    public function testFloat()
+    {
+        $re = Dy\Rand::float(4);
+        $this->assertEquals(true, is_float($re));
+    }
+
+    public function testNumeric()
+    {
+        $re = Dy\Rand::numeric(4);
+        $this->assertEquals(true, is_numeric($re));
+    }
+}
+
+
+
+// var_dump(Dy\Rand::float(4));
+// var_dump(Dy\Rand::alphanumeric(4));
+// var_dump(Dy\Rand::numeric(4));
+// var_dump(Dy\Crypt::md5('test'));
+// var_dump(md5('test'));
+
+
+// echo Dy\Shell::exec("exa", "");

BIN
tests/a.png


BIN
tests/b.png


BIN
tests/c.png


+ 8 - 0
tests/crypt_test.php

@@ -0,0 +1,8 @@
+<?php
+
+$str = "hello";
+$str_base32  = Dy\Crypt::base32_encode($str);
+var_dump($str_base32);
+var_dump(Dy\Crypt::base32_decode($str_base32));
+
+echo Dy\Crypt::md5(1);

+ 7 - 0
tests/fenci.php

@@ -0,0 +1,7 @@
+<?php
+
+$fenci = new Dy\Fenci();
+$re    = $fenci->do('中文分词是文本处理不可或缺的一步!', false);
+var_dump($re);
+$re = $fenci->do('中文分词是文本处理不可或缺的一步!', true);
+var_dump($re);

+ 8 - 0
tests/shell.php

@@ -0,0 +1,8 @@
+<?php
+
+// $re = DY\Shell::shell('ls', '-l');
+
+// var_dump($re);
+
+$re = Dy\Shell::exec('python', "-c \"print('Hello world!')\"");
+var_dump($re);

+ 28 - 0
tests/test.php

@@ -0,0 +1,28 @@
+<?php
+
+$ext = 'dyutils';
+
+if (extension_loaded($ext)) {
+    echo 'load ext';
+}
+
+echo dyutils_version();
+
+$ext = new ReflectionExtension($ext);
+
+var_dump($ext);
+var_dump($ext->getName());
+var_dump($ext->getVersion());
+var_dump($ext->getINIEntries());
+var_dump($ext->getClassNames());
+var_dump($ext->getDependencies());
+var_dump($ext->getFunctions());
+
+
+// $funs = get_extension_funcs($ext);
+// print_r($funs);
+
+foreach ($ext->getFunctions() as $k => $v) {
+    $f = new ReflectionFunction($k);
+    echo($f->getName());
+}

+ 32 - 0
tests/test_image.php

@@ -0,0 +1,32 @@
+<?php
+$code = 'https://demo.dyuit.cn/youxuanfuli';
+
+$src  = './a.png';
+$dest = './b.png';
+\Dy\Image::avatar($src, 300, 10);
+
+(new Dy\Image($src))->resize(600, 600)->crop(100, 100, 200, 200)->save($dest);
+
+$img_bg  = new Dy\Image($src);
+$img_top = new Dy\Image($dest);
+Dy\Image::new(500, 500)->over($img_bg, 100, 100)->over($img_top, 10, 10)->text(0, 0, '我的内容', 'assets.bak/HarmonyOS_Sans_SC_Light.ttf')->save('./c.png');
+
+// $a = get_class_methods("Dy\Image");
+// print_r($a);
+
+// $ok = \Dy\Image::avatar($p, 300, 10);
+// $ok = \Dy\Image::resize($p, $p, 200, 200);
+
+// $c = file_get_contents($p, true);
+// header('Content-Type: image/png');
+// echo $c;
+
+// unlink($p);
+
+// $ok = \Dy\Barcode::qr($code, $p);
+
+try {
+    \Dy\Barcode::code39('A1234', 'b.png');
+} catch (\Throwable $th) {
+    var_dump($th);
+}

+ 10 - 0
tests/test_map.php

@@ -0,0 +1,10 @@
+<?php
+$gps1 = new Dy\Map(121.468189122, 31.1526609317, 0); // var_dump($gps1);
+var_dump($gps1->gcj02());
+var_dump($gps1->gcj02()->wgs84());
+var_dump($gps1->wgs84());
+var_dump($gps1->bd09());
+// echo($gps1->lng);
+
+$gps2 = new Dy\Map(122.478189122, 31.1576609317, 2);
+echo $gps1->distance($gps2);

+ 8 - 0
tests/test_otp.php

@@ -0,0 +1,8 @@
+<?php
+
+$str_base32  = Dy\Crypt::base32_encode("hello");
+var_dump($str_base32);
+$a = new Dy\Otp($str_base32, 6, 60);
+var_dump($a->hotp(1));
+var_dump($a->totp());
+var_dump($a->url("wang 1@test2:test3"));

+ 3 - 0
tests/time.php

@@ -0,0 +1,3 @@
+<?php
+
+echo Dy\Time::now_time();