Expose PNG metadata in pano cli
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "assets/image_format.h"
|
||||
#include "assets/image_metadata.h"
|
||||
#include "assets/ppi_header.h"
|
||||
#include "document/document.h"
|
||||
#include "foundation/parse.h"
|
||||
@@ -9,6 +10,7 @@
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
@@ -166,9 +168,33 @@ int inspect_image(int argc, char** argv)
|
||||
return 2;
|
||||
}
|
||||
|
||||
pp::foundation::Result<pp::assets::ImageMetadata> metadata =
|
||||
pp::foundation::Result<pp::assets::ImageMetadata>::failure(
|
||||
pp::foundation::Status::invalid_argument("image metadata is unavailable"));
|
||||
if (format.value() == pp::assets::ImageFormat::png) {
|
||||
metadata = pp::assets::parse_png_metadata(std::span<const std::byte>(data, chars.size()));
|
||||
if (!metadata) {
|
||||
print_error("inspect-image", metadata.status().message);
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "{\"ok\":true,\"command\":\"inspect-image\",\"format\":\""
|
||||
<< pp::assets::image_format_name(format.value())
|
||||
<< "\",\"bytes\":" << chars.size() << "}\n";
|
||||
<< "\",\"bytes\":" << chars.size();
|
||||
|
||||
if (metadata) {
|
||||
std::cout << ",\"metadata\":{\"width\":" << metadata.value().width
|
||||
<< ",\"height\":" << metadata.value().height
|
||||
<< ",\"bitDepth\":" << static_cast<int>(metadata.value().bit_depth)
|
||||
<< ",\"components\":" << static_cast<int>(metadata.value().components)
|
||||
<< ",\"colorType\":\"" << pp::assets::image_color_type_name(metadata.value().color_type)
|
||||
<< "\"}";
|
||||
} else {
|
||||
std::cout << ",\"metadata\":null";
|
||||
}
|
||||
|
||||
std::cout << "}\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user