@@ -34,7 +34,7 @@ void sanityCheck(const string& inputFilename) {
3434 * @param options
3535 * @return
3636 */
37- int convert (const string& inputFilename, const string& outputFilename, Opts& options)
37+ int convert (const string& inputFilename, Opts& options)
3838{
3939 sanityCheck (inputFilename);
4040
@@ -87,7 +87,12 @@ int convert(const string& inputFilename, const string& outputFilename, Opts& opt
8787 image = createVipsThumbnail (image, options);
8888 }
8989
90- saveImage (image, outputFilename, options);
90+ if (!options.outputPath .empty ()) {
91+ saveOutputImageToFile (image, options);
92+ }
93+ else {
94+ printOutputImageToStdout (image, options);
95+ }
9196
9297 vips_shutdown ();
9398
@@ -98,6 +103,8 @@ Opts getTifigOptions(cxxopts::Options& options)
98103{
99104 Opts opts = {};
100105
106+ if (options.count (" output" ))
107+ opts.outputPath = options[" output" ].as <string>();
101108 if (options.count (" width" ))
102109 opts.width = options[" width" ].as <int >();
103110 if (options.count (" height" ))
@@ -110,7 +117,7 @@ Opts getTifigOptions(cxxopts::Options& options)
110117 opts.parallel = true ;
111118 if (options.count (" thumbnail" ))
112119 opts.thumbnail = true ;
113- if (options.count (" verbose" ))
120+ if (options.count (" verbose" ) && !opts. outputPath . empty () )
114121 opts.verbose = true ;
115122
116123 return opts;
@@ -132,7 +139,7 @@ int main(int argc, char* argv[])
132139
133140 cxxopts::Options options (argv[0 ], " Converts iOS 11 HEIC images to practical formats" );
134141
135- options.positional_help (" input_file output_file" );
142+ options.positional_help (" input_file [ output_file] " );
136143
137144 options.parse_positional (vector<string>{" input" , " output" });
138145
@@ -155,15 +162,14 @@ int main(int argc, char* argv[])
155162 if (options.count (" version" )) {
156163 printVersion ();
157164 retval = 0 ;
158- } else if (options.count (" input" ) && options. count ( " output " ) ) {
165+ } else if (options.count (" input" )) {
159166 string inputFileName = options[" input" ].as <string>();
160- string outputFileName = options[" output" ].as <string>();
161167
162168 Opts tifigOptions = getTifigOptions (options);
163169
164170 chrono::steady_clock::time_point begin = chrono::steady_clock::now ();
165171
166- retval = convert (inputFileName, outputFileName, tifigOptions);
172+ retval = convert (inputFileName, tifigOptions);
167173
168174 chrono::steady_clock::time_point end = chrono::steady_clock::now ();
169175 long duration = chrono::duration_cast<chrono::milliseconds>(end - begin).count ();
@@ -172,11 +178,11 @@ int main(int argc, char* argv[])
172178 cout << " Total Time: " << duration << " ms" << endl;
173179 }
174180 } else {
175- cout << options.help () << endl;
181+ cerr << options.help () << endl;
176182 }
177183 }
178184 catch (const cxxopts::OptionException& oe) {
179- cout << " error parsing options: " << oe.what () << endl;
185+ cerr << " error parsing options: " << oe.what () << endl;
180186 }
181187 catch (const FileReaderException& fre) {
182188 cerr << " Could not read HEIF image: " << fre.what () << endl;
0 commit comments