16using namespace Magick;
18static void Usage (
char **argv )
20 cout <<
"Usage: " << argv[0]
21 <<
" [-density resolution] [-filter algorithm] [-geometry geometry]"
22 <<
" [-resample resolution] input_file output_file" << endl
23 <<
" algorithm - bessel blackman box catrom cubic gaussian hamming hanning" << endl
24 <<
" hermite lanczos mitchell point quadratic sample scale sinc triangle" << endl;
28static void ParseError (
int position,
char **argv)
30 cout <<
"Argument \"" << argv[position] <<
"\" at position" << position
31 <<
"incorrect" << endl;
35int main(
int argc,
char **argv)
38 InitializeMagick(*argv);
54 Magick::FilterTypes filter(LanczosFilter);
55 ResizeAlgorithm resize_algorithm=Zoom;
58 while ((argv_index < argc - 2) && (*argv[argv_index] ==
'-'))
60 std::string command(argv[argv_index]);
61 if (command.compare(
"-density") == 0)
69 ParseError(argv_index,argv);
74 else if (command.compare(
"-filter") == 0)
77 std::string algorithm(argv[argv_index]);
78 if (algorithm.compare(
"point") == 0)
80 else if (algorithm.compare(
"box") == 0)
82 else if (algorithm.compare(
"triangle") == 0)
83 filter=TriangleFilter;
84 else if (algorithm.compare(
"hermite") == 0)
86 else if (algorithm.compare(
"hanning") == 0)
88 else if (algorithm.compare(
"hamming") == 0)
90 else if (algorithm.compare(
"blackman") == 0)
91 filter=BlackmanFilter;
92 else if (algorithm.compare(
"gaussian") == 0)
93 filter=GaussianFilter;
94 else if (algorithm.compare(
"quadratic") == 0)
95 filter=QuadraticFilter;
96 else if (algorithm.compare(
"cubic") == 0)
98 else if (algorithm.compare(
"catrom") == 0)
100 else if (algorithm.compare(
"mitchell") == 0)
101 filter=MitchellFilter;
102 else if (algorithm.compare(
"lanczos") == 0)
103 filter=LanczosFilter;
104 else if (algorithm.compare(
"bessel") == 0)
106 else if (algorithm.compare(
"sinc") == 0)
108 else if (algorithm.compare(
"sample") == 0)
109 resize_algorithm=Sample;
110 else if (algorithm.compare(
"scale") == 0)
111 resize_algorithm=Scale;
113 ParseError(argv_index,argv);
117 else if (command.compare(
"-geometry") == 0)
121 geometry=
Geometry(argv[argv_index]);
125 ParseError(argv_index,argv);
130 else if (command.compare(
"-resample") == 0)
134 resample=
Geometry(argv[argv_index]);
138 ParseError(argv_index,argv);
143 ParseError(argv_index,argv);
146 if (argv_index>argc-1)
147 ParseError(argv_index,argv);
148 std::string input_file(argv[argv_index]);
151 ParseError(argv_index,argv);
152 std::string output_file(argv[argv_index]);
155 Image image(input_file);
156 if (density.isValid())
157 image.density(density);
158 density=image.density();
160 if (resample.isValid())
164 (image.columns()*((
double)resample.width()/density.width())+0.5),
166 (image.rows()*((
double)resample.height()/density.height())+0.5));
167 image.density(resample);
169 switch (resize_algorithm)
172 image.sample(geometry);
175 image.scale(geometry);
178 image.filterType(filter);
179 image.zoom(geometry);
182 image.write(output_file);
184 catch( exception &error_ )
186 cout <<
"Caught exception: " << error_.what() << endl;