define('DISABLE_WP_CRON', 'true'); Downloading And Manipulating Images Using The Linux Command Line - HTNet

Downloading And Manipulating Images Using The Linux Command Line

Any decent Linux-based web hosting service would allow customers to access the server via SSH. SSH is short for Secure Shell. Using SSH, you can access your web hosting server to perform administration as well as file manipulation.

To know if your web hosting provider allows customers to access their servers using SSH, you need to ask the contact person. You would also need an SSH client. If you’re using Windows, I recommend that you download PuTTy.

Logging On To Your Server

Fire up PuTTy and under the Host Name (or IP address) section, type in your domain name. If your web site is at then enter that hostname into the text box, like the example below.

PuTTy Login Details

If this is the first time you’re accessing your server using PuTTy, you will see a security alert warning similar to this:

PuTTy Warning Window

If you’re sure that you’re logging on to the correct server, then you can click the Yes button confidently.

You should then see a black window asking your for your username. If you’re on a CPanel-based web hosting subscription, this would be your CPanel username.

After you’ve entered your username, you will then be prompted to enter your password. Again, if you’re on CPanel-based web host, this will be your CPanel password.

If you entered these details correctly, you’ll be greeted with a shell prompt that will look similar to this: [~]#

Congratulations! You’ve successfully logged on to the server.

Now, you might want to navigate to your web directory. On CPanel hosts, this would be at /home/yourname/public_html/. So all you need to do is enter the following command:

cd ~/public_html/

The tilde character: ~; is a shortcut to your home directory. Therefore if your username is yourname, entering the command above would take you to /home/yourname/public_html/.

Grabbing Pictures From Other Web Sites

Before you proceed any further, you should always understand the licensing terms of images you want to grab. Failure to do so might land you in trouble if the owner decides to take legal action against you.

In this example, I’m going to grab a picture of a lion cub from my own Flickr account. How do I do this from the Linux command line? Just type in the following:

wget URL of picture you want to download

This command tells the server to use the wget software to grab the file from the URL you provided. It does not necessarily have to be pictures. But in this example, I’m going to grab the lion cub picture.

The first thing I need is the URL to the picture. Since I’m using Firefox, I can just right-click on the picture and click on the Copy Image Location menu item. It tells me that the URL to the picture is:

I’m going to ignore the ?v=0 part because that is not part of the actual image filename. So now, I can grab the picture using this command:


If you’re on a fast server, the downloading should be almost instantaneous. You should now have a copy of that picture on your server. You can test it by typing in your browser’s address bar, replacing with your own domain name.

If you see the lion cub picture, than give yourself a pat at the back! You’ve successfully downloaded a picture using wget.

You might want to rename the file to something easier to remember. The command to do this is as follows:

mv old-file-name new-file-name

Let’s say we want to rename the downloaded file to lion-cub.jpg, then we should use this command:

mv 436307942_5269540c81.jpg lion-cub.jpg

Note that you must also supply the file extension (the .jpg part) as well.

Resizing The Picture

If you’re on a decent Linux hosting package, it should come preinstalled with the ImageMagick image manipulation software suite. Using ImageMagick, you can manipulate images easily via the command line.

In this example, I’m going to resize the lion cub picture to have a width of 200 pixels instead of its original 500 pixels. I also want the height to be automatically calculated for me so that the picture won’t be stretched unnaturally.

The command to do this is very easy:

convert -resize width filename newfilename

So, in order to make my lion cub picture to have a width of 200 pixels, and save the smaller picture as lion-cub-small.jpg, I would run type in the following at the command line:

convert -resize 200 lion-cub.jpg lion-cub-small.jpg

Simple, right? Just by typing a few command you have done the following:

  1. Download a remote picture directly to your server
  2. Rename it to something easier to remember
  3. Resize it to become smaller and keeping the original

You can then embed the picture in your web site very easily.

The Results

Here is the image file renamed to lion-cub.jpg that I grabbed from Flickr:

Lion Cub: Big

Here is the resized version of that picture; lion-cub-small.jpg:

Lion Cub: Small

Sure beats downloading the picture to your computer, resizing it using an imaging software, and uploading it to your server, right?

If you find this guide useful, please subscribe to my feeds to get updated instantaneously whenever I post something new. I regularly update HTNet with hints and tips just like the one you’ve just read.

What do you think of this guide? Was it helpful to you? I would love to hear your comments!

3 responses to “Downloading And Manipulating Images Using The Linux Command Line”.

  1. papajoneh Says:

    Cool instruction. Beats doing it with mouse.
    B4 i start, how to exit already, ah? 😛

  2. Site Admin Azmeen Says:

    papajoneh: Exactly that; type exit or logout

  3. papajoneh Says:

    thanks. 🙂