打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
ImageMagick v6 Examples

ImageMagick Examples - Introductory Notes

What is ImageMagick? A No-Holds-Barred Summary

ImageMagick isdesigned for batch processing of images. That is, it allow you to combineimage processing operations in a script (shell, DOS, Perl, PHP, etc.) sothe operations can be applied to many images, or asa sub-system of some other tool, such as a Web application, videoprocessing tool, panorama generator, etc. It is not a GUI imageeditor.

ImageMagick is, first of all, an image-to-image converter. That is what it wasoriginally designed to do. That is, it will convert an image in just aboutany image format (tell us if it can't) to any other image format.

But it is also a library of image processing algorithms. These can beaccess via the command line and shell/DOS scripts (which these example pagesdemonstrate), or via a large number of programming languages, such as C, C++,Perl, Ruby, PHP, etc. See: ImageMagick APIs.

Speed was never a major feature of IM, which places more emphasis on thequality of the images it generates. That is not to say that it can'ttransform images in a reasonable amount of time. It's just not blindinglyfast. Because of this, IM can be slow to perform certain processingoperations, especially when attempting to compress images into image formatsthat have limited capabilities.

ImageMagick concerns itself mainly with images in the form of a rectangulararray of pixels, commonly called a "raster." It will handle "vector"image formats like Postscript or PDF, but at the cost of converting thoseimages into a raster when loading them, and generating a vector image wrapperaround the raster when saving it. As a result, vector images are oftenprocessed badly when using the default settings. However, specific optionscan be used to improve this situation. See: A word about vector image formats.

About These Examples of ImageMagick Usage

These pages were developed from, and are a continuation of, my Collection of ImageMagick Hints and Tips page I first started in 1993,and placed on the new fangled world-wide-web making its appearance around thesame time. Information on many aspects of IM, and notes not included in thesepages, are still present in that document. However, while the present pageswere designed for you to look at, the hints and tips document was only for myown edification. So, it may be vague or chaotic in places. You are welcometo look at it, learn, and make comments on it.

Other examples were grabbed or developed from answers to users' questions onhe IMForums, or contributed to me as solutions to various problems.

I look forward to suggestions and e-mail from other IM users. Such e-mailgenerally results in improvements and expansions to these example pages.

Command Line Environments

All examples are written for use on UNIX, and specifically GNU/Linux systems,using BASH scripting. As a consequence, some examples use shell 'for-do'loops. Most examples use a backslash '\' at the end of a line tocontinue that command on the next line. The longer commands are broken intoseparate lines to try to further highlight the steps being applied.

However, you can still use these examples from PC Windows batchscripts, with some changes to the handling of certain characters. Withsome slight adaptation, the examples can also be run directly from'system' calls in PHP scripts.

See Windows Usage and APIsand Scripting for more information on using the ImageMagick commands inthese alternative environments. Contributions and test examples are welcome.

PerlMagick, and Other APIs

It should also be possible to adapt any of these examples to use the IM APIfrom languages such as Perl, C, C++, Ruby, PHP, and so on. I recommend tryingthings out on the command line first, until you get them right, and thenconverting the operations to the specific API you are using.

Although the situation has improved enormously with IM version 6, the commandline really only deals with a single image sequence at any one time. However,APIs do not have this limitation, and allow you to manipulate multiple imagesequences, separately or together, to perform more complex operations. Thisability makes it simpler to implement these examples using the IM API, andremoves the need to save images as temporary files, as many of the commandline examples require. When using an API, only permanent and semi-permanentimages need be saved to disk.

Basically, let the example pages give you a start, to let you see whatis possible with ImageMagick. Then, formulate what you want to do onthe command line, before coding the operations in scripts and APIcode, where it is harder to make extensive changes.

I also recommend that you comment your API code, heavily, adding thecommand line equivalents to what you are trying to do, if possible. That way,you can check and compare the results against those using the command line.This lets you debug problems that you may come across later, especially asimprovements are made to image processing in the Core ImageMagick Library.

Downloading Input Images and Results

As much as possible, I try to use images built-into IM (such as"logo:" or "rose:") as input images for IM examplecommands, or to generate input images using IM commands. I also often re-usethe output of previous commands in later examples. Because of this, youusually don't need to download any 'test' images in order to try out theexamples yourself.

However, such generated or built-in images are not always convenient. So,when I do use an external image, I tend to re-use that input image, or theresults of previous examples, for later examples in that section.

Sometimes the original source image will be displayed or for larger imagesa link to the source image is provided. More commonly only the final resultingimage will be shown, as the input is well known or obvious.

Almost all the IM example commands shown are executed in the same webdirectory in which they appear. That is, the command you see is the commandthat was actually used to generate the image. Because of this you can modifythe page's URL to download or view the input image(s) used by an example.Extra copies of the external source images have also been placed in the "images" and "img_photos"sub-directories. See also the example of a Fancy Photo Index of those images.

If text output or image information is produced by an example, it is saved toa text file, and an image of it is generated for display on the Web page.Selecting the text output image will link you to a copy of the actual textoutput by the command.

In all these examples, selecting the output image should let you download theimage which was actually created by the example command. But be warned, notall browsers understand all image formats used.

External Image Sources

By the way, most of the source images used in these examples come from Anthony's IconLibrary, particularly the background tiles, largeclip-art, and dragons sections of the library. (I like dragons!)

This library actually predates the WWW. I created it in 1991, due to the lackof good, clean iconic images for use on the X Window System. The advent ofthe WWW has of course changed this, but my original library still exists andremains available as a source of images, even though it is not activelygrowing.

Some specific images, and larger images, are contributed by the authors ofspecific examples. The authors of such examples are listed in the contributedsection, or at the bottom of the page.

If you are looking for a specific image, I recommend using Google Image Search (or similar) tofind something appropriate. You can, of course, convert or resize such imagesusing IM for your own purposes. However, you should be careful aboutcopyright if you plan to use such images commercially.

PNG Images on Web Pages

In many examples, I use an image in PNG format, such as that shown to theright of this text. The PNG image format supports images withsemi-transparent pixels, a feature few other image formats provide. It isalso a very well-understood image format and, as such, is usable by most oftoday's image programs and Web browsers.

Some Web browsers, however, do NOT handle transparent PNG images correctly(most notably Microsoft Internet Explorer v6). Because of this, I generallyuse the JPEG and GIF formats for images on the Web, and only use the PNGformat when generating images with semi-transparent pixels, or when exactcolors are needed for later examples.

To allow IE v6 browsers to display PNG images, I use a special 'style sheet'using complex JavaScript. For information on this, see PNG withtransparency for IE. Technically, this is only problem with IE, notImageMagick.

Displaying Images on Your Screen

Display problems can also occur when displaying images on-screen. Because ofthis, I recommend using a command like the following to tilea 'checkerboard' pattern underneath the image, to highlight anytransparent or semi-transparent pixels in it.
    composite  -compose Dst_Over -tile pattern:checkerboard image.png x:

The image displayed in the above example is a special PNG-format test image, which was generated using the shellscript "generate_test".Normally, the command would output the results to your display, not onto a Webpage like this.

If you look carefully, you can see the checkerboard pattern though thesemi-transparent colors. However, the image, as a whole, is fully opaque. So,this technique should work on all displays, Web browsers, and image viewers.

As of IM v6.0.2, the "display" program performs something likethis automatically. However, it does not seem to handle images using colortables (i.e., GIF) in this way. Using the "x:" output image format(as above) causes an image to be displayed directly to the screen, withouthaving to save it. See Show Output Display for moreinformation.

Font Usage

The fonts I use in these examples are from a small collection of TrueType fontsI have found over the years, and saved for my own use. Some of these are undercopyright, so I cannot publish them online.

You are, however, welcome to substitute other fonts that you have available.The examples should work (perhaps with some changes to image size) with anyappropriate font you have available on your system. Microsoft "Arial" font, oreven "Times-BoldItalic", should work on most systems.

To see what fonts are currently available to your version of IM, run thefollowing command...

    convert -list type       # for IM older than v6.3.5-7    convert -list font       # for newer versions

WARNING: If the font requested is not found, ImageMagick used to silentlysubstitute a default font, typically Arial or Times. It still does this, but awarning is now given. So, test the font beforehand, to make sure that it isthe one you want, and not the default font.

On my Linux system, I use a special Perl script, "imagick_type_gen", togenerate a file, "type.xml", saved in the ".magick"sub-directory of my home directory. ImageMagick uses that file, which containsa font list in XML format, to find fonts. The script "locate"s(run "updatedb" first, if you have just added new fonts), anddescribes all the fonts available on my system. With this setup, I only needto specify the name of the font I want to use, and not the full path to aspecific font file.

For example...

    # Instead of using the command...    convert -font $HOME/lib/font/truetype/favorite/candice.ttf             -pointsize 72 label:Anthony  anthony.gif    # I can use the simpler font label...    convert -font Candice -pointsize 72 label:Anthony  anthony.gif

Before IM v6.1.2-3, the "type.xml" file was named "type.mgk". If you are using an earlier version of IM.

The fonts used in these IM examples are listed in a Montage of Example Fonts Example. Mypersonal favorite is Candice, so it gets used quite a bit.

If you also like the 'Candice' font, or any of the other fonts I use, grab them from Free Fonts or 1001 Fonts .com.

Example Page Updates

These example pages are in an on-going cycle of improvement. Generally, I findI stop adding to these pages for long periods of time, when my interests becomefocused on other things.

Often these examples are re-built using the latest beta release of IM, allowingme to see changes and bugs that may appear in each version of IM, before it isgenerally released. However, the example images shown are what the given IMcommand produces on my system. If you get something different, your IMis probably a much older version (with old bugs), or is not correctlyinstalled.

Note that e-mailing me, or discussing some aspect of ImageMagick on the IM Mailing List,or IM Users Forum will generally result innew examples, or whole new sections, being added to these examples. The morediscussion there is, the better the examples become.

If you are doing anything interesting with IM, please share, and allow me toprovide examples of your technique to the rest of the IM community. Some of thebiggest advances in IM usage have come from users just like you.

Special Thanks

A special thank you goes to Cristy, who has tirelessly spent months, upgrading,bug-fixing, and putting up with my off-the-wall suggestions... especially withregards to my major suggestions for the command line processing, parenthesis,image sequence operators, and GIF animation processing.

He has done a marvelous job making Version 6 the best and most advanced commandline image processing program available. While most users will not showappreciation for that, I certainly do appreciate the effort he has put into IM.

I also want to thank Gabe Schaffer, who has been most helpful in discussionsinvolving the JPEG format and library, affine matrix operators, and MagickVector Graphics in general.

And to Glenn Randers-Pehrson, who looks after the PNG coder module and has ainterest in Color Quantization and Dithering. He was the first to add'halftone' dithering to IM, which I later revised and extended further, toadded new dithers to the ordered dither configuration file.

And finally, I want to thank the huge number of people with problems,suggestions, and solutions, who generally lurk on the IM User Forum. Many now have their names ascontributors of ideas and suggestions throughout IM Examples.

I also want to thank the people who regularly answer questions on the forums,such as 'Bonzo', and his web site RubbleWebs, detailing useof IM commands from PHP scripts. Also 'scri8e' and his Web site, MoonsStars, for glitter and star handling. Also a thank you goes to Pete 'el_supremo' (see his MagickWandC-Programming), and the many others who regularly answer other peoples'questions.

A special thanks goes to Fred Weinhaus, a researcher from the early days of image processing, whowas a major help in the initial implementation of the General Image Distortion Operator. You can seeFred's ImageMagick scripts on Fred's ImageMagick Site, often as a proof of concept for future IMadditions.

Also to Nicolas Robidoux, an expert in digital image processing, for reworkingthe Elliptical Weighted AverageResampling, which vastly improves the output of General Image Distortion.

And finally to the many users of ImageMagick who, had allowed others to seethe IM commands they use as part of some project, either on the forums, or onthe web. You are all to be commended on your willingness and openness to shareyour findings.



Well enough "Yadda, yadda, yadda."   Go look at some of the examples.

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
.net core 2.2 使用imagemagick 将pdf转化为png(示例代码)
ImageMagick使用for java(im4java)
imagemagick
Magick 1.0:高级图形和图像处理R
如何在运行时改变App的图标
ImageMagick
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服