| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | #include "wand/studio.h" |
|---|
| 49 | #include "wand/MagickWand.h" |
|---|
| 50 | #include "wand/mogrify-private.h" |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | static MagickBooleanType ConjureUsage(void) |
|---|
| 91 | { |
|---|
| 92 | const char |
|---|
| 93 | **p; |
|---|
| 94 | |
|---|
| 95 | static const char |
|---|
| 96 | *miscellaneous[]= |
|---|
| 97 | { |
|---|
| 98 | "-debug events display copious debugging information", |
|---|
| 99 | "-help print program options", |
|---|
| 100 | "-list type print a list of supported option arguments", |
|---|
| 101 | "-log format format of debugging information", |
|---|
| 102 | "-version print version information", |
|---|
| 103 | (char *) NULL |
|---|
| 104 | }, |
|---|
| 105 | *settings[]= |
|---|
| 106 | { |
|---|
| 107 | "-monitor monitor progress", |
|---|
| 108 | "-quiet suppress all warning messages", |
|---|
| 109 | "-regard-warnings pay attention to warning messages", |
|---|
| 110 | "-seed value seed a new sequence of pseudo-random numbers", |
|---|
| 111 | "-verbose print detailed information about the image", |
|---|
| 112 | (char *) NULL |
|---|
| 113 | }; |
|---|
| 114 | |
|---|
| 115 | (void) printf("Version: %s\n",GetMagickVersion((unsigned long *) NULL)); |
|---|
| 116 | (void) printf("Copyright: %s\n",GetMagickCopyright()); |
|---|
| 117 | (void) printf("Features: %s\n\n",GetMagickFeatures()); |
|---|
| 118 | (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n", |
|---|
| 119 | GetClientName()); |
|---|
| 120 | (void) printf("\nImage Settings:\n"); |
|---|
| 121 | for (p=settings; *p != (char *) NULL; p++) |
|---|
| 122 | (void) printf(" %s\n",*p); |
|---|
| 123 | (void) printf("\nMiscellaneous Options:\n"); |
|---|
| 124 | for (p=miscellaneous; *p != (char *) NULL; p++) |
|---|
| 125 | (void) printf(" %s\n",*p); |
|---|
| 126 | (void) printf("\nIn additiion, define any key value pairs required by " |
|---|
| 127 | "your script. For\nexample,\n\n"); |
|---|
| 128 | (void) printf(" conjure -size 100x100 -color blue -foo bar script.msl\n"); |
|---|
| 129 | return(MagickFalse); |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | WandExport MagickBooleanType ConjureImageCommand(ImageInfo *image_info, |
|---|
| 133 | int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception) |
|---|
| 134 | { |
|---|
| 135 | #define DestroyConjure() \ |
|---|
| 136 | { \ |
|---|
| 137 | image=DestroyImageList(image); \ |
|---|
| 138 | for (i=0; i < (long) argc; i++) \ |
|---|
| 139 | argv[i]=DestroyString(argv[i]); \ |
|---|
| 140 | argv=(char **) RelinquishMagickMemory(argv); \ |
|---|
| 141 | } |
|---|
| 142 | #define ThrowConjureException(asperity,tag,option) \ |
|---|
| 143 | { \ |
|---|
| 144 | (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \ |
|---|
| 145 | option); \ |
|---|
| 146 | DestroyConjure(); \ |
|---|
| 147 | return(MagickFalse); \ |
|---|
| 148 | } |
|---|
| 149 | #define ThrowConjureInvalidArgumentException(option,argument) \ |
|---|
| 150 | { \ |
|---|
| 151 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \ |
|---|
| 152 | "InvalidArgument","`%s': %s",option,argument); \ |
|---|
| 153 | DestroyConjure(); \ |
|---|
| 154 | return(MagickFalse); \ |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | char |
|---|
| 158 | *option; |
|---|
| 159 | |
|---|
| 160 | Image |
|---|
| 161 | *image; |
|---|
| 162 | |
|---|
| 163 | long |
|---|
| 164 | number_images; |
|---|
| 165 | |
|---|
| 166 | MagickStatusType |
|---|
| 167 | status; |
|---|
| 168 | |
|---|
| 169 | register long |
|---|
| 170 | i; |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | assert(image_info != (ImageInfo *) NULL); |
|---|
| 176 | assert(image_info->signature == MagickSignature); |
|---|
| 177 | if (image_info->debug != MagickFalse) |
|---|
| 178 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
|---|
| 179 | assert(exception != (ExceptionInfo *) NULL); |
|---|
| 180 | if (argc < 2) |
|---|
| 181 | { |
|---|
| 182 | (void) ConjureUsage(); |
|---|
| 183 | return(MagickTrue); |
|---|
| 184 | } |
|---|
| 185 | image=NewImageList(); |
|---|
| 186 | number_images=0; |
|---|
| 187 | option=(char *) NULL; |
|---|
| 188 | (void) respect_parenthesis; |
|---|
| 189 | |
|---|
| 190 | |
|---|
| 191 | |
|---|
| 192 | ReadCommandlLine(argc,&argv); |
|---|
| 193 | status=ExpandFilenames(&argc,&argv); |
|---|
| 194 | if (status == MagickFalse) |
|---|
| 195 | ThrowConjureException(ResourceLimitError,"MemoryAllocationFailed", |
|---|
| 196 | GetExceptionMessage(errno)); |
|---|
| 197 | for (i=1; i < (long) argc; i++) |
|---|
| 198 | { |
|---|
| 199 | option=argv[i]; |
|---|
| 200 | if (IsMagickOption(option) != MagickFalse) |
|---|
| 201 | { |
|---|
| 202 | if (LocaleCompare("concurrent",option+1) == 0) |
|---|
| 203 | break; |
|---|
| 204 | if (LocaleCompare("debug",option+1) == 0) |
|---|
| 205 | { |
|---|
| 206 | long |
|---|
| 207 | event; |
|---|
| 208 | |
|---|
| 209 | if (*option == '+') |
|---|
| 210 | break; |
|---|
| 211 | i++; |
|---|
| 212 | if (i == (long) argc) |
|---|
| 213 | ThrowConjureException(OptionError,"MissingArgument",option); |
|---|
| 214 | event=ParseMagickOption(MagickLogEventOptions,MagickFalse,argv[i]); |
|---|
| 215 | if (event < 0) |
|---|
| 216 | ThrowConjureException(OptionError,"UnrecognizedEventType", |
|---|
| 217 | argv[i]); |
|---|
| 218 | (void) SetLogEventMask(argv[i]); |
|---|
| 219 | continue; |
|---|
| 220 | } |
|---|
| 221 | if (LocaleCompare("duration",option+1) == 0) |
|---|
| 222 | { |
|---|
| 223 | if (*option == '+') |
|---|
| 224 | break; |
|---|
| 225 | i++; |
|---|
| 226 | if (i == (long) (argc-1)) |
|---|
| 227 | ThrowConjureException(OptionError,"MissingArgument",option); |
|---|
| 228 | if (IsGeometry(argv[i]) == MagickFalse) |
|---|
| 229 | ThrowConjureInvalidArgumentException(option,argv[i]); |
|---|
| 230 | continue; |
|---|
| 231 | } |
|---|
| 232 | if ((LocaleCompare("help",option+1) == 0) || |
|---|
| 233 | (LocaleCompare("-help",option+1) == 0)) |
|---|
| 234 | { |
|---|
| 235 | if (*option == '-') |
|---|
| 236 | return(ConjureUsage()); |
|---|
| 237 | continue; |
|---|
| 238 | } |
|---|
| 239 | if (LocaleCompare("log",option+1) == 0) |
|---|
| 240 | { |
|---|
| 241 | if (*option == '-') |
|---|
| 242 | { |
|---|
| 243 | i++; |
|---|
| 244 | if (i == (long) argc) |
|---|
| 245 | ThrowConjureException(OptionError,"MissingLogFormat",option); |
|---|
| 246 | (void) SetLogFormat(argv[i]); |
|---|
| 247 | } |
|---|
| 248 | continue; |
|---|
| 249 | } |
|---|
| 250 | if (LocaleCompare("monitor",option+1) == 0) |
|---|
| 251 | continue; |
|---|
| 252 | if (LocaleCompare("quiet",option+1) == 0) |
|---|
| 253 | continue; |
|---|
| 254 | if (LocaleCompare("regard-warnings",option+1) == 0) |
|---|
| 255 | break; |
|---|
| 256 | if (LocaleCompare("seed",option+1) == 0) |
|---|
| 257 | { |
|---|
| 258 | if (*option == '+') |
|---|
| 259 | break; |
|---|
| 260 | i++; |
|---|
| 261 | if (i == (long) (argc-1)) |
|---|
| 262 | ThrowConjureException(OptionError,"MissingArgument",option); |
|---|
| 263 | if (IsGeometry(argv[i]) == MagickFalse) |
|---|
| 264 | ThrowConjureInvalidArgumentException(option,argv[i]); |
|---|
| 265 | break; |
|---|
| 266 | } |
|---|
| 267 | if (LocaleCompare("verbose",option+1) == 0) |
|---|
| 268 | { |
|---|
| 269 | image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse; |
|---|
| 270 | continue; |
|---|
| 271 | } |
|---|
| 272 | if ((LocaleCompare("version",option+1) == 0) || |
|---|
| 273 | (LocaleCompare("-version",option+1) == 0)) |
|---|
| 274 | { |
|---|
| 275 | (void) fprintf(stdout,"Version: %s\n", |
|---|
| 276 | GetMagickVersion((unsigned long *) NULL)); |
|---|
| 277 | (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright()); |
|---|
| 278 | (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures()); |
|---|
| 279 | return(MagickFalse); |
|---|
| 280 | } |
|---|
| 281 | |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | (void) DeleteImageOption(image_info,option+1); |
|---|
| 285 | status=SetImageOption(image_info,option+1,argv[i+1]); |
|---|
| 286 | if (status == MagickFalse) |
|---|
| 287 | ThrowConjureException(ImageError,"UnableToPersistKey",option); |
|---|
| 288 | i++; |
|---|
| 289 | continue; |
|---|
| 290 | } |
|---|
| 291 | |
|---|
| 292 | |
|---|
| 293 | |
|---|
| 294 | (void) DeleteImageOption(image_info,"filename"); |
|---|
| 295 | status=SetImageOption(image_info,"filename",argv[i]); |
|---|
| 296 | if (status == MagickFalse) |
|---|
| 297 | ThrowConjureException(ImageError,"UnableToPersistKey",argv[i]); |
|---|
| 298 | (void) FormatMagickString(image_info->filename,MaxTextExtent,"msl:%s", |
|---|
| 299 | argv[i]); |
|---|
| 300 | image=ReadImages(image_info,exception); |
|---|
| 301 | CatchException(exception); |
|---|
| 302 | if (image != (Image *) NULL) |
|---|
| 303 | image=DestroyImageList(image); |
|---|
| 304 | status=image != (Image *) NULL ? MagickTrue : MagickFalse; |
|---|
| 305 | number_images++; |
|---|
| 306 | } |
|---|
| 307 | if (i != argc) |
|---|
| 308 | ThrowConjureException(OptionError,"MissingAnImageFilename",argv[i]); |
|---|
| 309 | if (number_images == 0) |
|---|
| 310 | ThrowConjureException(OptionError,"MissingAnImageFilename",argv[argc-1]); |
|---|
| 311 | if (image != (Image *) NULL) |
|---|
| 312 | image=DestroyImageList(image); |
|---|
| 313 | for (i=0; i < (long) argc; i++) |
|---|
| 314 | argv[i]=DestroyString(argv[i]); |
|---|
| 315 | argv=(char **) RelinquishMagickMemory(argv); |
|---|
| 316 | return(status != 0 ? MagickTrue : MagickFalse); |
|---|
| 317 | } |
|---|