Slashdot Mirror


Graphics Tricks from the Command Line

An anonymous reader writes "There's nothing quite like command-line tools for handling large batches of tasks, and image manipulations are no exception. Web developers and administrators will appreciate the ability to handle large numbers of files easily, either at the command line or in scripts. This article presents the ImageMagick suite, a Linux toolkit for sizing, rotating, converting, and otherwise manipulating images, in a huge number of formats, whether one or a hundred at a time."

68 comments

  1. Useful... by Kiriwas · · Score: 3, Insightful

    This seems like it could be useful for easy and fast (not always smart) integration into Web Applications. Its far easier to make a call to a command line image manipulation software than to call a library and do all the work yourself. Though I suppose with calling an application for the web, there may be security problems.

    1. Re:Useful... by GigsVT · · Score: 2, Informative

      I use it with a reverse proxy system. My web app on the internet facing server runs a PHP script that makes a HTTP request to an internal host that does the image processing.

      Done this way, it mitigates most security risks. I still scrub the data that can be influenced by the user, just in case.

      --
      I've had enough abrasive sigs. Kittens are cute and fuzzy.
    2. Re:Useful... by JimDabell · · Score: 2, Informative

      Its far easier to make a call to a command line image manipulation software than to call a library and do all the work yourself.

      Not particularly. For instance, with PHP:

  2. Gallery by L.+VeGas · · Score: 4, Informative

    ImageMagick is used quite a bit with online photo galleries. Here is one of the most popular.

    1. Re:Gallery by crisco · · Score: 4, Informative

      While it's true that ImageMagick is used quite often for online photo galleries and that Gallery is very popular, Gallery doesn't use ImageMagick (except for the forthcoming v2.0). Instead, it uses NetPBM, another set of opensource image manipulation tools that deserve a little pimping along with ImageMagick.

      --

      Bleh!

    2. Re:Gallery by L.+VeGas · · Score: 4, Informative

      Not true, but an understandable mistake.

      The latest version of Gallery (1.3.4) can and does use ImageMagick as well as NetPBM. I know many that have it running on their sites. It's just that Gallery's documentation is poor and rarely updated.

  3. XV by martin · · Score: 1

    and this differs from XV how - apart from maybe an API..

    1. Re:XV by ivan256 · · Score: 2, Insightful

      Well, for starters 'xv' is not free software and you have to purchase a license for non-commercial use, while ImageMagick is distributed under a BSD style license...

      Do you have some code to change now?

    2. Re:XV by ivan256 · · Score: 1

      Well, for starters 'xv' is not free software and you have to purchase a license for non-commercial use,

      Duh. I meant you have to purchase a licencs fo commercial use. It's 'free as in beer' for non-commercial use.

    3. Re:XV by Anonymous Coward · · Score: 0

      The difference is that XV rocks and ImageMagic doesn't as much. I've used them all, and XV and GIMP are easy to load, lightweight, quick. XV rules.

  4. I Love Image Magick! by szyzyg · · Score: 4, Interesting

    I used to use it a lot back when I was doing astronomy, I used to make movies and I wrote a load of scripts for IM which basically worked on directories full of jpegs to do crossfades, motion blur, and all sorts of other effects. Some of these movies of asteroids and comets still make it onto the occasional TV slot. The originals were rendered in POV ray, but IM was more important since it was essential for editing and compositing.
    It still runs today producing the map of asteroids (http://szyzyg.arm.ac.uk/~spm/), even though I've moved on a long time ago.
    For a while I even used ImageMagick as the core for a webcam motion detection program - rescale, blur, edge-detect, subtract differences and then count the total intensity of the output image - it worked pretty well, although it was a little slow.

    I think I've created more art with ImageMagick than I've done with the Gimp.

  5. Wonderful program by digerata · · Score: 4, Interesting
    I've used ImageMagick for a few years now, mostly for image processing on the backend of web application. It is great as far as the shear number of file formats it supports. I haven't seen any other 'free' application out there that does what ImageMagick does. Its speed is okay compared to commercial equivalents such as Image Alchemy.

    But the downfall of Image Magick is the installation. It is the most god awful spaghetti mess of all time when it comes to its dependancies. You see, what they don't tell you right off the bat is ImageMagick doesn't actually work with the file formats internally. AFAIK, it relies on all of the format specific libraries out there. If your application is hosted by a virtual hosting provider, good luck getting all that installed.

    Once it *is* installed, however, IM rocks.

    --

    1;
    1. Re:Wonderful program by Tolchz · · Score: 2, Informative

      You can install the libraries yourself. ./configure --prefix=/home/myusername/magicklibs/

      Then specify the location when you compiler ImageMagick.

    2. Re:Wonderful program by cattlepr0d · · Score: 1

      "It is the most god awful spaghetti mess of all time when it comes to its dependancies."

      Unless, of course, you're running it on FreeBSD...

      --
      R Tape loading error, 0:1
  6. Tiff libraries (little OT) by FroMan · · Score: 1

    At work we often work with multipage tiff images (~650MB) that we need to pull individual images out of. We currently have a poorly implemented hack to do it, but I am looking to find a better library to do this. I was wondering if anyone has a decent java library that they know about.

    Ideally something that works with msjava (java 1.1). I know in java 1.4 there is jai, but atleast immediately that does not seem to be a very understandable api.

    Anyways, we'll see if this gets any hits.

    --
    Norris/Palin 2012
    Fact: We deserve leaders who can kick your ass and field dress your carcass.
    1. Re:Tiff libraries (little OT) by hnoon · · Score: 1

      I've used JIMI before and it worked like a charm. I used it for basic resizing and cropping. Keep in mind though that it is outdated. You should probably hack away at JAI until you get it right.

    2. Re:Tiff libraries (little OT) by fingal · · Score: 1

      Why not use JMagick which is a JNI wrapper around some of the functionality of ImageMagick?

      --

      The only Good System is a Sound System

    3. Re:Tiff libraries (little OT) by Anonymous Coward · · Score: 0

      Why not stab out your eye?

    4. Re:Tiff libraries (little OT) by Anonymous Coward · · Score: 0

      At work, they use ImageGear to do similar stuff. It's commercial, but seems to work pretty well. http://www.accusoft.com

  7. It's great! by wizs · · Score: 2, Interesting
    IMHO, it is great that image processing software provides a set of command-line programs. It is easy to extend the functionalities of the software by writing some scripts that utilize those command-line programs. I did write some perl scripts that combine some command-line programs of ImageMagick. These scripts help me to organize a lot of images taken by DC. They do great jobs.

    I also expect some commercial image procssing software (e.g., Adobe photoshop) may export some command-line programs.

  8. netpbm tools? by battjt · · Score: 1

    Can anyone compare IM to the pbm tools?

    --
    Joe Batt Solid Design
    1. Re:netpbm tools? by Alan+Shutko · · Score: 3, Informative

      ImageMagick has all conversion type stuff in one "convert" program, so you don't have to pipe stuff between fifteen programs to get things done.

      OTOH, ImageMagick loads the entire file into memory to do its work, so on really big files you are better off shipping it through the pipe. (I've got a 150MB JPG around here that chokes convert, but pipes through netpbm great.)

      I like to have both on my machine.

    2. Re:netpbm tools? by Unordained · · Score: 2, Interesting

      on a web-app project i got to play with in mid-devel ... image-magick was used to convert from TIFF to GIF (i think) output. the problem was speed -- it loaded the entire image into memory in its own internal format. the problem is that the TIFF files were enormous, but they were black/white scans of documents. the final gif was also low-color, and scaled down ... but in-between, it was converting to full 24-bit color (with alpha?) and other overhead.

      in the end, (after we had left and done our part of the job) someone else (team lead) changed the code to a customized piece that resized the file as it streamed through, directly from TIFF to whatever output format was being used ... MUCH MUCH FASTER.

      image magick is neat -- lots of formats. but it's a lot of overhead in situations where you need speed. specialized tools (format_a2format_b) are of great help at that point.

    3. Re:netpbm tools? by Anonymous Coward · · Score: 0

      I have used both tools in my shell scripts, and I find that netpbm is a much better tool. Sorry ImageMagick.

    4. Re:netpbm tools? by nuba · · Score: 1

      I too tried to use IM for large scale commercial tiff and pdf work and found it lacking quite a bit in the area of speed :( And even loading a few moderate sized tiffs -> mp tiffs created gb sized temp files before they were reworked. Windows shareware could do the conversions easily 100x faster. We really need _good_ tiff and pdf software

    5. Re:netpbm tools? by Mikal · · Score: 1

      IBM DeveloperWorks also has articles on coding for TIFF (Intro, and Advanced) which might be of use. There are also many open source PDF APIs out there, including Panda.

  9. Hue by JohnFluxx · · Score: 1

    I used to this to change the hue of a load of pictures.

    I broke a picture of a map down into all the edges (roads) and then changed the images into various different hues.

    Now in a web page, you can see the roads change colour :)

  10. Not hard at all to install by metalhed77 · · Score: 1

    Most distros of linux come with IM as part of their main / stable distros. I've used it with Gentoo and debian via apt and emerge respectively, no problems. Redhat and Mandrake have it too! The windows version comes precompiled / statically linked, so that's no big deal. What were you using?

    --
    Photos.
    1. Re:Not hard at all to install by Thornae · · Score: 2, Insightful

      ...and, of course, FreeBSD has it in the ports tree. You would be amazed at the number of graphics (and other) ports that pull in the latest version of ImageMagick as a dependancy.

      Mind you, NetPBM isn't under-represented, either.

      --
      |>
      Here be Dragons
    2. Re:Not hard at all to install by dave_f1m · · Score: 2, Insightful

      And of course, Windows. I wrote some stuff for a photographer with Perl,Tk, and ImageMagick, and it works fine on her W98 machine. Well, I would prefer something nicer than Tk, but it seemed like that was the best choice for cross platform with Perl.

  11. DeskTop Backgrounds by sirket · · Score: 1

    I have a three head desktop and I needed some cool backgrounds. Unfortunately, the desktop is a single large canvas and not three smaller ones. I have a small script that grabs 3 random images from my backgrounds directory (mostly images from Digital Blasphemy) and stitches them together to form a single large background image.

    -sirket

  12. if only graphs were pretty by AssFace · · Score: 1

    I have been trying to automate some tasks here where the end results are graphs.
    The problem is that for Joe Nerd, the output of a scripted graph is "good enough" - I use GD for a lot of things and it looks fine and is fast enough to be generated on the fly.

    But my current need is to get graphs that look really good so that they can be used on a brochure type site, but can be updated frequently with the most recent market data (not updated in real time, every time the page is loaded - but updated by a script every month).

    My current process is to use Excel sice its graphs are customizable enough and look pretty good in the end. But the process unfortunately doesn't really lend itself to automation. (create graph in Excel, take screen capture, dump to Photoshop, tweak, dump to png)

    ImageMagick is very useful for many things though, and you can do some suprisingly good looking stuff with it.
    I have mainly ever used it for adding text to a whole lot of images, and also for converting images en masse.

    --

    There are some odd things afoot now, in the Villa Straylight.
    1. Re:if only graphs were pretty by Anonymous Coward · · Score: 0

      Its graphs are kind of plain (no shading or whatever), but Gnuplot is really nice for graphs where the information is more important than a "pretty picture".

      - chad

    2. Re:if only graphs were pretty by spongman · · Score: 1

      You can automate Excel (and most other office apps) quite easily.

      Here's an example JScript script that creates a graph:

      var excel = new ActiveXObject ("Excel.Application");
      var book = excel.Workbooks.Add ();
      var sheet = excel.Worksheets (1);

      sheet.Range ("A1") = "foo";
      sheet.Range ("B1") = "bar";
      sheet.Range ("C1") = "goo";

      sheet.Range ("A2") = "1";
      sheet.Range ("B2") = "2";
      sheet.Range ("C2") = "3";

      var chart = sheet.ChartObjects.Add (100, 100, 200, 200).Chart;
      chart.ChartWizard (
      sheet.Range ("A1:C2"), // source
      -4102, // Gallery: xl3DPie
      7, // Format:
      1, // PlotBy: xlRows
      1, // CategoryLabels
      0, // SeriesLabels
      1, // HasLegend
      "Example Graph"
      );

      chart.Export ("c:\\chart.png", "PNG", false);
      book.Close (false);
      excel.Quit ();

    3. Re:if only graphs were pretty by Anonymous Coward · · Score: 0

      If you want scripts that produce nice-looking graphs, then check out "R" (http://www.r-project.org/). With just a little effort, you can make graphs that look hundreds of times better than Excel will ever achieve. There are, of course, other tools besides R, for example, S and MATLAB. I merely mention R because it is free and I know by experience that it can make nice graphs.

    4. Re:if only graphs were pretty by AssFace · · Score: 1

      Interesting! Thanks.

      I have done that in the past, but for whatever reason (stupidity on my part?), I haven't seen the Export functionality. Very useful.

      I will have to play with it to see about font size, weight, and positioning - but that looks like that would be quite nice.

      Thanks again.

      --

      There are some odd things afoot now, in the Villa Straylight.
  13. Life saver! by unfortunateson · · Score: 3, Interesting

    Imagemagick made me look like a miracle worker.
    10,000 1.5MB bitmaps had to be delivered to the Food and Drug Administration in their original format and resolution (they needed to see things exactly as they were reviewed in a drug safety study), but wanted a visual 'menu' of the images, by patient over time.

    Using the index of the images, I was able to create a labeled page-per-patient visual menu in PDF (FDA's preferred format -- but it would be a 3-character change to make it anything else). Using other tools, the same index was munged into a CSV file that was applied as hyperlinks atop the PDF menu (non-Open-Source tool, but I might have been able to find an open-source one).

    In one day, the entire set of 15GB of data could be processed. In fact, putting it on a tape took longer than the image assembly.

    --
    Design for Use, not Construction!
  14. PIL by SeanAhern · · Score: 2, Interesting

    For those of you who use python, you might want to check out the Python Imaging Library, or PIL for short.

    After using many, many different tools for this type of thing (including IM, netPBM, GD, and my own tools), PIL has by far become my favorite for image processing.

    Check out this simple tutorial for some examples of what you can do.

  15. it's free by Xtifr · · Score: 1

    It's free software, and therefore, it comes with my system (Debian) while XV doesn't. I can use it for my commercial website, or sell someone a system using it (a commercial transaction) without worrying about license fees. And it's been updated more recently than 1988! :)

    Oh, and it has that API and a library that third-party apps use directly, so having XV on my system would involve a lot of redundancy, while having ImageMagick just means a small app that uses the already-installed library.

  16. Keynote on the Mac by daviddennis · · Score: 1

    If you have access to a Macintosh, or can squeeze out the budget for one, consider Keynote, Apple's fancy presentation program.

    The files are in XML, so they would be a snap to generate them through scripts, and the display engine produces stunningly beautiful graphs.

    The graphs are so much prettier than Excel's it isn't even funny.

    If you play with it at an Apple Store, I think you'd get sold on it pretty quick.

    Hope that helps.

    D

  17. Linux?? by Jon+Peterson · · Score: 2, Interesting

    "This article presents the ImageMagick suite, a Linux toolkit for sizing..."

    WTF has this got to do with Linux? AFAIK IM pre-dates any kind of wide-spread use of Linux. IM compiles on most unixes and is available for mac, win32, vms and more. It has nothing to do with Linux.

    Sigh.

    --
    ----- .sig: file not found
    1. Re:Linux?? by Mikal · · Score: 2, Informative

      I think you'll find that the article is written that way because it is taylored for the IBM DeveloperWorks Linux site. It's not a comment on the Linuxness of IM.

  18. Re:cat myBinaryFile.jpg by mph · · Score: 1

    1) What's this got to do with ImageMagick?

    2) How do you cat something to "stdio"?

  19. create multi-page PDFs by markjugg · · Score: 3, Informative
    ImageMagick can also be used to convert several image formats into a multi-page PDF. I used this just recently:

    convert -adjoin photos*.jpg one_big.pdf

    1. Re:create multi-page PDFs by Mikal · · Score: 1

      The PDFs created by ImageMagick aren't perfect however. You're much better off as a developer using one of the many APIs available for doing that sort of stuff.

  20. aah, but can it stitch images together? by Unominous+Coward · · Score: 1

    Say I give you two images where a portion of one on the edge is identical to a portion of the other on the opposite edge. I want to stitch these together to get one big image which seemlessly overlaps the two?

    How would you go about this?

    --
    "Smoking helps you lose weight - one lung at a time" -- A. E. Neumann
    1. Re:aah, but can it stitch images together? by fizbin · · Score: 1

      That's what the command montage, part of the IM suite, is for. Check (as always) the man page for montage, and look at the -chop option (which lets you cut out rows or columns from one of the images before sticking them together).

  21. Re:cat myBinaryFile.jpg by Istealmymusic · · Score: 1
    I'm not the OP but I can answer your Q's.
    • 1) Presumably there is no direct link, although ImageMagick has to do with images and so do JPEGs. An indirect link, if you will.
    • 2) man cat (this won't let you cat something to stdio, but it will tell you about cat and how to use it). The OP probably meant "stdin" instead of "stdio", its an easy typo to make, but then he would be wrong too. Stdin is one-way. My best guess is "stdout", and cat cats to there by default (always?). Regardless, we may never know; I doubt jpsst34 will respond so this fodder may be the best we have.

    Secondly, the OP clearly made this rediculous post to plug Cygwin, causing Linux to invade Windows. Maybe he's been using Linux too much and wants the safe comfort of a Linux-emulated Windows environment. In any case, the same effect can be achieved by typing "type myBinaryfile.jpg" at the command prompt.

    The file doesn't even have to be a JPEG; this is one of the great virtues of the cat/type duo. They are one of the few programs which surpass the image format support of ImageMagick.

    --
    "The lesson to be learned is not to take the comments on slashdot too literally." --Vinnie Falco, BearShare
  22. Graphic, huh? by Anonymous Coward · · Score: 0
    8 >-
    I think that's pretty graphic. It's supposed to be a naked lady.
  23. netpbm is much better by Anonymous Coward · · Score: 0

    netpbm is much better than image magick

  24. Raw CCIT G.4 anyone ? by Onanismous+Coward · · Score: 1

    I'm a big fan of ImageMagick, use it mostyly on Windows and haven't encountered any install problem some earlier post related, if you know how to press a "next" button that's well enough...

    Now one thing I've been looking for is something to let me read RAW (headerless) CCIT G.4 (fax-type encoding),ImageMagick doesn't support it and the few free tools I found didn't work quite well. Anybody got recommendations ?

    1. Re:Raw CCIT G.4 anyone ? by Mikal · · Score: 1

      That wouldn't be that hard to code. There is very similar code in PandaEdit which you're welcome to borrow. Look at the fax.cpp, fax.h, and faketiff.h...

    2. Re:Raw CCIT G.4 anyone ? by Onanismous+Coward · · Score: 1

      Thanks for the link, definitely cool stuff ! I agree with you that it shouldn't be too hard to code it myself but I cannot find any free reference available and you have to pay $100 or so to get the official one...

    3. Re:Raw CCIT G.4 anyone ? by Mikal · · Score: 1

      The TIFF specification is available for free from http://developer.adobe.com

  25. EXACTLY! hehe by No-op · · Score: 1

    I'm glad someone else pointed that out so I didn't have to...

    I dunno about you, but...

    cd /usr/ports/graphics/ImageMagick ; sudo make install

    isn't all that hard to do, now is it ? :)

    --
    EOM
    1. Re:EXACTLY! hehe by jo42 · · Score: 1


      pkg_add ImageMagick-5.5.6.tgz is even easier...

  26. question by larry+bagina · · Score: 1

    Could this utility be used to convert gif imageds to png? I understand this is very difficult (since Slashdot still uses gif images), but hopefully, someday there will be a way to convert gifs to png format.

    --
    Do you even lift?

    These aren't the 'roids you're looking for.

  27. colour conversion by Coneasfast · · Score: 1

    I've used it quite a bit, seems to be a bug in colour conversion though (at least in version 5.5.4).

    I found that it has problems converting an image to 256 color. It seems to mess up conversion of pixels with alpha transparency. The fix I found was to convert to gif format, then back to png (which automatically converts to 256 colour).

    This may be fixed in later versions though.

    --
    Marge, get me your address book, 4 beers, and my conversation hat.
  28. Re:Does this by Anonymous Coward · · Score: 0

    They're both FREE (as in herpes).

  29. Just curious... by Wolfrider · · Score: 1

    What in the world is that 150MB JPG a picture *of?*

    --
    .
    == WolfriderV6 == I'm willing to admit that *I just might* be wrong... Are you??
    1. Re:Just curious... by Alan+Shutko · · Score: 1

      It's a 20"x30"@300ppi photomosaic I put together for my sisters, of shots I took in and around her wedding. It's JPEG since ophoto wouldn't accept tiff.

  30. MOD PARENT UP by Wolfrider · · Score: 1

    +4 Informative

    --
    .
    == WolfriderV6 == I'm willing to admit that *I just might* be wrong... Are you??
  31. What about the GIMP? by Ed+Avis · · Score: 2, Interesting

    ImageMagick is great but I always feel that the same functionality must already be present in the GIMP, and it seems rather wasteful to have to learn two different tools to do the same job.

    The GIMP is scriptable with Scheme or with Perl or other languages... perhaps all it needs is a good set of command-line interfaces as well?

    --
    -- Ed Avis ed@membled.com
  32. Not "a Linux toolkit"! by Junks+Jerzey · · Score: 1

    From the ImageMagick site:

    ImageMagick is quite portable, and compiles under almost every general purpose operating system that runs on 32-bit or 64-bit CPUs. ImageMagick is available for virtually any Unix or Unix-like system, including Linux. It also runs under Windows '95 and later ('95, '98, ME, NT 4.0, 2000, and XP), Macintosh (MacOS 9 and 10), VMS, and OS/2.

    Once again, remember that freely available software, and software that comes with the source code, is NOT a Linux-specific phenomenon. In fact, just about any decent piece of software that runs on top of the Linux kernel can--and already has, in most case--be easily ported to any other popular operating system. Windows developers commonly make use of Perl, Python, Tk, and so on.

    I know this sounds somewhat pedantic, but I want to make clear that "Linux" is a *kernel*. Advocates usually forget this. Well-written software is not tied to a particular OS kernel.

  33. poser fag shows skillz as a FUCKING OFFICE H4X0R by Anonymous Coward · · Score: 0

    r u a l33t h4x0r? oh yeah baby, you sure look like it showing those SKILLAH skillz yo boi-yee.

    show the plebians how you fucking get down with MICROSOFT OFFICE. Did Miguel Icaza congratulate you on this fucking useless code sample

    you must be a project lead baby. show the WORLD you mean BUSINESS MOTHA FUKAAA yeah! hahahaha