Episode: 72
Title: HPR0072: Imagemagick
Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr0072/hpr0072.mp3
Transcribed: 2025-10-07 11:01:13

---

I'm-
Hi neighbor, today Trolley Trolley is going to take us to the mystical world of image magic.
That's right, today we're going to talk about all the different incantations you can cast
on your friend's images, incantations.
It's a big word, do you see incantations?
She can't and now we'll go to the grand wizard himself, clap two.
Hi clap two.
This is hacker public radio.
This is clap two and I've been playing around with a lot of images lately.
For one reason or another it seems like I'm putting together images to send to someone
or I'm designing a logo for something and I have been using a little program that you may
or may not have called image magic.
It's i-m-a-g-e-m-a-g-i-c-k.
It's easy enough for you to get, you can have to get install image magic,
get it from your repo, download it from the website, it may even be cross-platform.
But either way it's a great little application that is essentially a command line centered image manipulation program.
Now that might seem a little bit strange.
One doesn't equate image manipulation necessarily with the command line.
But imagine this.
If you have a number of images and you need to scale them down so that you can upload them to a website or email them to someone.
Traditionally you might take it into the gimp and you might go into image size and scale it down and then you can save it out again as maybe a copy.
And then you can do that a couple of times.
And maybe you might even be like really creative and maybe you could come up with some kind of shell script to be able to do much of that work for you.
But with image magic you basically can just cut out the gimp entirely.
So if you have a folder of 300 images that you're trying to upload and you need thumbnail versions of each, this is the program for you.
The other cool thing about image magic is that you can integrate it with scripting languages like Pearl or Ruby, Python, C of course, C++.
You know all those good programming languages, you can use image magic, you can call that from those languages so that even on the server side for instance you could have image magic kind of doing something, you know someone uploads an image to your site and you need it to be automatically resized for them.
You need to change it in some way, maybe you're going to turn it black and white for them or something or maybe you want to give it rounded corners so that it kind of fits the style of your site.
You can do all of that kind of stuff with image magic with a simple, you know, a PHP script or something like that.
So it's a really powerful little program. It's also a little bit odd because image magic is actually the name of the package rather than the program that you're going to invoke from the command line.
There are about, I don't know about, about eight different programs in image magic. I think I've used pretty much all of them for one thing or another.
There's convert, identify, magraphy, composite, montage, compare, display, animate, import, and conjure. That's actually like 10 I think.
So convert is a lot of these do the same thing, but there's some kind of variation. So convert, for instance, will take your image and do whatever you want it to, but it does it to a copy. It outputs the file to a copy so you're not changing your original image.
That's handy for certain things, especially if you're going to do thumbnail versions of stuff. You obviously don't want to lose the full size quality. Identify will give you all kinds of information about an image.
Magraphy is just like convert, except it does it to the original image. So if you want to just take a whole bunch of pictures and scale them down and turn them black and white, you can do that with magraphy. You won't have any extra files lying around afterwards. It just changes the actual image.
Composite will, well, composite images, so it's like overlaying an image and messing with transparency and things like that. Montage will tile images. That one I have not used, actually. Compare, displays, an image or an image sequence, animate will animate an image sequence.
So if you want 30 pictures to play in quick succession, that would be animate. Import is basically a screen capture. And that's a cool one because you can actually use import. For instance, if you have no GUI up at all and you want to take a picture, a screenshot of the text console that you're running at that moment, import would be the way to do that.
And the last one that also I've not used is conjure. That is the interface for the scripting language that image magic uses, which I believe is called mith-m-i-f-f. And you would use conjure to do the kind of scripting that image magic allows you to do.
Obviously, you can always do your own. Like I say, it's completely compatible with all kinds of programming languages. So if you've got a Python script that you're writing and you want to do something with image magic, there's no need to learn image magic built in scripting language.
Okay, let's do some interesting image magic tricks. First thing we'll do is take a photo of a text console because how often have you been in a text console, and either you're having a problem because you can't get X to start or something like that, and you want to record what the problem is.
Or maybe you've done something really cool in programming class, and you don't have X up. You're just using a normal console. So what you can do is use the import command.
So again, import is part of image magic, and the way it would work is you'd put import, space, dash, display, space, colon, zero, dot, zero, space, dash, window, space, root, space, screenshot, dot, png.
And that will take a snapshot, a screenshot of the current display, the window that you're looking at, the root window, and name it screenshot dot png.
Now, if you wanted to do that without the command being on screen, the import command actually being on screen, then what you would have to do is switch over to another virtual terminal.
So if you're in virtual terminal one, you'd switch over to virtual terminal two, you'd log in, and then you'd do like a little bit of quick switching. You'd do like a CHVT space one, which would get you back to virtual terminal one.
So, semicolon, space, sleep, three, that'll give you a couple of, it'll give the terminal a couple of seconds to, you know, to pop back up.
So, semicolon, space, import, space, dash, display, colon, zero, dot, zero, dash, window, root, screenshot, dot, png.
And that would basically switch you over to the first term of virtual terminal, it would wait for it to draw itself on the screen, and then it would do the import command.
That's the way to take a screenshot without having this screenshot command in your screenshot.
Okay, so that's the import command. Let's think of sometimes maybe when we are going to actually be doing something within the GUI.
There are two times, or a couple of times I use image magic when I'm actually in a graphic environment.
One of those times is when, like I said, if I've got a lot of images that I need to juggle.
If it's 100 images or something like that that you need to do essentially the same thing to, image magic is the way to go.
Honestly, I tend to do Magrify, which is the one that changes the actual image, which I wouldn't think I would ever do because the risk is kind of strong that if you screw something up your original file is going to be gone.
But I guess I've never really done this to anything that important, so I just go ahead and use Magrify.
But you can certainly use Convert just as easily. A lot of these little programs and image magic use the same attributes or the same parameters.
It's just depending on how you want to apply the changes.
So if we're doing, like, if we need to rotate images and maybe we need to make them black and white and maybe we need to resize them.
You would just enter Magrify, space, dash, rotate, space, 90. That would be 90 degrees to the right, clockwise.
If you wanted to go 90 degrees to the left, you'd do minus 90.
Space, dash, color, space, all in word, space, gray, all in capital. That would change the color space to a gray scale color space.
And if you knew that you were sending images out to a proper printer, you could also change the color space to CMYK.
If you're going out to video, if these are still, you're going to put out the video, you could go to YUV. It just depends on what the purpose of your changes are.
And then you would do space, resize, 50%, space, images, asterisk.png.
And that would do all those things to everything called images with a number behind it.png.
And obviously you'd want to do that within the directory in which those images all dwell.
Now the really cool thing is that if it is like 100 images, obviously if you're going out to the web, you're going to have to figure that out yourself.
You know, upload it to your FTP, via FTP or server, and do whatever you want to do with it.
But what I've done in the past is had the need to go out to a PDF.
So I've scanned in like 100 images or 100 scans of camera logs or something like that.
And I need to get it consolidated so that the people who are going to be using these things don't need to open up 83 or 100 different images just to sort through what essentially is one document.
So image magic can do that as well.
And the command for that is convert, space, images, asterisk.png, space, all in one.pdf.
That's all one word, just all in one.pdf.
If you use that, it will invoke the convert command.
So it's not saving over anything.
It's not changing any original file.
And it's going to take anything called images with anything afterwards.png and make it into an all in one PDF file.
In the exact order that it appears in that directory.
So if you haven't named your images with some kind of logic to it, for instance, image 01, image 02, image 03, image 04, or better yet, image 001, 002, 003, then you're going to have a real interesting surprise.
But it's a lot easier to just name them properly in the first place and then just take them all and convert them to a PDF.
And I have Zoke in the IRC to thank for that.
He Googled it for me and found that command, which saved my life one night.
So that was really cool.
Let's see.
Other useful commands.
Well, there's animate.
A lot of people that I know with kids, they like to see slide shows of all their kids.
And the easiest way to do that, at least one easy way to do it.
I'm sure probably F spot and did you cam in all those applications, the CASA, whatever.
I'm sure that all does has some function for this.
But I don't use any of those programs.
So if someone wants to see images of a slide show of a collection of photos, maybe you just went on vacation.
You want to see all your vacation photos just kind of play on your screen.
The animate function is what you're looking for.
Animating is easy.
It's just basically either if you have an animated gift that you have separated into 29 different images or an animated sequence that you want to see in motion.
You can tell it to do that.
But if you just want to see like a slide show of pictures, all you do is you type in animate and space dash delay, space, say 500.
That would be five seconds on each image or 707 seconds, whatever.
SpaceAstrisk.png, and so now it's going to take every png in that folder, in that directory, and animate it in a little window.
Play it one after another in a little window for seven seconds each.
So that's pretty easy.
ImageVagantMagic is pretty easy, really.
There are a whole bunch of different options that you, if you want to do it to an image, then you probably can.
You just need to find out what property that is.
That can be a little bit overwhelming.
They don't have a proper man page as such.
If you just type in man, convert, or man, animate, or magnifier, whatever.
You see a very brief description of what the, of what the software, the application does.
But it doesn't give you all the options.
You get a little bit more detail if you just type in, for instance, magnify, space, dash, help, and that's one dash, not two.
It's just dash help.
That will give you a list on screen, and actually you'd probably want to pipe it into less.
It will give you a list on screen of all the different options.
But even then, it doesn't give you a whole lot of detail.
A better way is to simply go to a browser, whether it's Firefox, or Links, or Conquer, or whatever.
Just go to File, colon, slash, slash, slash, slash, that's three slashes.
USR, slash, share, slash, docs, slash, image magic, slash, www, slash, command, dash, line, dash, options.html.
That will give you all the different options that you could possibly want.
That's really the way that you kind of have to browse through it, because otherwise you don't get really as much detail as you need.
But it's a very powerful program, and there's just so much you can do without ever bothering to open up a graphic application.
You can watermark an image.
You can generate text.
You can add drop shadows. You can flip them, flop them, flatten them, extract information from them, magnify, invert, emboss.
You can give them labels, like metadata, rotate, just whatever you need to do.
It's a very, very powerful application.
If you're doing a lot of graphics, this could really save you a lot of time.
If you are doing art design for a fight or something, working with images, you might find it necessary to send PNG spec files to people.
A lot of people don't necessarily want or know what to do with a full-fledged SVG file.
Maybe you don't really have a good-looking SVG version of it yet.
Maybe you've reached the way I work with it.
Inkscape is all have like 20 different ideas on one file.
So it's not very convenient to send that entire scratch pad to the person who needs the art.
It's better to just make your selection and export just that selected area as a PNG.
And then you can convert that PNG to the proper size that you want.
You can add a background to it, whatever you want to do to it, with an image magic.
So image magic is a really great little tool.
You can use it if you want. Be aware of it anyway.
You know because you just never know when you're going to need some quick image manipulation.
There's just no reason to fire up an entire graphic app, just to resize an image by 50%.
So thanks for listening.
This has been Hacker Public Radio.
If you have questions, you can email me.
gort.clap2 at gmail.com.
If you want to be a part of Hacker Public Radio, then you can go to hackerpublicradio.org.
Email the administration of that site and they will contact you with show ideas or information on how to do a show.
If you have an idea for a show, it's very open.
And they're really nice there, so talk to them if you want to do an episode.
Image magic, HPR, great combination.
Thank you for listening to Hacker Public Radio.
HPR is sponsored by Carol.net, so head on over to CARO.ENC for all of her team.
