// using ExCSS;
using NetCorePpt;
using static NetCorePptxTest.Modules.Constants;
namespace NetCorePptxTest.Modules;
public class DemoImage
{
///
/// SLIDE 1:
///
///
public static void genSlide01(PptxGen pptx, bool addSvg)
{
var slide = pptx.addSlide(new AddSlideProps { sectionTitle = "Images" });
slide.addTable(new List { new TableRow {
new TableCell { text = "Image Examples: Image Types", options = Constants.BASE_TEXT_OPTS_L },
Constants.BASE_TEXT_OPTS_R }
},
Constants.BASE_TABLE_OPTS);
slide.addNotes("API Docs: https://gitbrent.github.io/PptxGenJS/docs/api-images.html");
slide.slideNumber = new SlideNumberProps { x = "50%", y = "95%", color =Constants.COLOR_BLUE };
// TOP
{
// TOP = 1
slide.addText("Type: GIF (animated)", new TextPropsOptions
{
x = 0.5,
y = 0.6,
w = 2.75,
h = 2.5,
margin = 4,
fill = (Constants.BKGD_LTGRAY),
fontSize = 12,
fontFace = "Segoe UI",
color = Constants.COLOR_BLUE,
valign = VAlign.top,
align = HAlign.center,
});
slide.addImage(new ImageProps { x = 1.13, y = 1.1, w = 1.5, h = 1.5, path = Constants.IMAGE_PATHS.gifAnimTrippy.path, objectName = "animated gif" });
slide.addText("(legacy PPT only animates in slide show)", new TextPropsOptions
{
x = 0.5,
y = 2.79,
w = 2.75,
h = 0.3,
align = HAlign.center,
fontSize = 10,
color = "BF9000",
fill = "FFFCCC",
});
// TOP = 2
slide.addText("Type: GIF", new TextPropsOptions
{
x = 3.7,
y = 0.6,
w = 2.75,
h = 2.5,
margin = 4,
fill = (Constants.BKGD_LTGRAY),
fontSize = 12,
fontFace = "Segoe UI",
color = Constants.COLOR_BLUE,
valign = VAlign.top,
align = HAlign.center,
});
slide.addImage(new ImageProps { x = 4.16, y = 1.1, w = 1.88, h = 1.5, path = Constants.IMAGE_PATHS.ccDjGif.path, altText = "this is a gif" });
// TOP = 3
slide.addText("Type: PNG (base64)", new TextPropsOptions
{
x = 6.9,
y = 0.6,
w = 2.75,
h = 2.5,
margin = 4,
fill = (Constants.BKGD_LTGRAY),
fontSize = 12,
fontFace = "Segoe UI",
color = Constants.COLOR_BLUE,
valign = VAlign.top,
align = HAlign.center,
});
slide.addImage(new ImageProps { x = 7.53, y = 1.1, w = 1.5, h = 1.5, data = Constants.UNITE_PNG });
// TOP = 4
slide.addText("Hyperlink Image", new TextPropsOptions
{
x = 10.1,
y = 0.6,
w = 2.75,
h = 2.5,
margin = 4,
fill = (Constants.BKGD_LTGRAY),
fontSize = 12,
fontFace = "Segoe UI",
color = Constants.COLOR_BLUE,
valign = VAlign.top,
align = HAlign.center,
});
slide.addImage(new ImageProps
{
x = 10.8,
y = 1.1,
w = 1.36,
h = 1.5,
data = Constants.HYPERLINK_SVG,
hyperlink = new HyperlinkProps("https://github.com/gitbrent/pptxgenjs", "Visit Homepage"),
});
}
// BTM
{
// BOTTOM-LEFT =
slide.addText("Type: JPG", new TextPropsOptions
{
x = 0.5,
y = 3.5,
w = 3.5,
h = 3.5,
margin = 4,
fill = (Constants.BKGD_LTGRAY),
fontSize = 12,
fontFace = "Segoe UI",
color = Constants.COLOR_BLUE,
valign = VAlign.top,
align = HAlign.center,
});
// slide.AddImage(new ImageProps { path = Constants.IMAGE_PATHS.ccCopyRemix.path, x = 0.77, y = 3.8, w = 2.97, h = 2.9 });
slide.addImage(new ImageProps { data = Constants.FEDIVERSE_TREE, x = 0.72, y = 3.81, w = 3.06, h = 3.06 });
// BOTTOM-CENTER =
// peace image via = https = //www.vecteezy.com/vector-art/242684-peace-vector-design
slide.addText("Type: PNG", new TextPropsOptions
{
x = 4.93,
y = 3.5,
w = 3.5,
h = 3.5,
margin = 4,
fill = (Constants.BKGD_LTGRAY),
fontSize = 12,
fontFace = "Segoe UI",
color = Constants.COLOR_BLUE,
valign = VAlign.top,
align = HAlign.center,
});
slide.addImage(new ImageProps { path = Constants.IMAGE_PATHS.peace4.path, x = 5.2, y = 3.81, w = 3.0, h = 3.0 });
// BOTTOM-RIGHT =
slide.addText("Type: SVG", new TextPropsOptions
{
x = 9.33,
y = 3.5,
w = 3.5,
h = 3.5,
margin = 4,
fill = (Constants.BKGD_LTGRAY),
fontSize = 12,
fontFace = "Segoe UI",
color = Constants.COLOR_BLUE,
valign = VAlign.top,
align = HAlign.center,
});
if (addSvg)
{
slide.addImage(new ImageProps { path = Constants.IMAGE_PATHS.pixelfed_logo_svg.path, x = 9.25, y = 3.43, w = 2.33, h = 2.33 }); // TEST = @"path@"
slide.addImage(new ImageProps { data = Constants.SVG_MASTODON_LOGO_BASE64, x = 10.61, y = 4.77, w = 2.0, h = 2.0, transparency = 50 }); // TEST = @"data@"
}
}
// TEST = Ensure framework corrects for missing all header
// (Please **DO NOT** pass base64 data without the header! This is a JUNK TEST!)
//slide.addImage(new ImageProps { x = 5.2, y = 2.6, w = 0.8, h = 0.8, data = 'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAA3NCSVQICAjb4U/gAAAACXBIWXMAAAjcAAAI3AGf6F88AAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAANVQTFRF////JLaSIJ+AIKqKKa2FKLCIJq+IJa6HJa6JJa6IJa6IJa2IJa6IJa6IJa6IJa6IJa6IJa6IJq6IKK+JKK+KKrCLLrGNL7KOMrOPNrSRN7WSPLeVQrmYRLmZSrycTr2eUb6gUb+gWsKlY8Wqbsmwb8mwdcy0d8y1e863g9G7hdK8htK9i9TAjNTAjtXBktfEntvKoNzLquDRruHTtePWt+TYv+fcx+rhyOvh0e7m1e/o2fHq4PTu5PXx5vbx7Pj18fr49fv59/z7+Pz7+f38/P79/f7+dNHCUgAAABF0Uk5TAAcIGBktSYSXmMHI2uPy8/XVqDFbAAABB0lEQVQ4y42T13qDMAyFZUKMbebp3mmbrnTvlY60TXn/R+oFGAyYzz1Xx/wylmWJqBLjUkVpGinJGXXliwSVEuG3sBdkaCgLPJMPQnQUDmo+jGFRPKz2WzkQl//wQvQoLPII0KuAiMjP+gMyn4iEFU1eAQCCiCU2fpCfFBVjxG18f35VOk7Swndmt9pKUl2++fG4qL2iqMPXpi8r1SKitDDne/rT8vPbRh2d6oC7n6PCLNx/bsEM0Edc5DdLAHD9tWueF9VJjmdP68DZ77iRkDKuuT19Hx3mx82MpVmo1Yfv+WXrSrxZ6slpiyes77FKif88t7Nh3C3nbFp327sHxz167uHtH/8/eds7gGsUQbkAAAAASUVORK5CYII=' });
// NEGATIVE-TEST =
//slide.addImage(new ImageProps { data = 'https = //raw.githubusercontent.com/gitbrent/PptxGenJS/v2.1.0/examples/images/doh_this_isnt_base64_data.gif', x = 0.5, y = 0.5, w = 1.0, h = 1.0 });
}
///
/// SLIDE 4 = Image URLs
///
///
public static void genSlide02(PptxGen pptx)
{
var slide = pptx.addSlide(new AddSlideProps { sectionTitle = "Images" });
bool onlyImage2 = false;
if (!onlyImage2)
{
slide.addTable(new List {
new TableRow {
new TableCell { text = "Image Examples: Image URLs", options = Constants.BASE_TEXT_OPTS_L },Constants.BASE_TEXT_OPTS_R}},
Constants.BASE_TABLE_OPTS);
slide.addNotes("API Docs: https://gitbrent.github.io/PptxGenJS/docs/api-images.html");
slide.slideNumber = new SlideNumberProps { x = "50%", y = "95%", color = Constants.COLOR_BLUE };
}
if (!onlyImage2)
{
// TOP-LEFT = jpg
slide.addImage(new ImageProps { path = Constants.IMAGE_PATHS.ccLogo.path, x = 0.5, y = 0.6, h = 2.68, w = 3.58 });
}
var textOption = Constants.MergeTextOption(Constants.BASE_CODE_OPTS,
new TextPropsOptions { x = 0.5, y = 3.28, h = 0.7, w = 3.58 },
Constants.CODE_STYLE);
slide.addText(new List { new TextProps { text = @$"path:""{Constants.IMAGE_PATHS.ccLogo.path}""" } }, textOption);
if (!onlyImage2)
{
// TOP-CENTER = png
slide.addImage(new ImageProps { path = Constants.IMAGE_PATHS.wikimedia2.path, x = 4.6, y = 0.6, h = 2.64, w = 3.45 });
var textOption1 = Constants.MergeTextOption(Constants.BASE_CODE_OPTS,
new TextPropsOptions { x = 4.6, y = 3.24, h = 0.7, w = 3.45 },
Constants.CODE_STYLE);
slide.addText(new List { new TextProps { text = @$"path:""{Constants.IMAGE_PATHS.wikimedia2.path}""" } }, textOption1);
}
// TOP-RIGHT = relative-path test
// NOTE = Node will throw exception when using "/" path
// FIXME =
if (!onlyImage2)
{
Console.WriteLine(@$"{Constants.IMAGE_PATHS.ccLicenseComp.path}@");
// WIP = ^^^
slide.addImage(new ImageProps {
path = @$"{Constants.IMAGE_PATHS.ccLicenseComp.path}",
x = 8.57,
y = 0.6,
h = 2.52,
w = 4.26
});
var textOption2 = Constants.MergeTextOption(Constants.BASE_CODE_OPTS,
new TextPropsOptions { x = 8.57, y = 3.12, h = 0.82, w = 4.26 },
Constants.CODE_STYLE);
slide.addText(
new List {
new TextProps { text = "// Example: local path", options = new TextPropsOptions { breakLine = true } },
new TextProps { text = @$"path:""{Constants.IMAGE_PATHS.ccLicenseComp.path}"""}
}, textOption2);
// BOTTOM = wide, url-sourced
slide.addImage(new ImageProps { path = Constants.IMAGE_PATHS.sydneyBridge.path, x = 0.5, y = 4.35, h = 1.8, w = 12.33 });
var textOption3 = Constants.MergeTextOption(Constants.BASE_CODE_OPTS,
new TextPropsOptions { x = 0.5, y = 6.15, h = 0.8, w = 12.33 },
Constants.CODE_STYLE);
slide.addText(
new List {
new TextProps { text = "// Example: URL variables, plus more than one \".jpg\"", options = new TextPropsOptions { breakLine = true } },
new TextProps { text = @$"path:""{Constants.IMAGE_PATHS.sydneyBridge.path}""" }
}, textOption3);
}
}
///
/// SLIDE 2: Image sizing
///
///
public static void genSlide03(PptxGen pptx)
{
var slide = pptx.addSlide(new AddSlideProps { sectionTitle = "Images" });
slide.addTable(new List
{
new TableRow {
new TableCell { text = "Image Examples: Image Sizing/Rounding", options = Constants.BASE_TEXT_OPTS_L },
Constants.BASE_TEXT_OPTS_R } }
, Constants.BASE_TABLE_OPTS);
slide.addNotes("API Docs: https://gitbrent.github.io/PptxGenJS/docs/api-images.html");
slide.slideNumber = new SlideNumberProps { x = "50%", y = "95%", w = 1, h = 1, color = Constants.COLOR_BLUE };
// TOP = 1
slide.addText("Sizing: Orig `w:5, h:2.8`", new TextPropsOptions { x = 0.5, y = 0.6, w = 3.0, h = 0.3, color = Constants.COLOR_BLUE });
slide.addImage(new ImageProps { data = Constants.KRITA_SPLASHSCREEN, x = 0.6, y = 1.1, w = 5.0, h = 2.84 });
// TOP = 2
slide.addText("Sizing: `contain, w:3`", new TextPropsOptions { x = 0.6, y = 4.25, w = 3.0, h = 0.3, color = Constants.COLOR_BLUE });
slide.addShape(ShapeType.rect, new ShapeProps { x = 0.6, y = 4.65, w = 3, h = 2, fill = (Constants.BKGD_LRGRAY) });
slide.addImage(new ImageProps
{
data = Constants.KRITA_SPLASHSCREEN,
x = 0.6,
y = 4.65,
w = 5.0,
h = 1.5,
sizing = new ImageSizingProps(ImageSizingType.contain, 3, 2)
});
// TOP = 3
slide.addText("Sizing: `cover, w:3, h:2`", new TextPropsOptions { x = 5.3, y = 4.25, w = 3.0, h = 0.3, color = Constants.COLOR_BLUE });
slide.addShape(ShapeType.rect, new ShapeProps { x = 5.3, y = 4.65, w = 3, h = 2, fill = (Constants.BKGD_LRGRAY) });
slide.addImage(new ImageProps
{
data = Constants.KRITA_SPLASHSCREEN, x = 5.3, y = 4.65, w = 3.0, h = 1.5,
sizing = new ImageSizingProps(ImageSizingType.cover, 3, 2)
});
// TOP = 4
slide.addText("Sizing: `crop, w:3, h:2`", new TextPropsOptions { x = 10.0, y = 4.25, w = 3.0, h = 0.3, color = Constants.COLOR_BLUE });
slide.addShape(ShapeType.rect, new ShapeProps { x = 10, y = 4.65, w = 3, h = 1.5, fill = (Constants.BKGD_LRGRAY) });
slide.addImage(new ImageProps
{
data = Constants.KRITA_SPLASHSCREEN, x = 10.0, y = 4.65, w = 5.0, h = 1.5,
sizing = new ImageSizingProps(ImageSizingType.crop, 3, 1.5, 0.5, 0.5)
});
// TOP-RIGHT =
slide.addText("Rounding: `rounding:true`", new TextPropsOptions { x = 7, y = 0.6, w = 3.0, h = 0.3, color = Constants.COLOR_BLUE });
slide.addShape(ShapeType.rect, new ShapeProps { x = 7, y = 1.0, w = 6.0, h = 3.0, fill = (BKGD_LRGRAY) });
slide.addImage(new ImageProps { path = IMAGE_PATHS.kritaSquare.path, x = 7.42, y = 1.28, w = 2.5, h = 2.5, rounding = false });
slide.addImage(new ImageProps { path = IMAGE_PATHS.kritaSquare.path, x = 10.25, y = 1.28, w = 2.5, h = 2.5, rounding = true });
}
///
/// SLIDE 3 = Image Rotation
///
///
public static void genSlide04(PptxGen pptx)
{
var slide = pptx.addSlide(new AddSlideProps { sectionTitle = "Images" });
bool onlyImage = false;
if (!onlyImage)
{
slide.addTable(new List {
new TableRow {
new TableCell { text = "Image Examples: Image Rotation", options = Constants.BASE_TEXT_OPTS_L },
Constants.BASE_TEXT_OPTS_R
}},
Constants.BASE_TABLE_OPTS);
slide.addNotes("API Docs: https://gitbrent.github.io/PptxGenJS/docs/api-images.html");
slide.slideNumber = new SlideNumberProps { x = "50%", y = "95%", w = 1, h = 1, color = Constants.COLOR_BLUE };
}
if (!onlyImage)
{
var textOption = Constants.MergeTextOption(new TextPropsOptions { x = 0.50, y = 0.6, h = 0.4, w = 4.0 }, Constants.TITLE_STYLE);
// EXAMPLES
slide.addText("`rotate:45` ", textOption);
var textOption1 = Constants.MergeTextOption(new TextPropsOptions { x = 4.66, y = 0.6, h = 0.4, w = 4.0 }, Constants.TITLE_STYLE);
slide.addText("`rotate:180`", textOption1);
var textOption2 = Constants.MergeTextOption(new TextPropsOptions { x = 8.82, y = 0.6, h = 0.4, w = 4.0 }, Constants.TITLE_STYLE);
slide.addText("`rotate:315`", textOption2);
}
slide.addImage(new ImageProps { path= IMAGE_PATHS.nycSubway.path, x= 0.78, y= 2.46, w= 4.5, h= 3, rotate= 45 });
slide.addImage(new ImageProps { path = IMAGE_PATHS.nycSubway.path, x= 4.42, y= 2.25, w= 4.5, h= 3, rotate= 180 });
slide.addImage(new ImageProps { path = IMAGE_PATHS.nycSubway.path, x= 8.25, y= 2.84, w= 4.5, h= 3, rotate= 315 });
}
///
/// SLIDE 5 = Image shadow
///
///
public static void genSlide05(PptxGen pptx)
{
var slide = pptx.addSlide(new AddSlideProps { sectionTitle = "Images" });
slide.addTable(new List { new TableRow {
new TableCell { text = "Image Examples: Image Shadows", options = Constants.BASE_TEXT_OPTS_L },
Constants.BASE_TEXT_OPTS_R }
}, Constants.BASE_TABLE_OPTS);
slide.addNotes("API Docs: https://gitbrent.github.io/PptxGenJS/docs/api-images.html");
slide.slideNumber = new SlideNumberProps { x = "50%", y = "95%", w = 1, h = 1, color =Constants.COLOR_BLUE };
// type = none
ImageProps shadow1 = new ImageProps { shadow = new ShadowProps { type = ShadowType.none } };
var textOption = Constants.MergeTextOption(new TextPropsOptions { x = 0.5, y = 0.6, h = 0.4, w = 6.0 }, Constants.TITLE_STYLE);
slide.addText("Shadow: `type:none`", textOption);
textOption = Constants.MergeTextOption(Constants.BASE_CODE_OPTS,
new TextPropsOptions { x = 0.5, y = 1.0, h = 1.0, w = 6 },
Constants.CODE_STYLE);
slide.addText( new List { new TextProps { text = Constants.ToJson(shadow1).ToLower() } }, textOption );
var imageProp = Constants.MergeImage(
new ImageProps { path = Constants.IMAGE_PATHS.nycSubway.path, x = 7.0, y = 0.6, h = 1.4, w = 2.11 },
shadow1);
slide.addImage(imageProp);
// type = inner
ImageProps shadow2 = new ImageProps { shadow = new ShadowProps { type = ShadowType.inner, opacity = 0.5, blur = 20, color = "000000", offset = 20, angle = 320 } };
var textOption2_1 = Constants.MergeTextOption(new TextPropsOptions { x = 0.5, y = 2.45, h = 0.4, w = 6.0 }, Constants.TITLE_STYLE);
slide.addText("Shadow: `type:inner`", textOption2_1);
var textOption2_2 = Constants.MergeTextOption(Constants.BASE_CODE_OPTS,
new TextPropsOptions { x = 0.5, y = 2.85, h = 1.7, w = 6 },
Constants.CODE_STYLE);
var text2_json = Constants.ToJson(shadow2); // 对对象的序列化后和 JS 不同;
text2_json = Constants.ToJson(new { shadow = new { type = "inner", opacity = 0.5, blur = 20, color = "000000", offset = 20, angle = 320 } });
Console.WriteLine(text2_json);
slide.addText(new List { new TextProps { text = text2_json } }, textOption2_2);
var imageProps2 = Constants.MergeImage(
new ImageProps { path = Constants.IMAGE_PATHS.nycSubway.path, x = 7.0, y = 2.45, h = 2.1, w = 3.13 },
shadow2);
slide.addImage(imageProps2);
// type = outer
var textOption3_1 = Constants.MergeTextOption(new TextPropsOptions { x = 0.5, y = 5.0, h = 0.4, w = 6.0 }, Constants.TITLE_STYLE);
slide.addText("Shadow: `type:outer`", textOption3_1);
ImageProps shadow3 = new ImageProps { shadow = new ShadowProps { type = ShadowType.outer, opacity = 0.35, blur = 20, color = "000000", offset = 20, angle = 320 } };
var textOption3_2 = Constants.MergeTextOption(Constants.BASE_CODE_OPTS,
new TextPropsOptions { x = 0.5, y = 5.4, h = 1.7, w = 6 },
Constants.CODE_STYLE);
var text3_json = Constants.ToJson(shadow3); // 对对象的序列化后和 JS 不同;
text3_json = Constants.ToJson(new { shadow = new { type = "outer", opacity = 0.35, blur = 20, color = "000000", offset = 20, angle = 320 } });
Console.WriteLine(text3_json);
slide.addText(new List { new TextProps { text = text3_json } }, textOption3_2);
var imageProps3 = Constants.MergeImage(
new ImageProps { path = Constants.IMAGE_PATHS.nycSubway.path, x = 7.0, y = 5.0, h = 2.1, w = 3.13 }, shadow3);
slide.addImage(imageProps3);
}
}