Mo’ blogging, less problems
Posted: July 7th, 2003 | 7 Comments »
Brewer St. 10:30 pm.
Those pics up on top of my front page? They’re pictures from my 3G phone, implant sent
in an MMS to an email address which pipes them to this here
perl script wot I wrote which creates MT entries and thumbnails
and stuff.
(2nd update, more about 9/9/03: POP3 version from Ben, another code patch from Chris)
Notes about usage and development:
- Firstly, have some idea how to configure a script and have incoming
mail piped to it. (I’m assuming basic UNIXy knowledge here) You’ll
also need a working MT install and, somewhere reachable, the MIME::Tools
modules. Oh, and obviously this should all be
done on the same machine. (i.e. the machine that publishes your blog
should also be capable of receiving email) (UPDATE: If you have blog and email on separate machines, Ben Milleare’s POP3 version may be the thing for you) - Download the script and set the variables at the start. You’ll
also need to make a directory for the unpacked MIME files to go into. - You may want to make a new MT category for pictures, which makes it
much easier to do tricks like my picture bar. The code for it looks like this:
<MTEntries lastn="4" category="pic">
<$MTEntryExcerpt$>
</MTEntries>
… since it’s the entry excerpt that holds the clickable thumbnail.
Once you’ve made the category, put its ID number into the $CAT_ID constant
at the top of the code. If you don’t want to use category-setting, set it to 0.
(Oh, and you’ll want to edit your mainMTEntries
tag on
the Main Index to use every category except the picture one.) - Unfortunately, there aren’t currently any logging or
debugging facilities for the script beyond those that your MTA or
perl environment provide. However, I found that testing by piping
a pre-saved mail from a file was enormously helpful. (Well, more
helpful than having to work my way through my phone’s abysmal
message-sending interface and then sifting through the mail logs
for errors every time, anyway) - Once you’re sure it works, set up your mail handling in procmail
or whatever. Since I use qmail
(for reasons beyond my control) I have a .qmail-... file
that merely contains the line|/home/yoz/ym.pl
There should probably be a preline in there, but it seems
to work fine without it. - I say above that it’s built for handling MMS (Multimedia Message
Service) mails from phones and the like, but it’ll handle any mail with
an image attachment. (As long as there’s only one image. I should probably
fix that.) If there’s some
text in the body (not the subject) it’ll handle that too, using
it as a title for the entry, the A tag and the value of the ALT attribute. - Thanks to Chris Carline, the subject line can be used to rotate the image if your phone can’t do that for you.
Send “t” to rotate 90 degrees anti-clockwise or “tc” for 90 degrees clockwise. - Yes, okay, it’s a badly-hacked-up piece of shite, but it appears
to work. I didn’t use XML-RPC or any of that nonsense because firstly
it seemed a terribly roundabout way of getting some perl to call some
other perl and secondly because I wanted it to do some thumbnailing
and stuff. And okay, when I had this script half-written
Cory showed
me a Python one that was already done but I was too far into this one
to care, and besides, that one didn’t do thumbnailing. Credit must
go to Olivier
Mueller’s script for inspiration
and also to Azeem for
irritating me into thinking about this in the first place. - Thus, there is no license and no guarantee. Caveat haxxor. If it
breaks in half, you own both pieces. Please don’t use it to kill
people, though mortal embarrassment is fine (and, frankly, inevitable).
I wish I understood more than just the title of this post. If I had a cameraphone I would want to be moblogging to MT _really_ badly. And who knows… the new Handspring/Palm thingy is singing a Siren song…. (as well as ringing polyphonic ring tones)
Sorry, it’s all very techie – unfortunately, hooking anything up to a mail recipient usually gets nasty. 🙁
add this if you don’t want the script to break when you install extra MT modules
use lib “$MT_DIR/extlib”;
yoz & ben, thanks for this!
things were going fine till my t630 shit the bed, and i decided to go instead with the Samsung e715. problem was, the jpegs the samsung spits out doesn’t play nice with your script (in particular, the MT::Image module), giving this to errstr when it tries to make the thumbnail:
——————-
Reading file ‘pic.jpg’ failed: Exception 325: Invalid SOS parameters for sequential JPEG (pic.jpg)
Can’t call method “scale” on an undefined value at ./mt-moblog.pl line 132.
——————-
what to do? use another thumbnail module. for no particular reason other than it was the first one google turned up, i chose Image::Thumbnail by L. Goddard. so to get things going basicaly all i did was replace the MT::Image thumbnail code with this bit:
—————-
my $img = new Image::Thumbnail(
size => $WIDTH,
create => 1,
inputpath => $imagepath.$imgext,
outputpath => $imagepath.”_t”.$imgext,
);
—————-
and everything works again. probably not necessary for most, but for those whose phones spit jpegs out in a format that MT::Image can’t handle, the above hack will get you going again.
i should admit that you have a lovely site. Please accept my compliments!
RE: #6 when you say “As long as there’s only one image”, you mean for MMS as well as email? Just curious, as tmo has changed their MMS format to include a little web page w/ a spacer gif, and some other jpg (kinda like what SprintPCS does)…
Yep, given that it expects MMS to come in as email anyway. If there’s more than one image it’ll still only return one which may well be the wrong one, so it’s worth a try to see what it does. I’m rather short on coding time at the moment – if you want to have a go at patching it, feel free. Otherwise, send me an example MMS mail and I’ll see what I can do.