15 #include "imageResize.h"
16 #include "string_utils.h"
26 set_program_brief(
"resize an image file");
27 set_program_description
28 (
"This program reads an image file and resizes it to a larger or smaller "
33 "Specify the width of the output image in pixels, or as a percentage "
34 "of the original width (if a trailing percent sign is included). "
35 "If this is omitted, the ratio is taken from the ysize parameter.",
36 &ImageResize::dispatch_size_request, NULL, &_x_size);
40 "Specify the height of the output image in pixels, or as a percentage "
41 "of the original height (if a trailing percent sign is included). "
42 "If this is omitted, the ratio is taken from the xsize parameter.",
43 &ImageResize::dispatch_size_request, NULL, &_y_size);
47 "Use Gaussian filtering to resize the image, with the indicated radius.",
48 &ImageResize::dispatch_double, &_use_gaussian_filter, &_filter_radius);
52 "This option is ignored. It is provided only for backward compatibility "
53 "with a previous version of image-resize.",
54 &ImageResize::dispatch_none, NULL, NULL);
66 if (_x_size.get_type() == RT_none && _y_size.get_type() == RT_none) {
67 _x_size.set_ratio(1.0);
68 _y_size.set_ratio(1.0);
69 }
else if (_x_size.get_type() == RT_none) {
70 _x_size.set_ratio(_y_size.get_ratio(_image.get_y_size()));
71 }
else if (_y_size.get_type() == RT_none) {
72 _y_size.set_ratio(_x_size.get_ratio(_image.get_x_size()));
75 int x_size = _x_size.get_pixel_size(_image.get_x_size());
76 int y_size = _y_size.get_pixel_size(_image.get_y_size());
78 nout <<
"Resizing to " << x_size <<
" x " << y_size <<
"\n";
80 _image.get_num_channels(),
81 _image.get_maxval(), _image.get_type());
83 if (_use_gaussian_filter) {
86 new_image.quick_filter_from(_image);
98 dispatch_size_request(
const string &opt,
const string &arg,
void *var) {
99 SizeRequest *ip = (SizeRequest *)var;
100 if (!arg.empty() && arg[arg.length() - 1] ==
'%') {
102 string str = arg.substr(0, arg.length() - 1);
104 if (!string_to_double(str, ratio)) {
105 nout <<
"Invalid ratio for -" << opt <<
": "
109 ip->set_ratio(ratio / 100.0);
114 if (!string_to_int(arg, pixel_size)) {
115 nout <<
"Invalid pixel size for -" << opt <<
": "
119 ip->set_pixel_size(pixel_size);
126 int main(
int argc,
char *argv[]) {
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_...
This is the base class for a program that reads an image file, operates on it, and writes another ima...
void gaussian_filter_from(float radius, const PNMImage ©)
Makes a resized copy of the indicated image into this one using the indicated filter.
void write_image()
Writes the generated to the user's specified output filename.
A program to read an image file and resize it to a larger or smaller image file.