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