Images![[next]](../../img/ltp/arrow-next.gif)
Images are a simple way to make a web app more interesting. You can print an image with the image command.
|
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.
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.
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.
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.