Version 2.1.0 - (28/08/2024)

Completed support for ZEBRA PRN files, generate image and base64 for prn and image. Using URI format for base64 files
This commit is contained in:
2024-08-28 23:33:52 +02:00
parent e311b31daa
commit da112b0ff9
3 changed files with 18 additions and 11 deletions
+1 -1
View File
@@ -4,7 +4,7 @@
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor> <DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<ActiveDebugProfile>DEV_UFF</ActiveDebugProfile> <ActiveDebugProfile>DEV_HOME</ActiveDebugProfile>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor> <DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
+13 -10
View File
@@ -47,7 +47,10 @@ namespace ComicCompressor
//string progVersion = "Version 2.0.1 - (12/08/2024)"; //string progVersion = "Version 2.0.1 - (12/08/2024)";
// Added support for ZEBRA PRN files, generate image and base64 for prn and image. // Added support for ZEBRA PRN files, generate image and base64 for prn and image.
string progVersion = "Version 2.0.2 - (27/08/2024)"; //string progVersion = "Version 2.0.2 - (27/08/2024)";
// Completed support for ZEBRA PRN files, generate image and base64 for prn and image. Using URI format for base64 files
string progVersion = "Version 2.1.0 - (28/08/2024)";
public static int Main(string[] args) => CommandLineApplication.Execute<Program>(args); public static int Main(string[] args) => CommandLineApplication.Execute<Program>(args);
@@ -84,7 +87,7 @@ namespace ComicCompressor
[Option("-j|--image", Description = "process images only")] [Option("-j|--image", Description = "process images only")]
public bool DoImage { get; } = false; public bool DoImage { get; } = false;
[Option("-n|--prn", Description = "process images only")] [Option("-n|--prn", Description = "Process Zebra PRN files, generate png and webp from jpeg in base64 URI format")]
public bool DoPrn { get; } = false; public bool DoPrn { get; } = false;
[Option("-a|--copyall", Description = "copy all unprocessed files")] [Option("-a|--copyall", Description = "copy all unprocessed files")]
public bool DoCopyAll { get; } = false; public bool DoCopyAll { get; } = false;
@@ -754,9 +757,11 @@ namespace ComicCompressor
FileStream outStream = new FileStream(outputFolder, FileMode.Create); FileStream outStream = new FileStream(outputFolder, FileMode.Create);
using (Stream BitmapStream = System.IO.File.Open(imagefile, System.IO.FileMode.Open)) using (Stream BitmapStream = System.IO.File.Open(imagefile, System.IO.FileMode.Open))
{ {
// Write Webp
length_in = BitmapStream.Length; length_in = BitmapStream.Length;
Image img = Image.FromStream(BitmapStream); Image img = Image.FromStream(BitmapStream);
//Encode webp
mBitmap = new Bitmap(img); mBitmap = new Bitmap(img);
IntPtr result; IntPtr result;
@@ -766,6 +771,7 @@ namespace ComicCompressor
outStream.Flush(); outStream.Flush();
outStream.Close(); outStream.Close();
// Process images for PRN integration in Pin4ProdCrtl
if (DoPrn) if (DoPrn)
{ {
var image = Image.FromStream(BitmapStream); var image = Image.FromStream(BitmapStream);
@@ -774,6 +780,7 @@ namespace ComicCompressor
{ {
using (EncoderParameter encoderParameter = new EncoderParameter(Encoder.Quality, 33L)) using (EncoderParameter encoderParameter = new EncoderParameter(Encoder.Quality, 33L))
{ {
// Write JPEG
encParams.Param[0] = encoderParameter; encParams.Param[0] = encoderParameter;
var encoderJpeg = ImageCodecInfo.GetImageEncoders() var encoderJpeg = ImageCodecInfo.GetImageEncoders()
.First(c => c.FormatID == ImageFormat.Jpeg.Guid); .First(c => c.FormatID == ImageFormat.Jpeg.Guid);
@@ -788,6 +795,7 @@ namespace ComicCompressor
string outjpeg = outputFolder.Replace("webp", "jpeg"); string outjpeg = outputFolder.Replace("webp", "jpeg");
// Write base64 jpeg
File.WriteAllText(outjpeg + ".base64", base64String); File.WriteAllText(outjpeg + ".base64", base64String);
FileStream outStreamjpeg = new FileStream(outjpeg, FileMode.Create); FileStream outStreamjpeg = new FileStream(outjpeg, FileMode.Create);
@@ -805,31 +813,26 @@ namespace ComicCompressor
#if true #if true
using (MemoryStream m = new MemoryStream()) using (MemoryStream m = new MemoryStream())
{ {
// Write base64 webp
encoder.Encode(mBitmap, m, 70); encoder.Encode(mBitmap, m, 70);
byte[] imageBytes = m.ToArray(); byte[] imageBytes = m.ToArray();
string base64String = Convert.ToBase64String(imageBytes); string base64String = Convert.ToBase64String(imageBytes);
base64String = "data:image/webp;base64," + base64String; base64String = "data:image/webp;base64," + base64String;
File.WriteAllText(outputFolder + ".base64", base64String); File.WriteAllText(outputFolder + ".base64", base64String);
// regen image from base64 as debug
//byte[] imageBytes_o = Convert.FromBase64String(base64String); //byte[] imageBytes_o = Convert.FromBase64String(base64String);
//using (MemoryStream ms = new MemoryStream(imageBytes_o)) //using (MemoryStream ms = new MemoryStream(imageBytes_o))
//{ //{
// // Create image from memory stream // // Create image from memory stream
// using (FileStream file = new FileStream(outputFolder + ".base64.webp", FileMode.Create, System.IO.FileAccess.Write)) // using (FileStream file = new FileStream(outputFolder + ".base64.webp", FileMode.Create, System.IO.FileAccess.Write))
// { // {
// ms.WriteTo(file); // ms.WriteTo(file);
// } // }
//} //}
} }
#endif #endif
} }
//encoder.Encode(mBitmap, 70, out result, out length);
//UnmanagedMemoryStream ustream = new UnmanagedMemoryStream((byte*)result, length);
//ustream.CopyTo(outStream);
//ustream.Close();
//outStrea.Close();
} }
FileInfo finfo = new FileInfo(outputFolder); FileInfo finfo = new FileInfo(outputFolder);
+4
View File
@@ -27,6 +27,10 @@
"DEV_UFF": { "DEV_UFF": {
"commandName": "Project", "commandName": "Project",
"commandLineArgs": "-i \"E:\\SynologyDrive\\SynologyDrive\\A\\_PRINT_TEMPLATES_\\DEV_IN\" -o \"E:\\SynologyDrive\\SynologyDrive\\A\\_PRINT_TEMPLATES_\\DEV_OUT\" -r -s -j -a -n" "commandLineArgs": "-i \"E:\\SynologyDrive\\SynologyDrive\\A\\_PRINT_TEMPLATES_\\DEV_IN\" -o \"E:\\SynologyDrive\\SynologyDrive\\A\\_PRINT_TEMPLATES_\\DEV_OUT\" -r -s -j -a -n"
},
"DEV_HOME": {
"commandName": "Project",
"commandLineArgs": "-i \"D:\\SynologyDrive\\A\\_PRINT_TEMPLATES_\\DEV_IN\" -o \"D:\\SynologyDrive\\A\\_PRINT_TEMPLATES_\\DEV_OUT\" -r -s -j -a -n"
} }
} }
} }