forked from mtusi2026/mtusi2026lab5
lab5
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
#include "image_pipeline.hpp"
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc != 3) return 2;
|
||||
try {
|
||||
std::ifstream input(argv[1], std::ios::binary);
|
||||
if (!input) return 1;
|
||||
const std::vector<std::uint8_t> bytes((std::istreambuf_iterator<char>(input)), {});
|
||||
const auto variants = make_variants(bytes);
|
||||
std::filesystem::create_directories(argv[2]);
|
||||
nlohmann::json manifest;
|
||||
for (const auto& v : variants) {
|
||||
const auto path = std::filesystem::path(argv[2]) /
|
||||
(v.name + (v.content_type == "image/webp" ? ".webp" : ".jpg"));
|
||||
std::ofstream out(path, std::ios::binary);
|
||||
out.write(v.image.bytes.data(), v.image.bytes.size());
|
||||
if (!out) return 1;
|
||||
manifest[v.name] = {{"width", v.image.width}, {"height", v.image.height},
|
||||
{"size_bytes", v.image.bytes.size()}};
|
||||
}
|
||||
std::cout << manifest.dump() << '\n';
|
||||
return 0;
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << e.what() << '\n';
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user