mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-19 06:43:51 +02:00
Crop print border on upload
This commit is contained in:
@@ -204,13 +204,9 @@ namespace VRCX
|
||||
var ms = new MemoryStream(bytes);
|
||||
var print = await Image.LoadAsync(ms);
|
||||
// validation step to ensure image is actually a print
|
||||
if (print.Width != 2048 || print.Height != 1440)
|
||||
if (!CropPrint(ref print))
|
||||
return false;
|
||||
|
||||
var point = new Point(64, 69);
|
||||
var size = new Size(1920, 1080);
|
||||
var rectangle = new Rectangle(point, size);
|
||||
print.Mutate(x => x.Crop(rectangle));
|
||||
|
||||
await print.SaveAsPngAsync(tempPath);
|
||||
if (ScreenshotHelper.HasTXt(path))
|
||||
ScreenshotHelper.CopyTXt(path, tempPath);
|
||||
@@ -218,6 +214,18 @@ namespace VRCX
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CropPrint(ref Image image)
|
||||
{
|
||||
if (image.Width != 2048 || image.Height != 1440)
|
||||
return false;
|
||||
|
||||
var point = new Point(64, 69);
|
||||
var size = new Size(1920, 1080);
|
||||
var rectangle = new Rectangle(point, size);
|
||||
image.Mutate(x => x.Crop(rectangle));
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<string> SavePrintToFile(string url, string ugcFolderPath, string monthFolder, string fileName)
|
||||
{
|
||||
var folder = Path.Join(GetUGCPhotoLocation(ugcFolderPath), "Prints", MakeValidFileName(monthFolder));
|
||||
|
||||
@@ -11,6 +11,7 @@ using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Cookie = System.Net.Cookie;
|
||||
using NLog;
|
||||
using SixLabors.ImageSharp;
|
||||
using Timer = System.Threading.Timer;
|
||||
|
||||
#if !LINUX
|
||||
@@ -342,6 +343,19 @@ namespace VRCX
|
||||
|
||||
private static async Task PrintImageUpload(HttpWebRequest request, IDictionary<string, object> options)
|
||||
{
|
||||
if (options.TryGetValue("cropWhiteBorder", out var cropWhiteBorder) && (bool)cropWhiteBorder)
|
||||
{
|
||||
var oldImageData = options["imageData"] as string;
|
||||
var ms = new MemoryStream(Convert.FromBase64String(oldImageData));
|
||||
var print = await Image.LoadAsync(ms);
|
||||
if (Program.AppApiInstance.CropPrint(ref print))
|
||||
{
|
||||
var ms2 = new MemoryStream();
|
||||
await print.SaveAsPngAsync(ms2);
|
||||
options["imageData"] = Convert.ToBase64String(ms2.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
if (ProxySet)
|
||||
request.Proxy = Proxy;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user