Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
meibuyu-rpc
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
without authentication
meibuyu-rpc
Commits
aa87ce2b
Commit
aa87ce2b
authored
Apr 17, 2020
by
王源
🎧
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加自动生成头像方法
parent
ab4574f9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
0 deletions
+42
-0
UploadManager.php
src/Manager/UploadManager.php
+42
-0
No files found.
src/Manager/UploadManager.php
View file @
aa87ce2b
...
...
@@ -92,6 +92,48 @@ class UploadManager
}
}
/**
* 生成头像
* @return string|string[]
*/
public
static
function
createAvatar
()
{
$img
=
imagecreatetruecolor
(
180
,
180
);
$bgColor
=
imagecolorallocate
(
$img
,
240
,
240
,
240
);
imagefill
(
$img
,
0
,
0
,
$bgColor
);
$color
=
imagecolorallocate
(
$img
,
rand
(
90
,
230
),
rand
(
90
,
230
),
rand
(
90
,
230
));
for
(
$i
=
0
;
$i
<
90
;
$i
++
)
{
for
(
$y
=
0
;
$y
<
180
;
$y
++
)
{
$ad
=
rand
(
10
,
50
);
//随机
if
(
$ad
%
3
==
0
)
{
for
(
$xx
=
$i
;
$xx
<
$i
+
15
;
$xx
++
)
{
for
(
$yy
=
$y
;
$yy
<
$y
+
30
;
$yy
++
)
{
imagesetpixel
(
$img
,
$xx
,
$yy
,
$color
);
}
}
$is
=
((
90
-
$i
)
+
90
)
-
15
;
//计算偏移
for
(
$xx
=
$is
;
$xx
<
$is
+
15
;
$xx
++
)
{
for
(
$yy
=
$y
;
$yy
<
$y
+
30
;
$yy
++
)
{
imagesetpixel
(
$img
,
$xx
,
$yy
,
$color
);
}
}
}
$y
+=
14
;
}
$i
+=
14
;
}
$path
=
self
::
$pathPrefix
.
'avatar/default/'
;
if
(
!
is_dir
(
$path
))
{
mkdir
(
$path
,
0777
,
true
);
}
$fileName
=
$path
.
date
(
'YmdHis'
)
.
uniqid
()
.
'.png'
;
imagepng
(
$img
,
$fileName
);
imagedestroy
(
$img
);
//释放内存
return
str_replace
(
'public/'
,
''
,
$fileName
);
}
/**
* 处理保存路径
* @param $options
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment