Dion Moult Seriously who ever reads this description.

Presenting the Nagger

Over Christmas one of my more humourous gifts to my parents was to allow them to remotely nag each other electronically. Since my dad is often overseas, this actually has some practical use.

The idea was to create a remotely synchronised dynamic wallpaper with text that could be set by another person remotely. Person A would type in some text, a wallpaper with the text formatted would be generated, Person B’s computer would detect that there is an update, download the wallpaper and set it immediately. (I originally wanted to make a pop up message, but realised that having "Go and exercise!" pop up during a powerpoint presentation with your boss wasn’t the best thing)

The system would operate as such: I would create a html form on my webserver to allow somebody to type in text. PHP would take the text and use GD to generate a .jpg file of an image with the text overlayed on top. Batch file on Windows computer would download the .jpg file (either on startup, or via cronw) via URL2FILE. Batch file will call imagemagick installed on the Windows computer to convert .jpg to .bmp because apparently that’s what Windows likes for wallpaper formats and converting on the server would mean a ultra big file download. Finally, batch file will tweak the registry to change the wallpaper and "refresh" it such that it changes immediately.

Here’s an example :)

PHP code:

<?php
if (isset($_POST['submit']) && isset($_POST['nag']) && !empty($_POST['nag'])) {
$width = 1280;
$height = 800;
$imgname = "wallpaper_blank.jpg"; # The empty blue background template
$im = imagecreatefromjpeg ($imgname);
$text = $_POST['nag'];
$textcolor = ImageColorAllocate($im, 255, 255, 255);
$font = 20;
$font_width = ImageFontWidth($font);
$font_height = ImageFontHeight($font);
$font_width = 10;
$text_width = $font_width * strlen($text);
// Position to align in center
$position_center = ceil(($width - $text_width) / 2);
$text_height = $font_height;
// Position to align in abs middle
$position_middle = ceil(($height - $text_height) / 2);
imagettftext ($im, 15, 0, $position_center, $position_middle, $textcolor,
'/path/to/ttf/fontfile/AllOverAgainAllCaps.ttf', $text); # We're offsetting this a little to give space for desktop icons
Imagejpeg($im, '/path/to/final/image/wallpaper.jpg', 100);
chmod('/path/to/final/wallpaper.jpg', 0644); # Ensure we can download it (depending on server setup)
echo 'Nag done!';
} else {
echo '<form action="" method="post">';
echo '<textarea name="nag" rows="10" cols="50"></textarea><br />';
echo '<input type="submit" name="submit" value="Nag!">';
echo '</form>';
}

Batchfile code:

C:\path\to\URL2FILE.EXE http://mysite.com/wallpaper.jpg C:\path\to\save\wallpaper.jpg
C:\path\to\imagemagick\convert.exe C:\path\to\save\wallpaper.jpg C:\path\to\save\wallpaper.bmp
REG ADD "HKCU\Control Panel\Desktop" /V Wallpaper /T REG_SZ /F /D "C:\path\to\save\wallpaper.bmp"
REG ADD "HKCU\Control Panel\Desktop" /V WallpaperStyle /T REG_SZ /F /D 2
REG ADD "HKCU\Control Panel\Desktop" /V TileWallpaper /T REG_SZ /F /D 0
%SystemRoot%\System32\RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters

I thought it was cute, parents loved it.

P.S. If anybody knows a sane wait to input code into WordPress/Blogilo and have it immediately embedded in <code> tags as well as not lose whitespace, give me a poke.


8 Comments

hari says: (22 January 2011)

This looks like an excellent and innovative little utility. :)

By the way, to get code in good formatted HTML, I usually use the “Export as HTML” functionality from my text editor or use a code formatter in the command line and copy/paste the resulting HTML in my blog post. It’s a bit of a pain, but nevertheless is independent of server-side plugins etc. to achieve this.

Ole Christian Tvedt says: (22 January 2011)

Doesn’t <pre> work?

Dion Moult says: (22 January 2011)

Cheers hari, but WordPress’ WYSIWYG editor and Blogilo likes to enclose each line in paragraph tags. The only way I’ve figured out how to get past it is to copy the code into the HTML view, put my code tags, then tediously replace each html entity with its encoded equivalent. Ever tried inserting tabs in a web textbox? Not fun. Seems as though the WYSIWYG mode also likes to trim whitespace from each end which makes my indentation efforts useless.

Dion Moult says: (22 January 2011)

Christian Tvedt, I have my stylesheet setup to apply the style to code tags, plus pre wouldn’t be semantically correct :) (yes, I would’ve ignored semantics but afaik WordPress syntax highlighting plugins detect within code tags so I want to leave that option open)

Ole Christian Tvedt says: (23 January 2011)

I don’t agree that it is semantically incorrect. It is intended for preserving whitespace. If you want code where whitespace is preserved, then pre is correct. As far as I know, this is the common way of doing it. See for example stackoverflow.

Dion Moult says: (23 January 2011)

Ah just did a little bit of reading and turns out that <code> by itself _is_ semantically correct, but only appropriate for _inline_ code quotation. Should I want to quote a block of code, the proper solution is a code tag nested inside a pre tag, or <pre><code>, which semantically means “preformatted code”, which is correct :)

hari says: (24 January 2011)

I never bothered with these WYSIWYG editors anyway. I choose to simply type in the tags. :-)

p. says: (26 January 2011)

Really sweet! :)

Leave a Comment