Optional width and height parameters for thumbnailer This is to generate custom sized images from SVGs, defaults will still work the same as before. Diffs= 434223338 Optional width and height parameters for thumbnailer
diff --git a/.rive_head b/.rive_head index f2f0e15..b77e8cb 100644 --- a/.rive_head +++ b/.rive_head
@@ -1 +1 @@ -a1d921c85a7c4057dbebf972939e188a3d515c86 +4342233383156cba2154ad05b74157b139dc8bfc
diff --git a/skia/thumbnail_generator/src/main.cpp b/skia/thumbnail_generator/src/main.cpp index cfc4eb5..f804338 100644 --- a/skia/thumbnail_generator/src/main.cpp +++ b/skia/thumbnail_generator/src/main.cpp
@@ -9,6 +9,8 @@ #include <cstdio> #include <stdio.h> #include <string> +#include <iostream> +#include <sstream> std::string getFileName(char* path) { std::string str(path); @@ -18,6 +20,19 @@ return str.substr(from + 1, to - from - 1); } +const int DEFAULT_SIZE = 256; + +int getArg(char* arg) { + std::istringstream ss(arg); + int x; + if (!(ss >> x)) { + std::cerr << "Invalid number: " << arg << '\n'; + } else if (!ss.eof()) { + std::cerr << "Trailing chars after number: " << arg << '\n'; + } + return x == 0 ? DEFAULT_SIZE : x; +} + int main(int argc, char* argv[]) { rive::SkiaFactory factory; @@ -38,6 +53,12 @@ outPath = fullName.c_str(); } + int width = DEFAULT_SIZE, height = DEFAULT_SIZE; + if (argc == 5) { + width = getArg(argv[3]); + height = getArg(argv[4]); + } + if (fp == nullptr) { fprintf(stderr, "Failed to open rive file.\n"); return 1; @@ -61,8 +82,6 @@ auto artboard = file->artboardDefault(); artboard->advance(0.0f); - int width = 256, height = 256; - sk_sp<SkSurface> rasterSurface = SkSurface::MakeRasterN32Premul(width, height); SkCanvas* rasterCanvas = rasterSurface->getCanvas();