Posted by hank,
Wed Aug 06 01:37:00 UTC 2008
Idea
I wanted to put images on my iPod Touch without using iTunes since, as most of us know, there is no good way to use it from Linux. It turns out there is a magic directory on the iPod Touch where it saves images from Safari. I simply looked at how it saved them, and applied it on my box here at home.
Requirements
- Jailbroken iPod Touch (I used WinPWN), with OpenSSH installed and working (the root password is alpine)
- Firmware 2.0 (Though, 1.x may work, I just haven’t tried it)
- A Linux box with a bash shell
- Cool images
convert and mogrify from ImageMagick installed
Method
These instructions might work for the iPhone as well. YMMV
All of your images must be in the format IMG_XXXX.YYY where XXXX is a number < 9999, and YYY is either JPG or THM (THM is a thumbnail). To rename our files, I use a simple trick I outlined in my last post:
EII=4; for i in *.jpg; do ls $i; \
NEWNAME=IMG_00`printf "%02d" $EII`.JPG; \
echo Renaming $i to $NEWNAME; \
mv $i $NEWNAME; EII=`expr $EII + 1`; done
That will rename all the JPEG files in order from 4 to, in my case, 62. Now, I have to make the thumbnails:
for i in `ls *.JPG | cut -d '.' -f 1`; do \
convert $i.JPG -resize 75x75! $i.THM; \
done
The 75x75! part makes sure they are exactly those dimensions. You end up with something like the following:
IMG_0004.JPG IMG_0016.JPG IMG_0028.JPG IMG_0040.JPG IMG_0052.JPG
IMG_0004.THM IMG_0016.THM IMG_0028.THM IMG_0040.THM IMG_0052.THM
IMG_0005.JPG IMG_0017.JPG IMG_0029.JPG IMG_0041.JPG IMG_0053.JPG
....
Now, note that the iPod can only display images under 100KB (to my knowledge). If your high-res image is too large, it will just display the magnified 75x75, which is really ugly. So, make sure all your images fit that description, and if they don’t, mogrify -resize them until they do (or take other measures as necessary). I used this:
mogrify -resize 400x *.JPG
All my images turned out to be between 30 and 90 KB. This also keeps the aspect ratio, unlike the 75x75!.
Now, SSH into your iPod (if you can’t do this yet, google it). You should have the following file:
/var/mobile/Media/DCIM/.MISC/Info.plist
Open this file in vi, and observe the plist>dict>integer part of the hierarchy:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>LastFileGroupNumber-100</key>
<integer>62</integer>
</dict>
</plist>
So, I put 62 in there since the last image I have is numbered 0062. It’s a very simple idea. Now, just load them onto the iPod:
scp IMG_00* root@ipod:/var/mobile/Media/DCIM/100APPLE/
Let’s have a look from the iPod console!
HanksTouch:/var/mobile/Media/DCIM/100APPLE root# ls
IMG_0002.JPG IMG_0014.THM IMG_0027.JPG IMG_0039.THM IMG_0052.JPG
IMG_0002.THM IMG_0015.JPG IMG_0027.THM IMG_0040.JPG IMG_0052.THM
Beautiful. Now, to test it…
Tags: images
Posted by hank,
Sat Jan 05 16:49:00 UTC 2008
So, I found this today, and it is awesome. I wanted it in Bluecloth so I could use it in Mephisto. Here’s how.
First, I needed to make it so I could still do normal images, but turn on coolness if I want. Here’s the goal I came up with for the grammar:
[](imageurl.jpg "Scrolly Text at top" "photoslice")
Here’s the first test, with a single image:

And now a set with a namespace:

I did it by simply modifying the regex and image url parsing function in BlueCloth like so:
InlineLinkRegex = %r{
\( # Literal paren
[ ]* # Zero or more spaces
<?(.+?)>? # URI = $1
[ ]* # Zero or more spaces
(?: # title
([\"\']) # Opening quote char = $2
(.*?) # Title = $3
\2 # Matching quote char
)? # Title is optional
[ ]* # Zero or more spaces
(?: # rel
([\"\']) # Opening quote char = $2
(.*?) # rel = $5
\4 # Matching quote char
)? # rel is optional
\)
}x
# and later...
# ...or for an inline style second part
elsif @scanner.scan( InlineLinkRegex )
url = @scanner[1]
title = @scanner[3]
rel = @scanner[5]
@log.debug " Found an inline link to %p" % url
text += %{<a href="%s"} % escape_md( url )
if title
title.gsub!( /"/, """ )
text += %{ title="%s"} % escape_md( title )
end
if rel
rel.gsub!( /"/, """ )
text += %{ rel="%s"} % escape_md( rel )
end
I also added the following to my Mephisto theme layout, in the head section:
<!-- Photoslice -->
<link rel="stylesheet" type="text/css" href="/javascripts/photoslice/style.css" />
{{ "photoslice/functions.js" | javascript }}
Once again, Ruby is awesome. And so is Markdown.
Tags: images
Posted by hank,
Sat Nov 24 19:46:00 UTC 2007
So, I have all these JPEGs, and I want to know which ones are corrupt (specifically, ones that end prematurely). qiv will spit out the following to STDERR when it finds one:
Premature end of JPEG file
So, this is nice, except it’s entirely unscriptable. The solution I found was using the following script to the display the images in sequence:
perl -e 'for(glob("*.png *.jpg")){$output = `qiv "$_" 2>&1;`; if($output =~ /Premature/){print $_, "\n";}}'
All this does is mix STDERR with STDOUT for a qiv of the file, and check the output for the word “Premature”. If it finds the word, it prints the filename. Simple.
The only problem is that qiv doesnt have a way to just check whether a JPEG file is corrupt (and if there is a command line utility that does, please let me know). To make it go thru the list, I wrote this little gem:
while(true); do xte "key q"; done
All this does is send the q key to the Xserver infinitely. All I have to do is put focus on the first qiv window to make it and all subsequent qiv windows receive q’s. So, just run it, and click on the window. Then there are lots of flashes, and eventually that perl script will print out the names of the bad files. It’s totally ghetto, but it’s the best I’ve got right now. The point of this post is to hopefully find new ways to do this more programmatically.
Tags: images
Posted by hank,
Thu Sep 20 21:14:00 UTC 2007
I saw this today, and thought it was hilarious. Basically, this is the main point of the whole thing:

So I decided to have some fun.
Continue Reading
Tags: images
Posted by hank,
Mon Sep 17 20:11:00 UTC 2007
Magic EXIF recursive tagging!
Have you ever had your files all nicely nested in directories, but needed to change their EXIF dates? Here’s what I used today to do it:
# Structure like this: 1997/08/Picture.Whatever Maybe Some Spaces.jpg
# Delete the EXIF tags (DONT DO THIS UNLESS YOU KNOW WHAT YOU'RE DOING!)
find . -mindepth 3 -exec jhead -de "{}" \;
# Make Fresh EXIF tags
find . -mindepth 3 -exec jhead -mkexif "{}" \;
# Set the dates according to the Year and Month information in the filenames
find . -mindepth 3 | perl -ne '@a = split(/\//, $_); chomp($_); print `jhead -da$a[1]:$a[2]:01-2007:09:17 "$_"`, "\n"'
This worked wonderfully.
Tags: images