|
@@ -0,0 +1,68 @@
|
|
|
+<?php
|
|
|
+namespace Poster\Lib;
|
|
|
+
|
|
|
+use Dever;
|
|
|
+use Dever\Support\Img as Handle;
|
|
|
+
|
|
|
+class Img
|
|
|
+{
|
|
|
+
|
|
|
+ * create 生成图片
|
|
|
+ * @param array $config
|
|
|
+ * @param string $filename
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function create($config = array(), $filename = '', $type = 'gd', $update = 2)
|
|
|
+ {
|
|
|
+ $this->img = isset($this->img) ? $this->img : new Handle();
|
|
|
+
|
|
|
+
|
|
|
+ $config = array
|
|
|
+ (
|
|
|
+ 'background' => '/www/grow/data/upload/1/2018/07/19/a49fe8914df0eada4d4b7d530d7fa5ba.jpg',
|
|
|
+ 'param' => array
|
|
|
+ (
|
|
|
+ 0 => array
|
|
|
+ (
|
|
|
+ 'method' => 'mark',
|
|
|
+ 'water' => '/www/grow/data/upload/1/2018/07/19/46d5b0c5c25c800cf197ea4f64f503f2.jpg',
|
|
|
+
|
|
|
+ 'position' => array(100,200),
|
|
|
+ 'width' => 100,
|
|
|
+ 'height' => 100,
|
|
|
+ ),
|
|
|
+ 1 => array
|
|
|
+ (
|
|
|
+ 'method' => 'txt',
|
|
|
+ 'name' => 'test文字',
|
|
|
+ 'color' => '#FF0000',
|
|
|
+ 'position' => array(100,200),
|
|
|
+ 'size' => 50,
|
|
|
+ 'angle' => 0,
|
|
|
+ 'font' => '/www/grow/config/fonts/simsun.ttc',
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ */
|
|
|
+
|
|
|
+ if (!$filename) {
|
|
|
+ $filename = Dever::id();
|
|
|
+ }
|
|
|
+ $file = Dever::pathDay('upload/poster', false) . md5($filename) . '.jpg';
|
|
|
+
|
|
|
+ if (!is_file($file) || $update == 1) {
|
|
|
+ $this->img->setType($type);
|
|
|
+ $result = $this->img->init($config['background'], $config['param'], true, $file);
|
|
|
+ if ($result) {
|
|
|
+ $file = array_pop($result);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
+ $host = str_replace(DEVER_APP_NAME . '/', '', Dever::config('host')->base);
|
|
|
+ return $host . str_replace(DEVER_PROJECT_PATH, '', $file);
|
|
|
+ $file = Dever::pic($file);
|
|
|
+ return $file;
|
|
|
+ }
|
|
|
+}
|