Added JPEG compression
Added URI header before BASE64 images
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
|
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<ActiveDebugProfile>PROD</ActiveDebugProfile>
|
<ActiveDebugProfile>DEV_UFF</ActiveDebugProfile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||||
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
|
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
|
||||||
|
|||||||
+50
-10
@@ -370,10 +370,11 @@ namespace ComicCompressor
|
|||||||
{
|
{
|
||||||
byte[] img = drawer.Draw(labelInfo.ZplElements);
|
byte[] img = drawer.Draw(labelInfo.ZplElements);
|
||||||
outputPath = Path.Join(OutputFolder, Path.ChangeExtension(relativePath, ".prn.png"));
|
outputPath = Path.Join(OutputFolder, Path.ChangeExtension(relativePath, ".prn.png"));
|
||||||
|
Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
|
||||||
File.WriteAllBytes(outputPath, img);
|
File.WriteAllBytes(outputPath, img);
|
||||||
//imageData is bytes of png image
|
//imageData is bytes of png image
|
||||||
string base64String = Convert.ToBase64String(img);
|
string base64String = Convert.ToBase64String(img);
|
||||||
|
base64String = "data:image/png;base64," + base64String;
|
||||||
File.WriteAllText(outputPath + ".base64", base64String);
|
File.WriteAllText(outputPath + ".base64", base64String);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -732,6 +733,8 @@ namespace ComicCompressor
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region COMPRESS_IMAGE
|
#region COMPRESS_IMAGE
|
||||||
|
|
||||||
|
|
||||||
public void CompressImage(string imagefile, string outputFolder, int max_name_len = -1, Boolean isPar = false, string print_line_header = "")
|
public void CompressImage(string imagefile, string outputFolder, int max_name_len = -1, Boolean isPar = false, string print_line_header = "")
|
||||||
{
|
{
|
||||||
string name_print = imagefile;
|
string name_print = imagefile;
|
||||||
@@ -765,25 +768,62 @@ namespace ComicCompressor
|
|||||||
|
|
||||||
if (DoPrn)
|
if (DoPrn)
|
||||||
{
|
{
|
||||||
|
var image = Image.FromStream(BitmapStream);
|
||||||
|
|
||||||
|
using (EncoderParameters encParams = new EncoderParameters(1))
|
||||||
|
{
|
||||||
|
using (EncoderParameter encoderParameter = new EncoderParameter(Encoder.Quality, 33L))
|
||||||
|
{
|
||||||
|
encParams.Param[0] = encoderParameter;
|
||||||
|
var encoderJpeg = ImageCodecInfo.GetImageEncoders()
|
||||||
|
.First(c => c.FormatID == ImageFormat.Jpeg.Guid);
|
||||||
|
|
||||||
|
var stream = new MemoryStream();
|
||||||
|
// image.Save(stream, ImageFormat.Jpeg);
|
||||||
|
image.Save(stream, encoderJpeg, encParams);
|
||||||
|
|
||||||
|
byte[] imageBytes = stream.ToArray();
|
||||||
|
string base64String = Convert.ToBase64String(imageBytes);
|
||||||
|
base64String = "data:image/jpeg;base64," + base64String;
|
||||||
|
|
||||||
|
string outjpeg = outputFolder.Replace("webp", "jpeg");
|
||||||
|
|
||||||
|
File.WriteAllText(outjpeg + ".base64", base64String);
|
||||||
|
|
||||||
|
FileStream outStreamjpeg = new FileStream(outjpeg, FileMode.Create);
|
||||||
|
stream.Position = 0;
|
||||||
|
stream.CopyTo(outStreamjpeg);
|
||||||
|
outStreamjpeg.Flush();
|
||||||
|
outStreamjpeg.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if true
|
||||||
using (MemoryStream m = new MemoryStream())
|
using (MemoryStream m = new MemoryStream())
|
||||||
{
|
{
|
||||||
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;
|
||||||
|
|
||||||
File.WriteAllText(outputFolder + ".base64", base64String);
|
File.WriteAllText(outputFolder + ".base64", base64String);
|
||||||
|
|
||||||
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
|
||||||
}
|
}
|
||||||
//encoder.Encode(mBitmap, 70, out result, out length);
|
//encoder.Encode(mBitmap, 70, out result, out length);
|
||||||
//UnmanagedMemoryStream ustream = new UnmanagedMemoryStream((byte*)result, length);
|
//UnmanagedMemoryStream ustream = new UnmanagedMemoryStream((byte*)result, length);
|
||||||
|
|||||||
@@ -23,6 +23,10 @@
|
|||||||
"PROD": {
|
"PROD": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"commandLineArgs": "-i \"K:\\_RPG_\\__THE_AMBER_ROOM_UPDATE\\__ASSETS__\\_IMG_\" -o \"K:\\_RPG_\\__THE_AMBER_ROOM_UPDATE\\__ASSETS__\\_IMG_WEBP_\" -r -s -j -a"
|
"commandLineArgs": "-i \"K:\\_RPG_\\__THE_AMBER_ROOM_UPDATE\\__ASSETS__\\_IMG_\" -o \"K:\\_RPG_\\__THE_AMBER_ROOM_UPDATE\\__ASSETS__\\_IMG_WEBP_\" -r -s -j -a"
|
||||||
|
},
|
||||||
|
"DEV_UFF": {
|
||||||
|
"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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user