22 set_program_brief(
"resize an image file");
23 set_program_description
24 (
"This program reads an image file and resizes it to a larger or smaller "
29 "Specify the width of the output image in pixels, or as a percentage "
30 "of the original width (if a trailing percent sign is included). "
31 "If this is omitted, the ratio is taken from the ysize parameter.",
32 &ImageResize::dispatch_size_request,
nullptr, &_x_size);
36 "Specify the height of the output image in pixels, or as a percentage "
37 "of the original height (if a trailing percent sign is included). "
38 "If this is omitted, the ratio is taken from the xsize parameter.",
39 &ImageResize::dispatch_size_request,
nullptr, &_y_size);
43 "Use Gaussian filtering to resize the image, with the indicated radius.",
44 &ImageResize::dispatch_double, &_use_gaussian_filter, &_filter_radius);
48 "This option is ignored. It is provided only for backward compatibility "
49 "with a previous version of image-resize.",
50 &ImageResize::dispatch_none,
nullptr,
nullptr);
60 if (_x_size.get_type() == RT_none && _y_size.get_type() == RT_none) {
61 _x_size.set_ratio(1.0);
62 _y_size.set_ratio(1.0);
63 }
else if (_x_size.get_type() == RT_none) {
64 _x_size.set_ratio(_y_size.get_ratio(_image.get_y_size()));
65 }
else if (_y_size.get_type() == RT_none) {
66 _y_size.set_ratio(_x_size.get_ratio(_image.get_x_size()));
69 int x_size = _x_size.get_pixel_size(_image.get_x_size());
70 int y_size = _y_size.get_pixel_size(_image.get_y_size());
72 nout <<
"Resizing to " << x_size <<
" x " << y_size <<
"\n";
74 _image.get_num_channels(),
75 _image.get_maxval(), _image.get_type());
77 if (_use_gaussian_filter) {
78 new_image.gaussian_filter_from(_filter_radius, _image);
80 new_image.quick_filter_from(_image);
90 dispatch_size_request(
const std::string &opt,
const std::string &arg,
void *var) {
91 SizeRequest *ip = (SizeRequest *)var;
92 if (!arg.empty() && arg[arg.length() - 1] ==
'%') {
94 std::string str = arg.substr(0, arg.length() - 1);
97 nout <<
"Invalid ratio for -" << opt <<
": "
101 ip->set_ratio(ratio / 100.0);
107 nout <<
"Invalid pixel size for -" << opt <<
": "
111 ip->set_pixel_size(pixel_size);
118 int main(
int argc,
char *argv[]) {
This is the base class for a program that reads an image file, operates on it, and writes another ima...
A program to read an image file and resize it to a larger or smaller image file.
void write_image()
Writes the generated to the user's specified output filename.
The name of this class derives from the fact that we originally implemented it as a layer on top of t...
virtual void parse_command_line(int argc, char **argv)
Dispatches on each of the options on the command line, and passes the remaining parameters to handle_...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
double string_to_double(const string &str, string &tail)
A string-interface wrapper around the C library strtol().
int string_to_int(const string &str, string &tail)
A string-interface wrapper around the C library strtol().
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.