Skip to content

Commit

Permalink
Ver103
Browse files Browse the repository at this point in the history
Save last prompt/negative/layername setting for default value <br />
Add setting layer name function <br />
Bug fix image processing exception <br />
  • Loading branch information
Invary authored and Invary committed Oct 31, 2022
1 parent 3911864 commit ef2f99d
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 7 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ see [Documents](https://github.com/Invary/IvyPhotoshopDiffusion/tree/main/doc) p

## Changelog

- Ver103 <br />
Save last prompt/negative/layername setting for default value <br />
Add setting layer name function <br />
Bug fix image processing exception <br />


- Ver102 <br />
Support text2image. Use generate button with pressing [shift] key <br />
Change log output of generated images to InfoText only <br />
Expand Down
3 changes: 3 additions & 0 deletions src/IvyPhotoshopDiffusion/Automatic1111.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ public static JsonResponseImg2Img SendImg2Img(JsonRequestImg2Img objJson)

public static string Image2String(Image image)
{
if (image == null)
throw new Exception("unknown error image processing. Try again.");

using (MemoryStream ms = new MemoryStream())
{
image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
Expand Down
24 changes: 24 additions & 0 deletions src/IvyPhotoshopDiffusion/FormMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 39 additions & 4 deletions src/IvyPhotoshopDiffusion/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public FormMain()

textBoxPrompt.Text = XmlSetting.Current.LastPrompt;
textBoxNegativePrompt.Text = XmlSetting.Current.LastNegativePrompt;
textBoxLayerName.Text = XmlSetting.Current.LastLayerName;


labelNoiseScale100.Text = $"{(double)trackBarNoiseScale100.Value / 100:0.##}";
Expand Down Expand Up @@ -96,6 +97,7 @@ public FormMain()




buttonSelectionRestore.Enabled = false;
buttonClearMask.Enabled = false;

Expand Down Expand Up @@ -219,6 +221,10 @@ public FormMain()

FormClosing += delegate
{
XmlSetting.Current.LastPrompt = textBoxPrompt.Text;
XmlSetting.Current.LastNegativePrompt = textBoxNegativePrompt.Text;
XmlSetting.Current.LastLayerName = textBoxLayerName.Text;

XmlSetting.Current.Save();
TaskManager.AbortAll();
};
Expand Down Expand Up @@ -284,6 +290,7 @@ private void buttonGenerate_Click(object sender, EventArgs e)
request = new JsonRequestImg2Img();

int nBatchCount = 1;
string strLayerNameTemplate = "";

Invoke((MethodInvoker)delegate
{
Expand All @@ -300,6 +307,8 @@ private void buttonGenerate_Click(object sender, EventArgs e)
request.batch_size = trackBarBatchSize.Value;
nBatchCount = trackBarBatchCount.Value;

strLayerNameTemplate = textBoxLayerName.Text;

request.width = int.Parse((string)comboBoxWidth.SelectedItem);
request.height = int.Parse((string)comboBoxHeight.SelectedItem);

Expand Down Expand Up @@ -435,6 +444,26 @@ private void buttonGenerate_Click(object sender, EventArgs e)
appRef.ActiveDocument.Close();
appRef.ActiveDocument.Paste();

//set layer name
if (string.IsNullOrEmpty(strLayerNameTemplate) == false)
{
var name = strLayerNameTemplate;
//"@seed, @prompt, @negative, @cfg, @steps, @clip, @strength, @sampler, @subseed, @subseedstrength";
name = name.Replace(@"@date", $"{DateTime.Now.ToString("yyyyMMdd_HHmmss")}");
name = name.Replace(@"@seed", $"{responseObj.info.seed}");
name = name.Replace(@"@prompt", $"{responseObj.info.prompt}");
name = name.Replace(@"@negative", $"{responseObj.info.negative_prompt}");
name = name.Replace(@"@cfg", $"{responseObj.info.cfg_scale}");
name = name.Replace(@"@steps", $"{responseObj.info.steps}");
name = name.Replace(@"@clip", $"{responseObj.info.clip_skip}");
name = name.Replace(@"@strength", $"{responseObj.info.denoising_strength}");
name = name.Replace(@"@sampler", $"{responseObj.info.sampler}");
name = name.Replace(@"@subseedstrength", $"{responseObj.info.subseed_strength}");
name = name.Replace(@"@subseed", $"{responseObj.info.subseed}");
appRef.ActiveDocument.ActiveLayer.name = name;
LogMessage.WriteLine($"layer: {name}");
}

Photoshop.SetSelection(appRef, curSelection);
}
foreach (var item in responseObj.info.infotexts)
Expand All @@ -450,8 +479,11 @@ private void buttonGenerate_Click(object sender, EventArgs e)
}
catch (Exception ex)
{
LogMessage.WriteLine(ex.Message);
LogMessage.WriteLine("error: generate failed");
//this exception message is ignore, why this error???
// "General Photoshop error occurred. This functionality may not be available in this version of Photoshop."
if (ex.Message.IndexOf("This functionality may not") < 0)
LogMessage.WriteLine(ex.Message);
LogMessage.WriteLine("error: generate failed. try again");
return;
}
finally
Expand All @@ -473,8 +505,11 @@ private void buttonGenerate_Click(object sender, EventArgs e)
}
catch (Exception ex)
{
LogMessage.WriteLine(ex.Message);
LogMessage.WriteLine("error: generate failed");
//this exception message is ignore, why this error???
// "General Photoshop error occurred. This functionality may not be available in this version of Photoshop."
if (ex.Message.IndexOf("This functionality may not") < 0)
LogMessage.WriteLine(ex.Message);
LogMessage.WriteLine("error: generate failed. try again");
return;
}
}
Expand Down
20 changes: 18 additions & 2 deletions src/IvyPhotoshopDiffusion/FormMain.resx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
<data name="pictureBoxNewVersionExists.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAAH0AAAB9CAYAAACPgGwlAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAABM
4gAATOIBJ4pW6gAABylJREFUeF7tnb3O5DQUhrfmCpC4AloKtCVXQIEouQIkCmpqCgpa+pUQFV+LhKZA
4QAATOEBijN3hwAABylJREFUeF7tnb3O5DQUhrfmCpC4AloKtCVXQIEouQIkCmpqCgpa+pUQFV+LhKZA
SGgrkKChB8TH7wotFd2QN5pZRdGTOXbsGR+fz0d6mjf2sZN3nHE8SebR8XgcPDBQHMQGxUFsUBzEBsVB
bFAcxAbFQWxQHMQGxUFsUBzEBsVBbFAcxAbFQWxQtLhWUFs1+eqn5y9vQeVrcq2gtixQtKgd1MZeZOAn
Pzx744Onf73z1he/ffj6578+eeXJz4cFR+DFdpVXPdVXntofiNpBbVigaFEzKH8O393/+9JH3/79poxa
Expand Down Expand Up @@ -164,12 +164,28 @@
<data name="buttonSetting.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
wQAADsEBuJFr7QAAAUBJREFUOE+lkzFug0AQRX2DKIUrboMoaJC4BOIQqUAUcAJouQR3gM5yiTgBikQD
wAAADsABataJCQAAAUBJREFUOE+lkzFug0AQRX2DKIUrboMoaJC4BOIQqUAUcAJouQR3gM5yiTgBikQD
7XjfZgeBFUW2stI345n/P7Ozy+W4tm27GngGXwbyBHLUro5+XhQM7uu6fpvnrSgK8X3fgpicq93hOtnP
IkGhbVtJ01SmaZIkSaTrOgtictTgnEyO4jiOpaoqCcNQgiDY2ycmV5al5ZxMzI9Ha7hDQDAMwy5WaI4X
wHXb8TBgODda5C1931viOI5S17UFMTlM4MBFgxYDOyT2qW0jiKJIsiyTPM9trCZw4KJZlkWsAZNmWMSg
aRor1v+Y0In+h4tmnuffDSC/ZfDfLZyGqNNG8OoQ92PkiJTI84i/jvHDoH/lIlF7ukifeht3E9xpkX0y
LEBMjtrpFh6XmrjW3vuYdJkCJvZzZsIcEyAm52oH8eXyAJyoyKt3UO1nAAAAAElFTkSuQmCC
</value>
</data>
<data name="textBoxLayerName.ToolTip" xml:space="preserve">
<value>Layer name (optional setting)

Input layer name apply in photoshop.
The following words beginning with @ will be replaced by the value they represent
@seed, @prompt, @negative, @cfg, @steps, @strength, @sampler
@subseed, @subseedstrength, @clip, @date</value>
</data>
<data name="label9.ToolTip" xml:space="preserve">
<value>Layer name (optional setting)

Input layer name apply in photoshop.
The following words beginning with @ will be replaced by the value they represent
@seed, @prompt, @negative, @cfg, @steps, @strength, @sampler
@subseed, @subseedstrength, @clip, @date</value>
</data>
</root>
3 changes: 2 additions & 1 deletion src/IvyPhotoshopDiffusion/XmlSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class XmlSetting


[XmlIgnore]
public static int nVersion { get; } = 102;
public static int nVersion { get; } = 103;

[XmlIgnore]
public static string strVersion { get; } = $"Ver{nVersion}";
Expand Down Expand Up @@ -57,6 +57,7 @@ public class XmlSetting
public string LastPrompt { set; get; } = "";
public string LastNegativePrompt { set; get; } = "lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, \n";

public string LastLayerName { set; get; } = "@date, seed=@seed, strength=@strength, cfg=@cfg, steps=@steps, @sampler, @prompt";



Expand Down

0 comments on commit ef2f99d

Please sign in to comment.