| xqd
@@ -32,12 +32,15 @@ if (! function_exists('getUrlImage')) {
|
|
|
/**
|
|
|
* Get the image in the url.
|
|
|
*
|
|
|
- * @param string $img
|
|
|
+ * @param string $url
|
|
|
* @param string $filename
|
|
|
* @return string|boolean
|
|
|
*/
|
|
|
function getUrlImage($url, $filename)
|
|
|
{
|
|
|
+ if (file_exists($filename)) {
|
|
|
+ unlink($filename);
|
|
|
+ }
|
|
|
if (empty($url) || empty($filename)) {
|
|
|
return false;
|
|
|
}
|
| xqd
@@ -53,6 +56,54 @@ if (! function_exists('getUrlImage')) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+if (! function_exists('imageToCircle')) {
|
|
|
+ /**
|
|
|
+ * Change the image to the circle.
|
|
|
+ *
|
|
|
+ * @param string $url
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ function imageToCircle($url)
|
|
|
+ {
|
|
|
+ $ext = pathinfo($url);
|
|
|
+ $src_img = null;
|
|
|
+ switch ($ext['extension']) {
|
|
|
+ case 'jpg':
|
|
|
+ $src_img = imagecreatefromjpeg($url);
|
|
|
+ break;
|
|
|
+ case 'png':
|
|
|
+ $src_img = imagecreatefrompng($url);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ $wh = getimagesize($url);
|
|
|
+ $w = $wh[0];
|
|
|
+ $h = $wh[1];
|
|
|
+ $w = min($w, $h);
|
|
|
+ $h = $w;
|
|
|
+ $img = imagecreatetruecolor($w, $h);
|
|
|
+ //这一句一定要有
|
|
|
+ imagesavealpha($img, true);
|
|
|
+ //拾取一个完全透明的颜色,最后一个参数127为全透明
|
|
|
+ $bg = imagecolorallocatealpha($img, 255, 255, 255, 127);
|
|
|
+ imagefill($img, 0, 0, $bg);
|
|
|
+ $r = $w / 2; //圆半径
|
|
|
+ $y_x = $r; //圆心X坐标
|
|
|
+ $y_y = $r; //圆心Y坐标
|
|
|
+ for ($x = 0; $x < $w; $x++) {
|
|
|
+ for ($y = 0; $y < $h; $y++) {
|
|
|
+ $rgbColor = imagecolorat($src_img, $x, $y);
|
|
|
+ if (((($x - $r) * ($x - $r) + ($y - $r) * ($y - $r)) < ($r * $r))) {
|
|
|
+ imagesetpixel($img, $x, $y, $rgbColor);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $img;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
if( ! function_exists('array_to_sort')) {
|
|
|
/**
|
|
|
* 对二维数组排序
|