Random Lockscreen for iPhone

From BSODWiki
Jump to navigationJump to search


How To: Random Lockscreen Wallpaper on iPhone 3G 3.0+, using a PHP Web Server.

This is a tutorial about how to get a random lockscreen wallpaper on an iPhone 3G, 3GS, 4, with iOS 3.0+, using a PHP web server.
It works with jpg, png, and gif files. (Including animated gif)
It does not require file renaming.
Once it's configured, all you need to do is upload new pictures to your web site. This is usually done with FTP, or a web interface, if your provider has one.

Requirements

Skill level: Moderate (Some experience with HTML, FTP, and iPhone file system access will be needed.)
iPhone iOS 3.0+ (may work on other OS versions)
Edge data connection or better (Unlimited data plan recommended!)
(Data usage is based on image file size, and how many times the phone is locked per month.)
Jailbroken (RedSn0w, etc.)
Winterboard
SSH, WinSCP, iPhoneBrowser, or other similar program, for iPhone drive access.
Personal Web Server that supports PHP.
PHP Random Image Script.

The basics

After many months of research about how to get random lockscreen wallpaper on my iPhone, I finally ran across one post that mentioned using a Winterboard HTML file to link to a random image PHP script to change the wallpaper. There were no details about how to do this, so I had to start my own random wallpaper project from scratch. Here are my results that I think will work for many people out there.

How this works

A simple "LockBackground.html" file is created in a new folder under the "/private/var/stash/Themes.xxxxxx/" folder of the iPhone. I called my new folder "Random Lock.theme". Then open "Winterboard" and move the new theme to the top of the list and activate it. Now, every time you lock your iPhone, by tapping the power button or when it auto-locks, the HTML file is activated and it loads a PHP image file, from your own web server, that pulls up a random image from the same directory as the PHP file. (Note: The image folder can also be redirected within the PHP script.) The HTML file that I configured uses your main iPhone lockscreen image as the background, and covers it up with the new random image that is downloaded. That way, if you don’t have a data connection, or the server is down, or whatever, your main iPhone selected wallpaper image will still show up on your lock screen. The HTML file also resizes the random image to the correct size of the display. (See notes below the HTML code.) Your original images should be in the same aspect as the iPhone, for the best image results. Basically, your images should all be taller then they are wide. Animated GIF files a slightly choppy on the iPhone 3G. They do however play very smooth on the 3GS.

The stats from my testing

Since the image update only occurs each time the phone is locked, it does not really seem to impact performance or battery life. Each time the phone is locked it will download a new image from the web server, which, depending on the image size, and your connection speed, takes anywhere from 2-10 seconds, on average. I am on a T-Mobile Edge data connection, and the images pretty much always load within 10 seconds of pressing the lock button. A 3G connection should only take 2-3 seconds, and if you are connected to wifi when it locks, it is almost instant. The images that I have been testing with are between 20K and 150K.

File Stats:
391 files	20MB total folder size.
Sizes <10K 10-50K 50-100K >100K # of Pics 58 167 125 41 Largest files: 3 files at 200K each. Data Usage: Collected: Jan 2010 - Mar 2011 (14 months) Cell Data(MB) ServerHits ServerMB Average per month 89.64 714 34.39 Average per day 2.98 23.8 1.14

Cell Data = Total Cell data billed.
ServerHits = Hits to the server to load the random.php file.
ServerMB = Megabytes used at the server for the images. This included wifi image loads.

How to do it

The primary requirement is that you have your own web server that supports PHP scripts. Many people should have some free web site space available from their home Internet service provider. The PHP script that I used came from here: http://www.marcofolio.net/webdesign/php_random_image_rotation.html But you can find your own by doing a google search for "random image php". Place the rotate.php script on your web server, in its own folder, and put all of your 320x480 iPhone wallpaper images in there. The script I used works great with GIF, JPG, JPEG, and PNG files, by default. Then test out the script by loading it up in your browser. Example: http://www.myserver.com/iphonepics/rotate.php If it is working, you should see one of your pictures on the screen. If you refresh the page, you should get another random picture. If this is working, then you’re almost done.

Create a new text file somewhere on your computer, and call it "LockBackground.html" Open the new file in notepad and add the following HTML code:

<html>
<head><title>randomlock</title></head>
<body bgcolor="black" topmargin="0" marginheight="0" leftmargin="0" marginwidth="0" background="/var/mobile/Library/LockBackground.jpg">
<img src="http://www.myserver.com/iphonepics/rotate.php" alt="random" height="480" width="320" />
</body>
</html>

NOTE: iOS 3.x background="/var/mobile/Library/LockBackground.jpg"
iOS 4.x background="/var/mobile/Library/SpringBoard/LockBackground.jpg"
Also, if using an iPhone 4, you may need to adjust the height and width.
height="960" width="640"

Replace the "http://www.myserver.com/iphonepics/rotate.php" link with your own web server’s link that you tested earlier.

Now, access your iPhone with iPhoneBrowser or WinSCP, etc. Go to your Theme’s folder located at "/private/var/stash/Themes.xxxxxx/" Create a new folder, called "Random Lock.theme" Drag the "LockBackground.html" that you just created into the "Random Lock.theme" folder.

Load up "Winterboard" on your iPhone and you should see a new "Random Lock.theme" (if that’s what you called it) at the top of the list. Make sure it is at the top of the list, select it so it is checkmarked, and close Winterboard.

Now, you should have a functional random lockscreen wallpaper.

If you want to add or change the pictures, just add or delete the images from your web server. Just make sure not to delete the random PHP script file.

I hope this adds one more element of joy for you, to the great device that is the iPhone.

Enjoy, -dottrix

Disclaimer

This information is not guaranteed, and I can not be held responsible for any problems related to the procedures above. Use at your own risk. Just like everything else in the jailbroken iPhone world. Data charges may apply if you go over your allotted cellular data usage limit. An unlimited, or high usage data plan is highly recommended! Data usage will be determined by the size of the pictures multiplied by how many time your phone locks in a month. The smaller your files, the lower your overall data usage due to lockscreen updates. I have tested this on an iPhone 3G and 3GS, and have never personally experienced any problems.