Convert images with open source ImageMagick
Takeaway: Vincent Danen introduces you to a handy, lightweight tool for working with images.
Tools like the GIMP and similar graphical applications are great for modifying and manipulating images. Sometimes, however, they can be overkill for little things that need to be done, such as converting file types or resizing images. As well, a graphical tool can be time consuming and difficult to script, unlike CLI tools.
The ImageMagick suite of programs allows you to manipulate images from the command-line, making it much simpler to convert large numbers of pictures or even for that single quick image conversion.
Some of the tools that ImageMagick includes are the convert tool, the composite tool, and the display tool.
The convert tool is used to convert pictures from one format or size to another. The easiest method is to simply convert an image from one format to another using:
$ convert image.jpg image.png
This will convert image.jpg from a JPEG to a PNG and save it as image.png. To convert and resize an image, use:
$ convert -size 50x50 image.jpg image.png
This will convert from JPEG to PNG format and resize the resulting image to 50x50 pixels. Likewise, you can use convert to rotate an image:
$ convert -rotate 90 image.jpg image.png
This will rotate the image 90 degrees and convert it to a PNG file. To manipulate the file and keep it in the same format:
$ convert -rotate 90 image.jpg image-new.jpg
To create a composite image, or layer one image above another, use the composite tool. For instance, to put logo.jpg in the top-left corner of image.jpg, you would use:
$ composite -gravity NorthWest logo.jpg image.jpg composite.jpg
This will layer logo.jpg over image.jpg in the top-right corner (NorthWest), and the resulting file will be named composite.jpg. Each edge of the picture is noted by direction: Top is North, bottom is South, right is East, and left is West. The composite tool respects transparent pixels, so using it is a great way to automatically tag all your photos with your name or Web site address.
These commands merely scratch the surface of what ImageMagick can do. ImageMagick is capable of creating new images, embedding steganography in pictures, and much more.
Delivered each Tuesday, TechRepublic's free Linux NetNote provides tips, articles, and other resources to help you hone your Linux skills. Automatically sign up today!
White Papers, Webcasts, and Downloads
- The Journey Along an Information-Led Transformation IBM Corp. The cost of embedding information technology into every device we ... Download Now
- Business Value of Windows Server 2008 R2 Hyper-V and Live Migration Microsoft Today's IT departments are under increasing pressure to manage and support ... Download Now
- Service Management Resource Center IBM Corp. This buyer's guide provides assistance in evaluating identity and access ... Download Now
- Enabling Device-Independent Mobility with Dynamic Virtual Clients Intel Intel IT is investigating a model where users can access their ... Download Now
- Fundamentals of Volume Activation Microsoft Volume Activation is a set of activation methods applicable to systems ... Download Now
Article Categories
- Security
- Security Solutions, IT Locksmith
- Networking and Communications
- E-mail Administration NetNote, Cisco Routers and Switches
- CIO and IT Management
- Project Management, CIO Issues, Strategies that Scale
- Desktops, Laptops & OS
- Windows 2000 Professional, Microsoft Word, Microsoft Excel, Microsoft Access, Windows XP,
- Data Management
- Oracle, SQL Server
- Servers
- Windows NT, Linux NetNote, Windows Server 2003
- Career Development
- Geek Trivia
- Software/Web Development
- Web Development Zone, Visual Basic, .NET
