Let’s Make An Animated GIF (With ImageMagick)

Today’s article is just for fun, where we learn how to make an animated gif in the terminal – with ImageMagick. It’s just for fun and not something you’ll likely need unless you’re some sort of content creator. (We don’t know any of those, do we?) Anyhow, let’s go ahead and make an animated .gif in the terminal.

Today, we’ll be using ‘ImageMagick’. As far as I know, imagemagick has one of the longest and most complicated man pages. It’s huge and a capable tool in the right hands. ImageMagick has all sorts of capabilities but a new user isn’t likely to use them because of the complexity involved.

And, ImageMagick is complex… In fact, it defines itself as:

ImageMagick – is a free software suite for the creation, modification and display of bitmap images.

That’s an accurate description, I think… Except, well, it does a whole lot more than that. We’ll be using the .gif format, while the man page description only mentions bitmap. So, there’s a lot to the application.

Thus, without further ado, we make an animated gif in the terminal…

How To Make An Animated GIF:

The ImageMagick application is terminal-based. So, you’re going to need an open terminal. If you want, you can just press CTRL + ALT + T and your default terminal should open.

If you don’t have ImageMagick installed, you’ll need to install it. If you’re using a mainstream distro, it’s possibly installed already. Otherwise, it’ll certainly be in your default repositories as it’s a pretty major tool. For example, an apt user would just use a command like this (adjust for your package manager):

With your terminal now open and imagemagick properly installed, let’s just see how long that man page is:

See? I wasn’t kidding!

Now, here’s what you need to make an animated gif:

  1. A dedicated folder, perhaps in your ~/Pictures directory.
  2. A few images of the same format, we’ll use .jpg in our example.
  3. A terminal opened in the above-mentioned dedicated folder.

The first thing to learn is that this command is going to take those images and turn them into an animated file with the .gif extension. It is going to organize them alphanumerically. So, you should rename the  .jpg files in the order you wish to see them (assuming the order matters to you).

All set? Have you done all those things? Are you 100% prepared? Good!

The command we’re looking for would be:

Alright, so the ‘delay 1000’ is how long each image will be shown – in hundredths of a second. The ‘-loop 0’ tells it to loop infinitely, or you can pick your own number of times. The ‘*.jpg’ means use all the .jpg files in that directory. The ‘file_name’ is the name of the file you want to have as your output.

See? Pretty simple. An example command might be something like:

Let the command run, and it is a pretty speedy process unless you have a whole lot of images, and you’ll get an animated gif as a result. As these tend to have smaller file sizes, it’s sometimes a better option than sharing a larger video file. It depends on your circumstances, I suppose.

NOTE: This article has been edited to correct the time delay, the delay between changing images. Thanks @wizardfromoz!

Closure:

There you have it. You have an article that tells you how to make an animated gif with ImageMagick. The ImageMagick application has a ton of options, making it daunting for a new Linux user. So, this is just a tiny bite. This is just one of many ways to use ImageMagick. Instead of learning the whole application at once, you can do so in chunks – learning only what you need.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

How To: Convert JPG to PNG

In today’s article, we’re going to learn how to convert JPG to PNG image files. It’s a pretty easy process. In fact, the second part of the article should be fairly brief. Read on to learn more!

I should also mention that we’ll be learning how to convert JPG to PNG in the terminal. There are all sorts of GUI ways to do so, from individually converting files to batch conversions. Well, you can do all that in the terminal and this article will show you how.

Why PNG? Well, it supports lossless compression. PNG also supports transparency. PNG also looks better at higher resolutions, as it is able to display more details. Additionally, PNG not only supports lossless compression, it supports compression better – so you needn’t transfer larger files if you have no reason to do so. Plus, PNG is one of the better formats if  you’re going to do things like share the images online.

So, there are a number of reasons why you’d want to convert JPG to PNG. Fortunately, as I mentioned above, it’s really not all that difficult. You have tools to do this right in your default repositories, assuming you’re using a mainstream distro.

Without further ado…

Convert JPG to PNG:

As we’ll be converting in the terminal, you will have to have an open terminal. To do that, just press CTRL + ALT + T and your default terminal should open. See? We’re off to a good start.

Now, the tool we’ll be using is ‘ImageMagick’ and it’s available to install via  your normal channels. If you were using a distro that uses apt (Debian/Ubuntu/Mint/etc) then it’s trivial to install with:

Otherwise, install it with your default package manager tools. (You just might have installed when we covered how to resize images with ImageMagick. If not, now’s a good time to install it and then read that article!)

So, next you’ll either want to use the /path/to/directory where your JPG files are,  or just navigate to the directory where you’ve stored them (the easiest path), and you can convert them all with just one command:

Congratulations, in just that one command you’ll have converted all the JPG to PNG files. Feel the power of Linux! You’ll retain the originals, just in case something goes awry. If you’re happy with the results, you can always delete the originals with any one of a number of commands.

So, what if you just want to convert one JPG to PNG? Well, that’s easy:

See? I told you it was easy. While there’s a whole lot of complexity with ImageMagick, it can be quite simple to use for some very generic day-to-day tasks. Of couse, man imagemagick is always an option to learn more.

Closure:

Yup… It’s really not all that hard to convert JPG to PNG files with ImageMagick. If it’s a large number of files, it could be a bit for you to convert them all, but let it do its thing and it won’t take too long on a modern computer. If you only need to convert one image, that’s fine too.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

A Couple of Ways To Resize Images With ImageMagick

In today’s article, we’re going to go over a couple of ways to resize images with ImageMagick. It’s a useful skill to have if you’re into sharing images or the likes. This will actually be pretty quick and easy. I won’t take much of your time today but it’ll be longer than some other articles – but it really should be a quick read for you today.

It’s nice to not put full resolution pictures online – unless there’s a reason for the higher resolution. So, it’s a bit of a politeness to resize your images. I try to be considerate, ’cause I know what it’s like to have limited bandwidth. You people who started off in life with things like 100 GB fiber have no idea the pain we went through to get here! Alas, that whining is perhaps subject to another article, though probably not really a suitable article for this site. There are people who still use slow connections, and metered connections are entirely too popular.

So, what is ImageMagick? It describes itself as:

ImageMagick – is a free software suite for the creation, modification
and display of bitmap images.

ImageMagick is actually quite a useful application for quickly and easily manipulating images in the terminal. ImageMagick is so robust that trying to cover all of it in a single article would be foolish. I simply couldn’t do it within the bounds of a single article.

That’s why we’ll just be examining a couple of quick ways to resize images with ImageMagick. We couldn’t possibly cover it all today. If you want to see what all the options are, I’d recommend checking the man pages – and reading other tutorials that cover the things you’d like to do.

With that said and done, let’s resize some images with ImageMagick!

Resize Images With ImageMagick:

This article requires an open terminal, like many other articles on this site. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.

The first thing we’re going to need to do is make sure you have ImageMagick installed. So, let’s install it. The command below is for those who use apt, but you can easily change it to your own package manager. I’m 99% certain that ImageMagick will be in your default repositories! It’s a pretty widely used application! The command for those of us who are apt-using people is simply:

Follow any on-screen prompts to install it, else it’ll tell you that it is already installed. ImageMagick appears to be installed by default on a number of distros, but it’s easy enough to install. You can actually just add a -y to it and skip some of the prompts:

Of course, you’ll still need to enter your password. Well, if you really want to live on the edge, you can enable passwordless sudo easily enough. I don’t really suggest that, but I do tell you how to do it. ‘Snot something for the faint of  heart.

Ah well… Onto the meat of the article!

Resize By Resolution:

Now that you have ImageMagick installed, let’s try resizing something. What we’re going to do first is resize it by way of the resolution. That is, we will resize it by declaring the new height and length. To do so, you’d use a command like:

For example, you might try something like this:

See? Pretty easy. I told you this wouldn’t be too hard – nor will this article be all that long. Well, it might be a bit longer than some, but I won’t let it be too long. I know my reader’s attention span! You should make sure to use the same base resolution. If the image is 16:9, your resized image should retain that aspect ratio. Otherwise, your images may appear warped and ugly.

I should probably mention that it’s possible to make images larger with this command. However, when you make an image larger you lose fidelity. Making an image too large is going to result in an ugly image. It’s not like the television where you can just keep zooming in and enhancing. Ones and zeros don’t work like that.

Resize By Percentage:

This is my favorite way to resize images with ImageMagick, unless I have a specific reason to resize images by resolution. In this case, you just declare a percentage of the original and ImageMagick does the rest. It’s really a very easy command. It looks a little like this:

If you want, here’s an example of how you can use that command to resize images by percentage with ImageMagick:

That command will make ImageMagick output a file that’s 50% smaller than the original image. Not only will this be a smaller image visually, it will have a smaller file size. Because of the way images work, this doesn’t mean the new file size, size on disk, will be reduced by 50%. It just means you’ve reduced the image’s dimensions by 50%. The size on disk will also be lower, but it’s not directly proportionate. 

Like above, where  you resize the image by resolution, you can use this to make images larger. The same caveats exist that existed above. That is making an image too large means it results in a poor quality image. As you can guess, making images larger isn’t always a good idea, but it’s generally fine if the operation is making the images smaller.

Closure:

And there you have it. You have another article! This time, we’ve covered how to resize images with ImageMagick. I think that’s a useful skill to have and it’s a quick/easy thing to learn. Of course, you can always check man imagemagick to check the man page. That man page will be enlightening, I suspect.

I’ve changed the format a bit for this article (though I’ve used it before), and made it a bit longer than the recent articles. If you have an opinion on the matter, please feel free to leave a comment. The more I know about your wants, the more I can tailor the content. The more I can tailor the content, the better you’ll enjoy the content. To do this, I need to know your thoughts on the matter. Speak up!

So, do you enjoy the longer articles? Do you enjoy the shorter articles? Do you appreciate a mix of them, and each article only being as long as it really needs to be? I normally try to keep all my articles friendly, informative,  and fairly strictly informal. Lately they’ve been pretty  short, but I can be more verbose, as many of you will have witnessed.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Subscribe To Our Newsletter
Get notified when new articles are published! It's free and I won't send you any spam.
Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.