Grayscale with ImageMagick
I use command-line ImageMagick's graphics file handling software. It usually rocks and it use to be easy and simple to use, for that I love it. However, I've been fighting now for more than one hour to get it right.
What I wanted was to convert to grayscale a set of JPEG files I had on a folder. There are a couple of annoying things with ImageMagick:
What I wanted was to convert to grayscale a set of JPEG files I had on a folder. There are a couple of annoying things with ImageMagick:
- Once you use wildcard as the command source file (i.e. mogrify -resize 1024x768 *.JPG) then it seems to take a long long time to work. The reason seems to be the command reads and stores in RAM all the files BEFORE the magic starts. The result is a poor user response time (and sometimes an almost frozen system if you run out of memory and all the time is used paging). I use to change to use a for loop instead, with some "progress information" (i.e. for i in *.JPG; do mogrify -resize 1024x768 $i; echo $i " done!"; done )
- I do not convert to grayscale every week, so I cannot remember how to it. Here is when the trouble starts because the easy way is somehow obscure and several Google searches did not give the right information fast enough. The simple way seems to be mogrify -type Grayscale image.jpg but I was fooled instead to use the -colorspace parameter which produced no visible results but a full-color image file. So you know, next time you want to use this old tool you better write down your "magic" commands before it is too late.
Comments
Thanks,
Miguel
ImageMagick is great, but I wish it had vaguely complete documentation.
I made this post as a reminder to myself after some frustration not finding the right way. Next time I'll give a try to your way.
Thanks.
mogrify -modulate 100,0,50 image.jpg
mogrify -verbose -resize 1024x768 *.JPG
It will tell what it's doing you as it goes along.
About slurping all the images into RAM before processing, it doesn't do that: I routinely convert batches of 300 images of 10 MB each... but it's 2009 and I use Linux, so something may be different.
I do use Linux too. Not sure what goes under the hood but it use to take a long time. I have not use it for a while and maybe the verbose option does help as you see that it's actually working.
+1
I've dried using -type Grayscale, -colorspace Gray and the -modulate command listed earlier, and they all output an image that is still indexed 2 color monochrome.
I need to convert to grayscale or RGB so that I can do some reasonable scaling and apply a blur. Does anyone know how to do this?
Maybe you want to apply a blur once you've switch from monochrome to grayscale so then the change will become visible too.
You can do a blur with imagemagik with -blur