49#include "MagickWand/studio.h"
50#include "MagickWand/MagickWand.h"
51#include "MagickWand/magick-wand-private.h"
52#include "MagickWand/wandcli.h"
53#include "MagickWand/wandcli-private.h"
54#include "MagickWand/operation.h"
55#include "MagickWand/magick-cli.h"
56#include "MagickWand/script-token.h"
57#include "MagickCore/string-private.h"
58#include "MagickCore/thread-private.h"
59#include "MagickCore/utility-private.h"
60#include "MagickCore/exception-private.h"
61#include "MagickCore/version.h"
68#define MagickCommandDebug 0
116WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
117 MagickCommand command,
int argc,
char **argv,
char **metadata,
118 ExceptionInfo *exception)
121 client_name[MagickPathExtent],
141 (void) setlocale(LC_ALL,
"");
142 (void) setlocale(LC_NUMERIC,
"C");
143 GetPathComponent(argv[0],TailPath,client_name);
144 (void) SetClientName(client_name);
145 concurrent=MagickFalse;
149 regard_warnings=MagickFalse;
150 for (i=1; i < (ssize_t) (argc-1); i++)
153 if ((strlen(option) == 1) || ((*option !=
'-') && (*option !=
'+')))
155 if (LocaleCompare(
"-bench",option) == 0)
156 iterations=StringToUnsignedLong(argv[++i]);
157 if (LocaleCompare(
"-concurrent",option) == 0)
158 concurrent=MagickTrue;
159 if (LocaleCompare(
"-debug",option) == 0)
160 (void) SetLogEventMask(argv[++i]);
161 if (LocaleCompare(
"-distribute-cache",option) == 0)
163 DistributePixelCacheServer(StringToInteger(argv[++i]),exception);
166 if (LocaleCompare(
"-duration",option) == 0)
167 duration=StringToDouble(argv[++i],(
char **) NULL);
168 if (LocaleCompare(
"-regard-warnings",option) == 0)
169 regard_warnings=MagickTrue;
177 status=command(image_info,argc,argv,&text,exception);
178 if (exception->severity != UndefinedException)
180 if ((exception->severity > ErrorException) ||
181 (regard_warnings != MagickFalse))
183 CatchException(exception);
185 if (text != (
char *) NULL)
187 if (metadata != (
char **) NULL)
188 (void) ConcatenateString(&(*metadata),text);
189 text=DestroyString(text);
193 number_threads=GetOpenMPMaximumThreads();
195 for (n=1; n <= (ssize_t) number_threads; n++)
205 (void) SetMagickResourceLimit(ThreadResource,(MagickSizeType) n);
206 timer=AcquireTimerInfo();
207 if (concurrent == MagickFalse)
209 for (i=0; i < (ssize_t) iterations; i++)
215 if (status == MagickFalse)
219 if (GetElapsedTime(timer) > duration)
221 (void) ContinueTimer(timer);
223 status=command(image_info,argc,argv,&text,exception);
224 if (exception->severity != UndefinedException)
226 if ((exception->severity > ErrorException) ||
227 (regard_warnings != MagickFalse))
229 CatchException(exception);
231 if (text != (
char *) NULL)
233 if (metadata != (
char **) NULL)
234 (void) ConcatenateString(&(*metadata),text);
235 text=DestroyString(text);
242#if defined(MAGICKCORE_OPENMP_SUPPORT)
243 # pragma omp parallel for shared(status)
245 for (i=0; i < (ssize_t) iterations; i++)
251 if (status == MagickFalse)
255 if (GetElapsedTime(timer) > duration)
257 (void) ContinueTimer(timer);
259 status=command(image_info,argc,argv,&text,exception);
260#if defined(MAGICKCORE_OPENMP_SUPPORT)
261 # pragma omp critical (MagickCore_MagickCommandGenesis)
264 if (exception->severity != UndefinedException)
266 if ((exception->severity > ErrorException) ||
267 (regard_warnings != MagickFalse))
269 CatchException(exception);
271 if (text != (
char *) NULL)
273 if (metadata != (
char **) NULL)
274 (void) ConcatenateString(&(*metadata),text);
275 text=DestroyString(text);
280 user_time=GetUserTime(timer);
281 parallel=GetElapsedTime(timer);
286 e=((1.0/(1.0/((serial/(serial+parallel))+(1.0-(serial/(serial+parallel)))/
287 (double) n)))-(1.0/(double) n))/(1.0-1.0/(
double) n);
288 (void) FormatLocaleFile(stderr,
289 " Performance[%.20g]: %.20gi %0.3fips %0.6fe %0.6fu %lu:%02lu.%03lu\n",
290 (
double) n,(
double) iterations,(
double) iterations/parallel,e,user_time,
291 (
unsigned long) (parallel/60.0),(
unsigned long) floor(fmod(parallel,
292 60.0)),(
unsigned long) (1000.0*(parallel-floor(parallel))+0.5));
293 timer=DestroyTimerInfo(timer);
340WandExport
void ProcessScriptOptions(
MagickCLI *cli_wand,
const char *filename,
341 int magick_unused(argc),
char **magick_unused(argv),
int magick_unused(index))
357 magick_unreferenced(argc);
358 magick_unreferenced(argv);
359 magick_unreferenced(index);
360 assert(filename != (
char *) NULL );
362 assert(cli_wand->signature == MagickWandSignature);
363 if (cli_wand->wand.debug != MagickFalse)
364 (void) LogMagickEvent(CommandEvent,GetMagickModule(),
365 "Processing script \"%s\"", filename);
368 token_info = AcquireScriptTokenInfo(filename);
370 CLIWandExceptionFile(OptionFatalError,
"UnableToOpenScript",filename);
376 cli_wand->location=
"in \"%s\" at line %u,column %u";
377 if ( LocaleCompare(
"-", filename) == 0 )
378 cli_wand->filename=
"stdin";
380 cli_wand->filename=filename;
383 option = arg1 = arg2 = (
char*) NULL;
384DisableMSCWarning(4127)
388 { MagickBooleanType status = GetScriptToken(token_info);
389 cli_wand->line=token_info->token_line;
390 cli_wand->column=token_info->token_column;
391 if (status == MagickFalse)
398 CloneString(&option,token_info->token);
401 cli_wand->command = GetCommandOptionInfo(option);
402 count=cli_wand->command->type;
403 option_type=(CommandOptionFlags) cli_wand->command->flags;
405 (void) FormatLocaleFile(stderr,
"Script: %u,%u: \"%s\" matched \"%s\"\n",
406 cli_wand->line, cli_wand->line, option, cli_wand->command->mnemonic );
410 if ( option_type == UndefinedOptionFlag ||
411 (option_type & NonMagickOptionFlag) != 0 ) {
412#if MagickCommandDebug >= 3
413 (void) FormatLocaleFile(stderr,
"Script %u,%u Non-Option: \"%s\"\n",
414 cli_wand->line, cli_wand->line, option);
416 if (IsCommandOption(option) == MagickFalse) {
418 cli_wand->command=(
const OptionInfo *) NULL;
419 CLIOption(cli_wand,
"-read",option);
422 CLIWandException(OptionFatalError,
"UnrecognizedOption",option);
427 if (GetScriptToken(token_info) == MagickFalse)
428 CLIWandException(OptionFatalError,
"MissingArgument",option);
429 CloneString(&arg1,token_info->token);
432 CloneString(&arg1,(
char *) NULL);
435 if (GetScriptToken(token_info) == MagickFalse)
436 CLIWandExceptionBreak(OptionFatalError,
"MissingArgument",option);
437 CloneString(&arg2,token_info->token);
440 CloneString(&arg2,(
char *) NULL);
445#if MagickCommandDebug >= 3
446 (void) FormatLocaleFile(stderr,
447 "Script %u,%u Option: \"%s\" Count: %d Flags: %04x Args: \"%s\" \"%s\"\n",
448 cli_wand->line,cli_wand->line,option,count,option_type,arg1,arg2);
451 if ( (option_type & DeprecateOptionFlag) != 0 ) {
452 CLIWandException(OptionError,
"DeprecatedOptionNoCode",option);
457 if ( (option_type & GenesisOptionFlag) != 0 ) {
458 CLIWandException(OptionError,
"InvalidUseOfOption",option);
463 if ( (option_type & SpecialOptionFlag) != 0 ) {
464 if ( LocaleCompare(option,
"-exit") == 0 ) {
467 if ( LocaleCompare(option,
"-script") == 0 ) {
469 CLIWandException(OptionError,
"InvalidUseOfOption",option);
474 CLIWandException(OptionError,
"InvalidUseOfOption",option);
479 CLIOption(cli_wand, option, arg1, arg2);
480 (void) fflush(stdout);
481 (void) fflush(stderr);
483DisableMSCWarning(4127)
487#if MagickCommandDebug >= 5
488 fprintf(stderr,
"Script Image Count = %ld\n",
489 GetImageListLength(cli_wand->wand.images) );
491 if (CLICatchException(cli_wand, MagickFalse) != MagickFalse)
499#if MagickCommandDebug >= 3
500 (void) FormatLocaleFile(stderr,
"Script End: %d\n", token_info->status);
502 switch( token_info->status ) {
505 if (cli_wand->image_list_stack != (
CLIStack *) NULL)
506 CLIWandException(OptionError,
"UnbalancedParenthesis",
"(eof)");
507 else if (cli_wand->image_info_stack != (
CLIStack *) NULL)
508 CLIWandException(OptionError,
"UnbalancedBraces",
"(eof)");
510 case TokenStatusBadQuotes:
512 if( strlen(token_info->token) > INITAL_TOKEN_LENGTH-1 ) {
513 token_info->token[INITAL_TOKEN_LENGTH-4] =
'.';
514 token_info->token[INITAL_TOKEN_LENGTH-3] =
'.';
515 token_info->token[INITAL_TOKEN_LENGTH-2] =
'.';
516 token_info->token[INITAL_TOKEN_LENGTH-1] =
'\0';
518 CLIWandException(OptionFatalError,
"ScriptUnbalancedQuotes",
521 case TokenStatusMemoryFailed:
522 CLIWandException(OptionFatalError,
"ScriptTokenMemoryFailed",
"");
524 case TokenStatusBinary:
525 CLIWandException(OptionFatalError,
"ScriptIsBinary",
"");
528 (void) fflush(stdout);
529 (void) fflush(stderr);
530 if (cli_wand->wand.debug != MagickFalse)
531 (void) LogMagickEvent(CommandEvent,GetMagickModule(),
532 "Script End \"%s\"", filename);
535 token_info = DestroyScriptTokenInfo(token_info);
537 CloneString(&option,(
char *) NULL);
538 CloneString(&arg1,(
char *) NULL);
539 CloneString(&arg2,(
char *) NULL);
587WandExport
int ProcessCommandOptions(
MagickCLI *cli_wand,
int argc,
char **argv,
604 assert(argv != (
char **) NULL);
605 assert(argv[index] != (
char *) NULL);
606 assert(argv[argc-1] != (
char *) NULL);
608 assert(cli_wand->signature == MagickWandSignature);
612 cli_wand->location=
"at %s arg %u";
613 cli_wand->filename=
"CLI";
614 cli_wand->line=(size_t) index;
616 if (cli_wand->wand.debug != MagickFalse)
617 (void) CLILogEvent(cli_wand,CommandEvent,GetMagickModule(),
618 "- Starting (\"%s\")", argv[index]);
621 if ( (cli_wand->process_flags & ProcessImplicitWrite) != 0 )
624 for (i=index; i < end; i += count +1) {
626 if ( (cli_wand->process_flags & ProcessOneOptionOnly) != 0 && i != index )
632 cli_wand->line=(size_t) i;
635 cli_wand->command = GetCommandOptionInfo(argv[i]);
636 count=cli_wand->command->type;
637 option_type=(CommandOptionFlags) cli_wand->command->flags;
639 (void) FormatLocaleFile(stderr,
"CLI %d: \"%s\" matched \"%s\"\n",
640 i, argv[i], cli_wand->command->mnemonic );
643 if ( option_type == UndefinedOptionFlag ||
644 (option_type & NonMagickOptionFlag) != 0 ) {
645#if MagickCommandDebug >= 3
646 (void) FormatLocaleFile(stderr,
"CLI arg %d Non-Option: \"%s\"\n",
649 if (IsCommandOption(option) == MagickFalse) {
650 if ( (cli_wand->process_flags & ProcessImplicitRead) != 0 ) {
652 cli_wand->command=(
const OptionInfo *) NULL;
653 CLIOption(cli_wand,
"-read",option);
657 CLIWandException(OptionFatalError,
"UnrecognizedOption",option);
661 if ( ((option_type & SpecialOptionFlag) != 0 ) &&
662 ((cli_wand->process_flags & ProcessScriptOption) != 0) &&
663 (LocaleCompare(option,
"-script") == 0) ) {
668 if ( (i+count) >= argc )
669 CLIWandException(OptionFatalError,
"MissingArgument",option);
670 ProcessScriptOptions(cli_wand,argv[i+1],argc,argv,i+count);
675 if ((i+count) >= end ) {
676 CLIWandException(OptionFatalError,
"MissingArgument",option);
677 if ( CLICatchException(cli_wand, MagickFalse) != MagickFalse )
682 arg1 = ( count >= 1 ) ? argv[i+1] : (char *) NULL;
683 arg2 = ( count >= 2 ) ? argv[i+2] : (
char *) NULL;
688#if MagickCommandDebug >= 3
689 (void) FormatLocaleFile(stderr,
690 "CLI arg %u Option: \"%s\" Count: %d Flags: %04x Args: \"%s\" \"%s\"\n",
691 i,option,count,option_type,arg1,arg2);
694 if ( (option_type & GenesisOptionFlag) != 0 )
698 if ( (option_type & SpecialOptionFlag) != 0 ) {
699 if ( (cli_wand->process_flags & ProcessExitOption) != 0
700 && LocaleCompare(option,
"-exit") == 0 )
706 CLIOption(cli_wand, option, arg1, arg2);
708DisableMSCWarning(4127)
712#if MagickCommandDebug >= 5
713 (void) FormatLocaleFile(stderr,
"CLI-post Image Count = %ld\n",
714 (
long) GetImageListLength(cli_wand->wand.images) );
716 if ( CLICatchException(cli_wand, MagickFalse) != MagickFalse )
721 if ( (cli_wand->process_flags & ProcessImplicitWrite) == 0 )
730 cli_wand->line=(size_t) i;
733 if (cli_wand->image_list_stack != (
CLIStack *) NULL)
734 CLIWandException(OptionError,
"UnbalancedParenthesis",
"(end of cli)");
735 else if (cli_wand->image_info_stack != (
CLIStack *) NULL)
736 CLIWandException(OptionError,
"UnbalancedBraces",
"(end of cli)");
737 if ( CLICatchException(cli_wand, MagickFalse) != MagickFalse )
740#if MagickCommandDebug >= 3
741 (void) FormatLocaleFile(stderr,
"CLI arg %d Write File: \"%s\"\n",i,option);
745 if (LocaleCompare(option,
"-exit") == 0 )
751 if (IsCommandOption(option) != MagickFalse ||
752 (option[0] ==
' ' && option[1] ==
'\0') ) {
753 CLIWandException(OptionError,
"MissingOutputFilename",option);
757 cli_wand->command=(
const OptionInfo *) NULL;
758 CLIOption(cli_wand,
"-write",option);
801static MagickBooleanType MagickCommandUsage(
void)
804 channel_operators[] =
805 " -channel-fx expression\n"
806 " exchange, extract, or transfer one or more image channels\n"
807 " -separate separate an image channel into a grayscale image",
809 " -debug events display copious debugging information\n"
810 " -distribute-cache port\n"
811 " distributed pixel cache spanning one or more servers\n"
812 " -help print program options\n"
813 " -list type print a list of supported option arguments\n"
814 " -log format format of debugging information\n"
815 " -usage print program usage\n"
816 " -version print version information",
818 " -adaptive-blur geometry\n"
819 " adaptively blur pixels; decrease effect near edges\n"
820 " -adaptive-resize geometry\n"
821 " adaptively resize image using 'mesh' interpolation\n"
822 " -adaptive-sharpen geometry\n"
823 " adaptively sharpen pixels; increase effect near edges\n"
824 " -alpha option on, activate, off, deactivate, set, opaque, copy\n"
825 " transparent, extract, background, or shape\n"
826 " -annotate geometry text\n"
827 " annotate the image with text\n"
828 " -auto-gamma automagically adjust gamma level of image\n"
829 " -auto-level automagically adjust color levels of image\n"
830 " -auto-orient automagically orient (rotate) image\n"
831 " -auto-threshold method\n"
832 " automatically perform image thresholding\n"
833 " -bench iterations measure performance\n"
834 " -bilateral-blur geometry\n"
835 " non-linear, edge-preserving, and noise-reducing smoothing filter\n"
836 " -black-threshold value\n"
837 " force all pixels below the threshold into black\n"
838 " -blue-shift factor simulate a scene at nighttime in the moonlight\n"
839 " -blur geometry reduce image noise and reduce detail levels\n"
840 " -border geometry surround image with a border of color\n"
841 " -bordercolor color border color\n"
842 " -brightness-contrast geometry\n"
843 " improve brightness / contrast of the image\n"
844 " -canny geometry detect edges in the image\n"
845 " -cdl filename color correct with a color decision list\n"
846 " -channel mask set the image channel mask\n"
847 " -charcoal radius simulate a charcoal drawing\n"
848 " -chop geometry remove pixels from the image interior\n"
849 " -clahe geometry contrast limited adaptive histogram equalization\n"
850 " -clamp keep pixel values in range (0-QuantumRange)\n"
851 " -colorize value colorize the image with the fill color\n"
852 " -color-matrix matrix apply color correction to the image\n"
853 " -colors value preferred number of colors in the image\n"
854 " -connected-components connectivity\n"
855 " connected-components uniquely labeled\n"
856 " -contrast enhance or reduce the image contrast\n"
857 " -contrast-stretch geometry\n"
858 " improve contrast by 'stretching' the intensity range\n"
859 " -convolve coefficients\n"
860 " apply a convolution kernel to the image\n"
861 " -cycle amount cycle the image colormap\n"
862 " -decipher filename convert cipher pixels to plain pixels\n"
863 " -deskew threshold straighten an image\n"
864 " -despeckle reduce the speckles within an image\n"
865 " -distort method args\n"
866 " distort images according to given method and args\n"
867 " -draw string annotate the image with a graphic primitive\n"
868 " -edge radius apply a filter to detect edges in the image\n"
869 " -encipher filename convert plain pixels to cipher pixels\n"
870 " -emboss radius emboss an image\n"
871 " -enhance apply a digital filter to enhance a noisy image\n"
872 " -equalize perform histogram equalization to an image\n"
873 " -evaluate operator value\n"
874 " evaluate an arithmetic, relational, or logical expression\n"
875 " -extent geometry set the image size\n"
876 " -extract geometry extract area from image\n"
877 " -fft implements the discrete Fourier transform (DFT)\n"
878 " -flip flip image vertically\n"
879 " -floodfill geometry color\n"
880 " floodfill the image with color\n"
881 " -flop flop image horizontally\n"
882 " -frame geometry surround image with an ornamental border\n"
883 " -function name parameters\n"
884 " apply function over image values\n"
885 " -gamma value level of gamma correction\n"
886 " -gaussian-blur geometry\n"
887 " reduce image noise and reduce detail levels\n"
888 " -geometry geometry preferred size or location of the image\n"
889 " -grayscale method convert image to grayscale\n"
890 " -hough-lines geometry\n"
891 " identify lines in the image\n"
892 " -identify identify the format and characteristics of the image\n"
893 " -ift implements the inverse discrete Fourier transform (DFT)\n"
894 " -implode amount implode image pixels about the center\n"
895 " -integral calculate the sum of values (pixel values) in the image\n"
896 " -interpolative-resize geometry\n"
897 " resize image using interpolation\n"
898 " -kmeans geometry K means color reduction\n"
899 " -kuwahara geometry edge preserving noise reduction filter\n"
900 " -lat geometry local adaptive thresholding\n"
901 " -level value adjust the level of image contrast\n"
902 " -level-colors color,color\n"
903 " level image with the given colors\n"
904 " -linear-stretch geometry\n"
905 " improve contrast by 'stretching with saturation'\n"
906 " -liquid-rescale geometry\n"
907 " rescale image with seam-carving\n"
908 " -local-contrast geometry\n"
909 " enhance local contrast\n"
910 " -mean-shift geometry delineate arbitrarily shaped clusters in the image\n"
911 " -median geometry apply a median filter to the image\n"
912 " -mode geometry make each pixel the 'predominant color' of the\n"
914 " -modulate value vary the brightness, saturation, and hue\n"
915 " -monochrome transform image to black and white\n"
916 " -morphology method kernel\n"
917 " apply a morphology method to the image\n"
918 " -motion-blur geometry\n"
919 " simulate motion blur\n"
920 " -negate replace every pixel with its complementary color \n"
921 " -noise geometry add or reduce noise in an image\n"
922 " -normalize transform image to span the full range of colors\n"
923 " -opaque color change this color to the fill color\n"
924 " -ordered-dither NxN\n"
925 " add a noise pattern to the image with specific\n"
927 " -paint radius simulate an oil painting\n"
928 " -perceptible epsilon\n"
929 " pixel value less than |epsilon| become epsilon or\n"
931 " -polaroid angle simulate a Polaroid picture\n"
932 " -posterize levels reduce the image to a limited number of color levels\n"
933 " -profile filename add, delete, or apply an image profile\n"
934 " -quantize colorspace reduce colors in this colorspace\n"
935 " -raise value lighten/darken image edges to create a 3-D effect\n"
936 " -random-threshold low,high\n"
937 " random threshold the image\n"
938 " -range-threshold values\n"
939 " perform either hard or soft thresholding within some range of values in an image\n"
940 " -region geometry apply options to a portion of the image\n"
941 " -render render vector graphics\n"
942 " -resample geometry change the resolution of an image\n"
943 " -reshape geometry reshape the image\n"
944 " -resize geometry resize the image\n"
945 " -roll geometry roll an image vertically or horizontally\n"
946 " -rotate degrees apply Paeth rotation to the image\n"
947 " -rotational-blur angle\n"
948 " rotational blur the image\n"
949 " -sample geometry scale image with pixel sampling\n"
950 " -scale geometry scale the image\n"
951 " -segment values segment an image\n"
952 " -selective-blur geometry\n"
953 " selectively blur pixels within a contrast threshold\n"
954 " -sepia-tone threshold\n"
955 " simulate a sepia-toned photo\n"
956 " -set property value set an image property\n"
957 " -shade degrees shade the image using a distant light source\n"
958 " -shadow geometry simulate an image shadow\n"
959 " -sharpen geometry sharpen the image\n"
960 " -shave geometry shave pixels from the image edges\n"
961 " -shear geometry slide one edge of the image along the X or Y axis\n"
962 " -sigmoidal-contrast geometry\n"
963 " increase the contrast without saturating highlights or\n"
965 " -sketch geometry simulate a pencil sketch\n"
966 " -solarize threshold negate all pixels above the threshold level\n"
967 " -sort-pixels sort each scanline in ascending order of intensity\n"
968 " -sparse-color method args\n"
969 " fill in a image based on a few color points\n"
970 " -splice geometry splice the background color into the image\n"
971 " -spread radius displace image pixels by a random amount\n"
972 " -statistic type geometry\n"
973 " replace each pixel with corresponding statistic from the\n"
975 " -strip strip image of all profiles and comments\n"
976 " -swirl degrees swirl image pixels about the center\n"
977 " -threshold value threshold the image\n"
978 " -thumbnail geometry create a thumbnail of the image\n"
979 " -tile filename tile image when filling a graphic primitive\n"
980 " -tint value tint the image with the fill color\n"
981 " -transform affine transform image\n"
982 " -transparent color make this color transparent within the image\n"
983 " -transpose flip image vertically and rotate 90 degrees\n"
984 " -transverse flop image horizontally and rotate 270 degrees\n"
985 " -trim trim image edges\n"
986 " -type type image type\n"
987 " -unique-colors discard all but one of any pixel color\n"
988 " -unsharp geometry sharpen the image\n"
989 " -vignette geometry soften the edges of the image in vignette style\n"
990 " -wave geometry alter an image along a sine wave\n"
991 " -wavelet-denoise threshold\n"
992 " removes noise from the image using a wavelet transform\n"
993 " -white-balance automagically adjust white balance of image\n"
994 " -white-threshold value\n"
995 " force all pixels above the threshold into white",
996 sequence_operators[] =
997 " -append append an image sequence\n"
998 " -clut apply a color lookup table to the image\n"
999 " -coalesce merge a sequence of images\n"
1000 " -combine combine a sequence of images\n"
1001 " -compare mathematically and visually annotate the difference between an image and its reconstruction\n"
1002 " -complex operator perform complex mathematics on an image sequence\n"
1003 " -composite composite image\n"
1004 " -copy geometry offset\n"
1005 " copy pixels from one area of an image to another\n"
1006 " -crop geometry cut out a rectangular region of the image\n"
1007 " -deconstruct break down an image sequence into constituent parts\n"
1008 " -evaluate-sequence operator\n"
1009 " evaluate an arithmetic, relational, or logical expression\n"
1010 " -flatten flatten a sequence of images\n"
1011 " -fx expression apply mathematical expression to an image channel(s)\n"
1012 " -hald-clut apply a Hald color lookup table to the image\n"
1013 " -layers method optimize, merge, or compare image layers\n"
1014 " -morph value morph an image sequence\n"
1015 " -mosaic create a mosaic from an image sequence\n"
1016 " -poly terms build a polynomial from the image sequence and the corresponding\n"
1017 " terms (coefficients and degree pairs).\n"
1018 " -print string interpret string and print to console\n"
1019 " -process arguments process the image with a custom image filter\n"
1020 " -smush geometry smush an image sequence together\n"
1021 " -write filename write images to this file",
1023 " -adjoin join images into a single multi-image file\n"
1024 " -affine matrix affine transform matrix\n"
1025 " -alpha option activate, deactivate, reset, or set the alpha channel\n"
1026 " -antialias remove pixel-aliasing\n"
1027 " -authenticate password\n"
1028 " decipher image with this password\n"
1029 " -attenuate value lessen (or intensify) when adding noise to an image\n"
1030 " -background color background color\n"
1031 " -bias value add bias when convolving an image\n"
1032 " -black-point-compensation\n"
1033 " use black point compensation\n"
1034 " -blue-primary point chromaticity blue primary point\n"
1035 " -bordercolor color border color\n"
1036 " -caption string assign a caption to an image\n"
1037 " -clip clip along the first path from the 8BIM profile\n"
1038 " -clip-mask filename associate a clip mask with the image\n"
1039 " -clip-path id clip along a named path from the 8BIM profile\n"
1040 " -colorspace type alternate image colorspace\n"
1041 " -comment string annotate image with comment\n"
1042 " -compose operator set image composite operator\n"
1043 " -compress type type of pixel compression when writing the image\n"
1044 " -define format:option\n"
1045 " define one or more image format options\n"
1046 " -delay value display the next image after pausing\n"
1047 " -density geometry horizontal and vertical density of the image\n"
1048 " -depth value image depth\n"
1049 " -direction type render text right-to-left or left-to-right\n"
1050 " -display server get image or font from this X server\n"
1051 " -dispose method layer disposal method\n"
1052 " -dither method apply error diffusion to image\n"
1053 " -encoding type text encoding type\n"
1054 " -endian type endianness (MSB or LSB) of the image\n"
1055 " -family name render text with this font family\n"
1056 " -features distance analyze image features (e.g. contrast, correlation)\n"
1057 " -fill color color to use when filling a graphic primitive\n"
1058 " -filter type use this filter when resizing an image\n"
1059 " -font name render text with this font\n"
1060 " -format \"string\" output formatted image characteristics\n"
1061 " -fuzz distance colors within this distance are considered equal\n"
1062 " -gravity type horizontal and vertical text placement\n"
1063 " -green-primary point chromaticity green primary point\n"
1064 " -illuminant type reference illuminant\n"
1065 " -intensity method method to generate an intensity value from a pixel\n"
1066 " -intent type type of rendering intent when managing the image color\n"
1067 " -interlace type type of image interlacing scheme\n"
1068 " -interline-spacing value\n"
1069 " set the space between two text lines\n"
1070 " -interpolate method pixel color interpolation method\n"
1071 " -interword-spacing value\n"
1072 " set the space between two words\n"
1073 " -kerning value set the space between two letters\n"
1074 " -label string assign a label to an image\n"
1075 " -limit type value pixel cache resource limit\n"
1076 " -loop iterations add Netscape loop extension to your GIF animation\n"
1077 " -matte store matte channel if the image has one\n"
1078 " -mattecolor color frame color\n"
1079 " -moments report image moments\n"
1080 " -monitor monitor progress\n"
1081 " -orient type image orientation\n"
1082 " -page geometry size and location of an image canvas (setting)\n"
1083 " -ping efficiently determine image attributes\n"
1084 " -pointsize value font point size\n"
1085 " -precision value maximum number of significant digits to print\n"
1086 " -preview type image preview type\n"
1087 " -quality value JPEG/MIFF/PNG compression level\n"
1088 " -quiet suppress all warning messages\n"
1089 " -read-mask filename associate a read mask with the image\n"
1090 " -red-primary point chromaticity red primary point\n"
1091 " -regard-warnings pay attention to warning messages\n"
1092 " -remap filename transform image colors to match this set of colors\n"
1093 " -repage geometry size and location of an image canvas\n"
1094 " -respect-parentheses settings remain in effect until parenthesis boundary\n"
1095 " -sampling-factor geometry\n"
1096 " horizontal and vertical sampling factor\n"
1097 " -scene value image scene number\n"
1098 " -seed value seed a new sequence of pseudo-random numbers\n"
1099 " -size geometry width and height of image\n"
1100 " -stretch type render text with this font stretch\n"
1101 " -stroke color graphic primitive stroke color\n"
1102 " -strokewidth value graphic primitive stroke width\n"
1103 " -style type render text with this font style\n"
1104 " -support factor resize support: > 1.0 is blurry, < 1.0 is sharp\n"
1105 " -synchronize synchronize image to storage device\n"
1106 " -taint declare the image as modified\n"
1107 " -texture filename name of texture to tile onto the image background\n"
1108 " -tile-offset geometry\n"
1110 " -treedepth value color tree depth\n"
1111 " -transparent-color color\n"
1112 " transparent color\n"
1113 " -undercolor color annotation bounding box color\n"
1114 " -units type the units of image resolution\n"
1115 " -verbose print detailed information about the image\n"
1116 " -view FlashPix viewing transforms\n"
1117 " -virtual-pixel method\n"
1118 " virtual pixel access method\n"
1119 " -weight type render text with this font weight\n"
1120 " -white-point point chromaticity white point\n"
1121 " -write-mask filename associate a write mask with the image"
1122 " -word-break type sets whether line breaks appear wherever the text would otherwise overflow",
1124 " -clone indexes clone an image\n"
1125 " -delete indexes delete the image from the image sequence\n"
1126 " -duplicate count,indexes\n"
1127 " duplicate an image one or more times\n"
1128 " -insert index insert last image into the image sequence\n"
1129 " -reverse reverse image sequence\n"
1130 " -swap indexes swap two images in the image sequence";
1132 ListMagickVersion(stdout);
1133 (void) FormatLocaleFile(stdout,
1134 "Usage: %s tool [ {option} | {image} ... ] {output_image}\n",
1136 (void) FormatLocaleFile(stdout,
1137 "Usage: %s [ {option} | {image} ... ] {output_image}\n",GetClientName());
1138 (void) FormatLocaleFile(stdout,
1139 " %s [ {option} | {image} ... ] -script {filename} [ {script_args} ...]\n",
1141 (void) FormatLocaleFile(stdout,
"\nImage Settings:\n");
1142 (void) FormatLocaleFile(stdout,
"%s\n",settings);
1143 (void) FormatLocaleFile(stdout,
"\nImage Operators:\n");
1144 (void) FormatLocaleFile(stdout,
"%s\n",operators);
1145 (void) FormatLocaleFile(stdout,
"\nImage Channel Operators:\n");
1146 (void) FormatLocaleFile(stdout,
"%s\n",channel_operators);
1147 (void) FormatLocaleFile(stdout,
"\nImage Sequence Operators:\n");
1148 (void) FormatLocaleFile(stdout,
"%s\n",sequence_operators);
1149 (void) FormatLocaleFile(stdout,
"\nImage Stack Operators:\n");
1150 (void) FormatLocaleFile(stdout,
"%s\n",stack_operators);
1151 (void) FormatLocaleFile(stdout,
"\nMiscellaneous Options:\n");
1152 (void) FormatLocaleFile(stdout,
"%s\n",miscellaneous);
1153 (void) FormatLocaleFile(stdout,
1154 "\nBy default, the image format of 'file' is determined by its magic\n");
1155 (void) FormatLocaleFile(stdout,
1156 "number. To specify a particular image format, precede the filename\n");
1157 (void) FormatLocaleFile(stdout,
1158 "with an image format name and a colon (i.e. ps:image) or specify the\n");
1159 (void) FormatLocaleFile(stdout,
1160 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
1161 (void) FormatLocaleFile(stdout,
"'-' for standard input or output.\n");
1165static void MagickUsage(MagickBooleanType verbose)
1173 name=GetClientName();
1176 if (verbose == MagickFalse)
1178 MagickCommandUsage();
1182 if (len>=7 && LocaleCompare(
"convert",name+len-7) == 0) {
1184 (void) FormatLocaleFile(stdout,
1185 "Usage: %s [ {option} | {image} ... ] {output_image}\n",name);
1186 (void) FormatLocaleFile(stdout,
1187 " %s -help | -version | -usage | -list {option}\n\n",name);
1190 else if (len>=6 && LocaleCompare(
"script",name+len-6) == 0) {
1192 (void) FormatLocaleFile(stdout,
1193 "Usage: %s {filename} [ {script_args} ... ]\n",name);
1197 (void) FormatLocaleFile(stdout,
1198 "Usage: %s tool [ {option} | {image} ... ] {output_image}\n",name);
1199 (void) FormatLocaleFile(stdout,
1200 "Usage: %s [ {option} | {image} ... ] {output_image}\n",name);
1201 (void) FormatLocaleFile(stdout,
1202 " %s [ {option} | {image} ... ] -script {filename} [ {script_args} ...]\n",
1205 (void) FormatLocaleFile(stdout,
1206 " %s -help | -version | -usage | -list {option}\n\n",name);
1208 (void) FormatLocaleFile(stdout,
"%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
1209 "All options are performed in a strict 'as you see them' order\n",
1210 "You must read-in images before you can operate on them.\n",
1212 "Magick Script files can use any of the following forms...\n",
1213 " #!/path/to/magick -script\n",
1216 " :; exec magick -script \"$0\" \"$@\"; exit 10\n",
1217 " # Magick script from here...\n",
1219 " #!/usr/bin/env magick-script\n",
1220 "The latter two forms do not require the path to the command hard coded.\n",
1221 "Note: \"magick-script\" needs to be linked to the \"magick\" command.\n",
1223 "For more information on usage, options, examples, and techniques\n",
1224 "see the ImageMagick website at ", MagickAuthoritativeURL);
1239static MagickBooleanType ConcatenateImages(
int argc,
char **argv,
1240 ExceptionInfo *exception )
1255 if (ExpandFilenames(&argc,&argv) == MagickFalse)
1256 ThrowFileException(exception,ResourceLimitError,
"MemoryAllocationFailed",
1257 GetExceptionMessage(errno));
1258 output=fopen_utf8(argv[argc-1],
"wb");
1259 if (output == (FILE *) NULL)
1261 ThrowFileException(exception,FileOpenError,
"UnableToOpenFile",
1263 return(MagickFalse);
1266 for (i=2; i < (ssize_t) (argc-1); i++)
1268 input=fopen_utf8(argv[i],
"rb");
1269 if (input == (FILE *) NULL)
1271 ThrowFileException(exception,FileOpenError,
"UnableToOpenFile",argv[i]);
1274 for (c=fgetc(input); c != EOF; c=fgetc(input))
1275 if (fputc((
char) c,output) != c)
1277 (void) fclose(input);
1278 (void) remove_utf8(argv[i]);
1280 (void) fclose(output);
1284WandExport MagickBooleanType MagickImageCommand(ImageInfo *image_info,
int argc,
1285 char **argv,
char **metadata,ExceptionInfo *exception)
1293 assert(image_info != (ImageInfo *) NULL);
1296 ReadCommandlLine(argc,&argv);
1299 cli_wand=AcquireMagickCLI(image_info,exception);
1300 cli_wand->location=
"Initializing";
1301 cli_wand->filename=argv[0];
1304 if (cli_wand->wand.debug != MagickFalse)
1305 (void) CLILogEvent(cli_wand,CommandEvent,GetMagickModule(),
1309 GetPathComponent(argv[0],TailPath,cli_wand->wand.name);
1310 SetClientName(cli_wand->wand.name);
1311 ConcatenateMagickString(cli_wand->wand.name,
"-CLI",MagickPathExtent);
1313 len=strlen(argv[0]);
1316 if (len>=7 && LocaleCompare(
"convert",argv[0]+len-7) == 0) {
1317 cli_wand->process_flags = ConvertCommandOptionFlags;
1318 (void) FormatLocaleFile(stderr,
"WARNING: %s\n",
1319 "The convert command is deprecated in IMv7, use \"magick\"\n");
1323 if (len>=6 && LocaleCompare(
"script",argv[0]+len-6) == 0) {
1324 if (argc >= 2 && ( (*(argv[1]) !=
'-') || (strlen(argv[1]) == 1) )) {
1325 GetPathComponent(argv[1],TailPath,cli_wand->wand.name);
1326 ProcessScriptOptions(cli_wand,argv[1],argc,argv,2);
1327 goto Magick_Command_Cleanup;
1333 if ((LocaleCompare(
"-version",argv[1]) == 0) ||
1334 (LocaleCompare(
"--version",argv[1]) == 0) ) {
1335 CLIOption(cli_wand,
"-version");
1336 goto Magick_Command_Exit;
1338 if ((LocaleCompare(
"-help",argv[1]) == 0) ||
1339 (LocaleCompare(
"--help",argv[1]) == 0) ) {
1340 if (cli_wand->wand.debug != MagickFalse)
1341 (void) CLILogEvent(cli_wand,CommandEvent,GetMagickModule(),
1342 "- Special Option \"%s\"", argv[1]);
1343 MagickUsage(MagickFalse);
1344 goto Magick_Command_Exit;
1346 if (LocaleCompare(
"-usage",argv[1]) == 0) {
1347 if (cli_wand->wand.debug != MagickFalse)
1348 (void) CLILogEvent(cli_wand,CommandEvent,GetMagickModule(),
1349 "- Special Option \"%s\"", argv[1]);
1350 CLIOption(cli_wand,
"-version" );
1351 MagickUsage(MagickTrue);
1352 goto Magick_Command_Exit;
1358 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1359 "InvalidArgument",
"%s",argc > 1 ? argv[argc-1] :
"");
1360 MagickUsage(MagickFalse);
1361 goto Magick_Command_Exit;
1365 if (LocaleCompare(
"-concatenate",argv[1]) == 0) {
1366 if (cli_wand->wand.debug != MagickFalse)
1367 (void) CLILogEvent(cli_wand,CommandEvent,GetMagickModule(),
1368 "- Special Option \"%s\"", argv[1]);
1369 ConcatenateImages(argc,argv,exception);
1370 goto Magick_Command_Exit;
1374 if (argc == 3 && LocaleCompare(
"-list",argv[1]) == 0) {
1375 CLIOption(cli_wand, argv[1], argv[2]);
1376 goto Magick_Command_Exit;
1382 if (LocaleCompare(
"-script",argv[1]) == 0) {
1387 GetPathComponent(argv[2],TailPath,cli_wand->wand.name);
1388 ProcessScriptOptions(cli_wand,argv[2],argc,argv,3);
1392 ProcessCommandOptions(cli_wand,argc,argv,1);
1396Magick_Command_Cleanup:
1397 cli_wand->location=
"Cleanup";
1398 cli_wand->filename=argv[0];
1399 if (cli_wand->wand.debug != MagickFalse)
1400 (void) CLILogEvent(cli_wand,CommandEvent,GetMagickModule(),
1405 while ((cli_wand->image_list_stack != (
CLIStack *) NULL) &&
1406 (cli_wand->image_list_stack->next != (
CLIStack *) NULL))
1407 CLIOption(cli_wand,
")");
1408 while ((cli_wand->image_info_stack != (
CLIStack *) NULL) &&
1409 (cli_wand->image_info_stack->next != (
CLIStack *) NULL))
1410 CLIOption(cli_wand,
"}");
1413 assert(cli_wand->wand.image_info == image_info);
1414 assert(cli_wand->wand.exception == exception);
1417 if ((cli_wand->wand.images != (Image *) NULL) &&
1418 (metadata != (
char **) NULL))
1427 text=InterpretImageProperties(image_info,cli_wand->wand.images,format,
1429 if (text == (
char *) NULL)
1430 ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
1431 "MemoryAllocationFailed",
"`%s'", GetExceptionMessage(errno));
1434 (void) ConcatenateString(&(*metadata),text);
1435 text=DestroyString(text);
1440 cli_wand->location=
"Exiting";
1441 cli_wand->filename=argv[0];
1442 if (cli_wand->wand.debug != MagickFalse)
1443 (void) CLILogEvent(cli_wand,CommandEvent,GetMagickModule(),
1447 cli_wand->wand.image_info = (ImageInfo *) NULL;
1448 cli_wand->wand.exception = (ExceptionInfo *) NULL;
1449 cli_wand=DestroyMagickCLI(cli_wand);
1451 return(exception->severity < ErrorException ? MagickTrue : MagickFalse);