[prev]Images[next]

Images are a simple way to make a web app more interesting. You can print an image with the image command.

Example: Adding Images

 
1
2
printp("Programming at a Young Age:")
print(image("http://i27.tinypic.com/16hvyfd.gif"))

Click to run the code.

In line 2, instead of printing a string, we are printing an image! The print command is flexible like that. The image is created using the image command, which is given a string: the URL where the image is located. Note that two close-parentheses are needed at the end of line 2, one for each command.

What's a URL?

A "URL", short for Uniform Resource Locator, is a web address of the kind you see in your browser's location bar, usually starting with http://. It can refer to a web page, an image, a media file, or any other kind of file.

Exercise: Chuck Norris needs a tag-line. Change the image URL in the above program to refer to the picture of Chuck Norris linked here. You'll have to change the tag-line above the image to something a little more appropriate!


In this example, we used tinypic to host the image. ("Host" is just another way of saying "make available on the Internet.") TinyPic is a service that hosts images you upload, free of charge. There are many other such services, and you can find them with a google search.

Another way to find images for your web app is using Google Image Search. When you search for an image and click on a result, you can also click on the "See full-size image" link at the top of the page. This will take you directly to the image in your browser, and you can copy the URL from the browser's location bar, and use that with AppJet's image command.

Link It Like It's Hot

Using URLs from Google Image Search is an example of hotlinking. Hotlinking means linking to someone else's image directly, without hosting it yourself. Some web site owners dislike it when you hotlink to their images, but most will not mind unless your app starts to generate lots of traffic which costs them in bandwidth.

If you hotlink to someone's image, they may pull a "switcheroo"!

Sometimes web site owners will do what's called the "hotlink switcheroo". When someone hotlinks to an image on their site, they will change the image to something funny or embarassing, which will in turn be displayed on the site that hotlinked to it. To prevent someone from pulling the switcheroo on you, use a service like TinyPic to host your images.

For an example of a fun AppJet app that uses images, check out imagethief.appjet.net (warning: this app lets anyone upload images, and sometimes explicit/offensive images appear). You can view the source code to imagethief at source.imagethief.appjet.net. It probably looks complicated, but stick with this guide and it will all make sense.

Previous Lesson: Web Apps Next Lesson: Getting Input