Avatar restored
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 39 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.0 KiB |
@ -1,6 +1,5 @@
|
||||
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNetCore.Html;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
@ -9,6 +8,8 @@ using Yavsc.Models;
|
||||
using Yavsc.Models.FileSystem;
|
||||
using Yavsc.Models.Streaming;
|
||||
using Yavsc.ViewModels;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
|
||||
namespace Yavsc.Helpers
|
||||
{
|
||||
@ -28,43 +29,12 @@ namespace Yavsc.Helpers
|
||||
|
||||
using (var org = formFile.OpenReadStream())
|
||||
{
|
||||
Image i = Image.FromStream(org);
|
||||
using (Bitmap source = new Bitmap(i))
|
||||
{
|
||||
source.Save(destFileName, ImageFormat.Png);
|
||||
}
|
||||
using Image image = Image.Load(org);
|
||||
image.Save(destFileName);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create avatars
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="source"></param>
|
||||
private static void CreateAvatars(this ApplicationUser user, Bitmap source)
|
||||
{
|
||||
var dir = Config.SiteSetup.Avatars;
|
||||
var name = user.UserName + ".png";
|
||||
var smallname = user.UserName + ".s.png";
|
||||
var xsmallname = user.UserName + ".xs.png";
|
||||
using (Bitmap newBMP = new Bitmap(source, 128, 128))
|
||||
{
|
||||
newBMP.Save(Path.Combine(
|
||||
dir, name), ImageFormat.Png);
|
||||
}
|
||||
using (Bitmap newBMP = new Bitmap(source, 64, 64))
|
||||
{
|
||||
newBMP.Save(Path.Combine(
|
||||
dir, smallname), ImageFormat.Png);
|
||||
}
|
||||
using (Bitmap newBMP = new Bitmap(source, 32, 32))
|
||||
{
|
||||
newBMP.Save(Path.Combine(
|
||||
dir, xsmallname), ImageFormat.Png);
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetAvatarUri(this ApplicationUser user)
|
||||
{
|
||||
return $"/{Config.SiteSetup.Avatars}/{user.UserName}.png";
|
||||
@ -257,42 +227,15 @@ namespace Yavsc.Helpers
|
||||
{
|
||||
FileName = user.UserName + ".png"
|
||||
};
|
||||
|
||||
var destFileName = Path.Combine(Config.SiteSetup.Avatars, item.FileName);
|
||||
|
||||
var fi = new FileInfo(destFileName);
|
||||
if (fi.Exists) item.Overriden = true;
|
||||
Rectangle cropRect = new Rectangle();
|
||||
|
||||
using (var org = formFile.OpenReadStream())
|
||||
{
|
||||
Image i = Image.FromStream(org);
|
||||
using (Bitmap source = new Bitmap(i))
|
||||
{
|
||||
if (i.Width != i.Height)
|
||||
{
|
||||
if (i.Width > i.Height)
|
||||
{
|
||||
cropRect.X = (i.Width - i.Height) / 2;
|
||||
cropRect.Y = 0;
|
||||
cropRect.Width = i.Height;
|
||||
cropRect.Height = i.Height;
|
||||
}
|
||||
else
|
||||
{
|
||||
cropRect.X = 0;
|
||||
cropRect.Y = (i.Height - i.Width) / 2;
|
||||
cropRect.Width = i.Width;
|
||||
cropRect.Height = i.Width;
|
||||
}
|
||||
using (var cropped = source.Clone(cropRect, source.PixelFormat))
|
||||
{
|
||||
CreateAvatars(user,cropped);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
using Image image = Image.Load(org);
|
||||
image.Mutate(x=>x.Resize(128,128));
|
||||
image.Save(Path.Combine(Config.SiteSetup.Avatars,item.FileName));
|
||||
image.Mutate(x=>x.Resize(64,64));
|
||||
image.Save(Path.Combine(Config.SiteSetup.Avatars,user.UserName + ".s.png"));
|
||||
image.Mutate(x=>x.Resize(32,32));
|
||||
image.Save(Path.Combine(Config.SiteSetup.Avatars,user.UserName + ".xs.png"));
|
||||
}
|
||||
item.DestDir = Config.AvatarsOptions.RequestPath.ToUriComponent();
|
||||
user.Avatar = $"{item.DestDir}/{item.FileName}";
|
||||
|
@ -69,10 +69,6 @@
|
||||
@Model.Logins.Count [<a asp-controller="Manage" asp-action="ManageLogins">Manage</a>]
|
||||
</dd>
|
||||
|
||||
<dt>Full name:</dt>
|
||||
<dd>@Model.FullName [<a asp-controller="Manage" asp-action="SetFullName"
|
||||
>@Model.FullName==null?"Set":"Modify"</a>]</dd>
|
||||
|
||||
<dt>Address:</dt>
|
||||
<dd>@Model.PostalAddress
|
||||
[<a asp-controller="Manage" asp-action="SetAddress"
|
||||
|
@ -1,13 +1,13 @@
|
||||
@model PerformerProfile
|
||||
@{ ViewData["Title"] = "Edit your avatar"; }
|
||||
@section header{
|
||||
<link href="~/css/main/dropzone.css" rel="stylesheet">
|
||||
<script src="https://unpkg.com/dropzone@5/dist/min/dropzone.min.js"></script>
|
||||
<link rel="stylesheet" href="https://unpkg.com/dropzone@5/dist/min/dropzone.min.css" type="text/css" />
|
||||
}
|
||||
@section scripts{
|
||||
<script src="~/js/dropzone.js"></script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
Dropzone.options.postavatar= {
|
||||
Dropzone.options.postavatar = {
|
||||
maxFilesize: 2, // MB (an avatar)
|
||||
autoProcessQueue: true,
|
||||
accept: function(file, done) {
|
||||
@ -23,10 +23,10 @@ $(document).ready(function() {
|
||||
}
|
||||
<img src="~/avatars/@(User.Identity.Name).png">
|
||||
|
||||
<form id="postavatar" class="dropzone" method="post" enctype="multipart/form-data">
|
||||
<form id="postavatar" action="/api/setavatar" class="dropzone" method="post" enctype="multipart/form-data">
|
||||
<div class="fallback">
|
||||
<input name="Avatar" type="file" id="Avatar" />
|
||||
</div>
|
||||
(IconWebUploadSpecification"])
|
||||
@Html.AntiForgeryToken()
|
||||
|
||||
</form>
|
||||
|
@ -43,6 +43,8 @@
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.2" IncludeAssets="All" />
|
||||
<PackageReference Include="AsciiDocNet" Version="1.0.0" />
|
||||
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.6" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../Yavsc.Server/Yavsc.Server.csproj" />
|
||||
|
1126
src/Yavsc/wwwroot/images/it/sofwarelibre.svg
Normal file
After Width: | Height: | Size: 48 KiB |