12#include <boost/gil.hpp>
13#include <boost/gil/extension/io/jpeg.hpp>
14#include <boost/gil/extension/io/png.hpp>
15#include <boost/gil/extension/numeric/sampler.hpp>
16#include <boost/gil/extension/numeric/resample.hpp>
37namespace fs = std::filesystem;
39ENUM(ImageFormat, JPG, PNG);
56 , fs::path
const& path_file_dst
60 namespace gil = boost::gil;
63 logger(
"I::Reading image {}", path_file_src);
64 return_if(not Try(fs::is_regular_file(path_file_src))
65 , Error(
"E::File '{}' does not exist or is not a regular file", path_file_src)
69 std::string ext = Try(path_file_src.extension().string());
70 std::ranges::transform(ext, ext.begin(), [](
unsigned char c){ return static_cast<char>(std::tolower(c)); });
72 ImageFormat format = Pop(
75 Error(
"E::Input image of invalid format: '{}'", ext)
79 gil::rgba8_image_t img;
80 if (format == ImageFormat::JPG)
82 Try(gil::read_and_convert_image(path_file_src, img, gil::jpeg_tag()));
84 else if (format == ImageFormat::PNG)
86 Try(gil::read_and_convert_image(path_file_src, img, gil::png_tag()));
88 logger(
"I::Image size is {}x{}", std::to_string(img.width()), std::to_string(img.height()));
89 logger(
"I::Saving image to {}", path_file_dst);
94 .with_args(path_file_src)
95 .with_args(
"-resize", (img.width() > img.height())? std::format(
"{}x", width) : std::format(
"x{}", height))
116 , fs::path
const& path_file_dst
120 return resize_impl(path_file_src, path_file_dst, width, height);
std::unique_ptr< Child > spawn()
Spawns (forks) the child process and begins execution.
Subprocess & with_args(Args &&... args)
Arguments forwarded as the process' arguments.
Custom enumeration class.
A library for manipulating environment variables.
A library for file logging.
#define logger(fmt,...)
Compile-time log level dispatch macro with automatic location capture.
Value< fs::path > search_path(std::string const &query)
Search the directories in the PATH variable for the given input file name.
Value< void > resize_impl(fs::path const &path_file_src, fs::path const &path_file_dst, uint32_t width, uint32_t height)
Internal implementation for resizing an image.
Image processing utilities.
Value< void > resize(fs::path const &path_file_src, fs::path const &path_file_dst, uint32_t width, uint32_t height)
Resizes an input image to the specified width and height.
Enhanced expected type with integrated logging capabilities.
A library to spawn sub-processes in linux.