19using namespace Magick;
21static void Usage (
char **argv )
23 cout <<
"Usage: " << argv[0]
24 <<
" [-density resolution] [-filter algorithm] [-geometry geometry]"
25 <<
" [-resample resolution] input_file output_file" << endl
26 <<
" algorithm - bessel blackman box catrom cubic gaussian hamming hanning" << endl
27 <<
" hermite lanczos mitchell point quadratic sample scale sinc triangle" << endl;
31static void ParseError (
int position,
char **argv)
33 cout <<
"Argument \"" << argv[position] <<
"\" at position" << position
34 <<
"incorrect" << endl;
38int main(
int argc,
char **argv)
55 Magick::FilterType filter(LanczosFilter);
58 ResizeAlgorithm resize_algorithm=Zoom;
61 while ((argv_index < argc - 2) && (*argv[argv_index] ==
'-'))
63 std::string command(argv[argv_index]);
64 if (command.compare(
"-density") == 0)
72 ParseError(argv_index,argv);
77 else if (command.compare(
"-filter") == 0)
80 std::string algorithm(argv[argv_index]);
81 if (algorithm.compare(
"point") == 0)
83 else if (algorithm.compare(
"box") == 0)
85 else if (algorithm.compare(
"triangle") == 0)
86 filter=TriangleFilter;
87 else if (algorithm.compare(
"hermite") == 0)
89 else if (algorithm.compare(
"hanning") == 0)
91 else if (algorithm.compare(
"hamming") == 0)
93 else if (algorithm.compare(
"blackman") == 0)
94 filter=BlackmanFilter;
95 else if (algorithm.compare(
"gaussian") == 0)
96 filter=GaussianFilter;
97 else if (algorithm.compare(
"quadratic") == 0)
98 filter=QuadraticFilter;
99 else if (algorithm.compare(
"cubic") == 0)
101 else if (algorithm.compare(
"catrom") == 0)
103 else if (algorithm.compare(
"mitchell") == 0)
104 filter=MitchellFilter;
105 else if (algorithm.compare(
"lanczos") == 0)
106 filter=LanczosFilter;
107 else if (algorithm.compare(
"bessel") == 0)
109 else if (algorithm.compare(
"sinc") == 0)
111 else if (algorithm.compare(
"sample") == 0)
112 resize_algorithm=Sample;
113 else if (algorithm.compare(
"scale") == 0)
114 resize_algorithm=Scale;
116 ParseError(argv_index,argv);
120 else if (command.compare(
"-geometry") == 0)
124 geometry=
Geometry(argv[argv_index]);
128 ParseError(argv_index,argv);
133 else if (command.compare(
"-resample") == 0)
137 resample=
Geometry(argv[argv_index]);
141 ParseError(argv_index,argv);
146 ParseError(argv_index,argv);
149 if (argv_index>argc-1)
150 ParseError(argv_index,argv);
151 std::string input_file(argv[argv_index]);
154 ParseError(argv_index,argv);
155 std::string output_file(argv[argv_index]);
158 Image image(input_file);
159 if (density.isValid())
160 image.density(density);
161 density=image.density();
163 if (resample.isValid())
167 (image.columns()*((
double)resample.x()/density.x())+0.5),
169 (image.rows()*((
double)resample.y()/density.y())+0.5));
170 image.density(resample);
172 switch (resize_algorithm)
175 image.sample(geometry);
178 image.scale(geometry);
181 image.filterType(filter);
182 image.zoom(geometry);
185 image.write(output_file);
187 catch( exception &error_ )
189 cout <<
"Caught exception: " << error_.what() << endl;