Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Text2Image/T2IParamSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using SwarmUI.Accounts;
using SwarmUI.Core;
using SwarmUI.Utils;
using System.IO;

namespace SwarmUI.Text2Image;

Expand Down Expand Up @@ -153,6 +154,10 @@ Image imageFor(string val)
{
return Image.FromDataString(val);
}
if (File.Exists(val))
{
return Image.FromFilePath(val);
}
return new Image(val, Image.ImageType.IMAGE, "png");
}
object obj = param.Type switch
Expand Down
8 changes: 4 additions & 4 deletions src/Text2Image/T2IParamTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -994,10 +994,10 @@ public static string ValidateParam(T2IParamType type, string val, Session sessio
{
return "";
}
if (!ValidBase64Matcher.IsOnlyMatches(val) || val.Length < 10)
if ((!ValidBase64Matcher.IsOnlyMatches(val) || val.Length < 10) && !File.Exists(val))
{
string shortText = val.Length > 10 ? val[..10] + "..." : val;
throw new SwarmUserErrorException($"Invalid image value for param {type.Name} - '{origVal}' - must be a valid base64 string - got '{shortText}'");
throw new SwarmUserErrorException($"Invalid image value for param {type.Name} - '{origVal}' - must be a valid base64 string or file path - got '{shortText}'");
}
return origVal;
case T2IParamDataType.IMAGE_LIST:
Expand All @@ -1012,10 +1012,10 @@ public static string ValidateParam(T2IParamType type, string val, Session sessio
{
continue;
}
if (!ValidBase64Matcher.IsOnlyMatches(partVal) || partVal.Length < 10)
if ((!ValidBase64Matcher.IsOnlyMatches(partVal) || partVal.Length < 10) && !File.Exists(partVal))
{
string shortText = partVal.Length > 10 ? partVal[..10] + "..." : partVal;
throw new SwarmUserErrorException($"Invalid image-list value for param {type.Name} - '{origVal}' - must be a valid base64 string - got '{shortText}'");
throw new SwarmUserErrorException($"Invalid image-list value for param {type.Name} - '{origVal}' - must be a valid base64 string or file path - got '{shortText}'");
}
}
return origVal;
Expand Down
6 changes: 6 additions & 0 deletions src/Utils/Image.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ public static Image FromDataString(string data)
return new Image(data.ToString().After(";base64,"), ImageType.IMAGE, "png");
}

/// <summary>Creates an image object from a local file path</summary>
public static Image FromFilePath(string path)
{
return new Image(ISImage.Load(path));
}

/// <summary>Construct an image from Base64 text.</summary>
public Image(string base64, ImageType type, string extension) : this(Convert.FromBase64String(base64), type, extension)
{
Expand Down