<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>george-graphics.co.uk</title>
	<atom:link href="http://george-graphics.co.uk/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://george-graphics.co.uk/blog</link>
	<description>Photography, Coding, Travel and Random Bits</description>
	<lastBuildDate>Thu, 12 Jan 2012 07:46:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>New Domain</title>
		<link>http://george-graphics.co.uk/blog/2012/01/12/new-domain/</link>
		<comments>http://george-graphics.co.uk/blog/2012/01/12/new-domain/#comments</comments>
		<pubDate>Thu, 12 Jan 2012 07:46:07 +0000</pubDate>
		<dc:creator>geohar</dc:creator>
				<category><![CDATA[PhotoBlog]]></category>

		<guid isPermaLink="false">http://geohar.webfactional.com/blog/?p=582</guid>
		<description><![CDATA[Woot.. webfaction is pretty neat]]></description>
			<content:encoded><![CDATA[ <p>Woot.. webfaction is pretty neat</p>
]]></content:encoded>
			<wfw:commentRss>http://george-graphics.co.uk/blog/2012/01/12/new-domain/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title></title>
		<link>http://george-graphics.co.uk/blog/2011/06/17/578/</link>
		<comments>http://george-graphics.co.uk/blog/2011/06/17/578/#comments</comments>
		<pubDate>Fri, 17 Jun 2011 04:42:17 +0000</pubDate>
		<dc:creator>geohar</dc:creator>
				<category><![CDATA[BlogMeta]]></category>

		<guid isPermaLink="false">http://george-graphics.co.uk/blog/?p=578</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[ 						<div class="flickr-gallery image none"><a href="http://www.flickr.com/photos/georgeharker/5822972277"><img class="flickr medium" title="Jun 10, 2011-2" alt="Jun 10, 2011-2" src="http://farm3.static.flickr.com/2588/5822972277_5b969785c9.jpg" /></a></div>
					
]]></content:encoded>
			<wfw:commentRss>http://george-graphics.co.uk/blog/2011/06/17/578/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fixing the iPhone&#8217;s photo library</title>
		<link>http://george-graphics.co.uk/blog/2010/08/14/fixing-the-iphones-photo-library/</link>
		<comments>http://george-graphics.co.uk/blog/2010/08/14/fixing-the-iphones-photo-library/#comments</comments>
		<pubDate>Sat, 14 Aug 2010 05:13:34 +0000</pubDate>
		<dc:creator>geohar</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://george-graphics.co.uk/blog/?p=565</guid>
		<description><![CDATA[The other day my iPhone photo library got corrupted. It quit out whilst saving a photo, and thereafter when opening Photos, it tried to rebuild the database. Some of my photos were gone! Oh no. Actually, it turns out they were still there and were importable into Aperture (iPhoto and others would have been similar). [...]]]></description>
			<content:encoded><![CDATA[ <p>The other day my iPhone photo library got corrupted.  It quit out whilst saving a photo, and thereafter when opening Photos, it tried to rebuild the database.  Some of my photos were gone!  Oh no.</p>
<p>Actually, it turns out they were still there and were importable into Aperture (iPhoto and others would have been similar).  But the photo library was corrupt.  It was missing some photos and others were out of order.</p>
<p>I decided to poke about.  Of course I could restore my iPhone, but I&#8217;d loose new photos and that&#8217;s no fun.  I really wanted a way to fix it in situ.  I used <a href="http://www.ecamm.com/mac/phoneview/">PhoneView</a> to mount the phone and view it as a drive.  It doesn&#8217;t require jailbreaking.  It&#8217;s best to turn on &#8220;Show Entire Disk (Advance Mode)&#8221;.</p>
<p>Here you&#8217;ll find some folders:</p>
<ul>
<li><tt>DCIM</tt> &#8211; the actual photos</li>
<li><tt>PhotoData</tt> &#8211; the iPhone&#8217;s databases and thumbnails</li>
</ul>
<p>The interesting things are:</p>
<ul>
<li><tt>DCIM/.MISC/Info.plist</tt> &#8211; contains counts of maximum file number per folder (See below)</li>
<li><tt>PhotoData/MISC/Info.plist</tt> &#8211; contains counts of maximum file number per folder, seem to be identical to that above</li>
<li><tt>PhotoData/Photos.sqlite</tt> &#8211; the photo db which Photos uses to display stuff</li>
<li><tt>PhotoData/PhotosAux.sqlite</tt> &#8211; Another db which Photos uses to display stuff ( contains location data, needs to exist and be kept in sync with Photos)</li>
</ul>
<p>Here&#8217;s what happened: The phone stores it&#8217;s photos in a folder called <tt>DCIM/XYZAPPLE/</tt> where <tt>xyz</tt> are a three digit number starting 100,101,102 etc.  This affects the numbering scheme of the photos inside.  Each folder can contain 1000 shots, so <tt>100APPLE</tt> can contain <tt>IMG_0000.jpg</tt> thru <tt>IMG_0999.jpg</tt> and <tt>200APPLE</tt> can contain <tt>IMG_1000.jpg</tt> thru <tt>IMG_1999.jpg</tt>, and so on.</p>
<p><strong>Step 1.</strong></p>
<p>If the database files get corrupt, they can be rebuilt.  There are issues however.  The <tt>Info.plist</tt> file can get corrupted.  That prevents the phone from knowing the maximum file number in each <tt>DCIM</tt> folder.  It seems like the phone can recreate this file if it&#8217;s gone.  I just updated mine to make sure it was correct.</p>
<p>It looks something like this (in PropertyList Editor, WP stripped the xml markup of the xml plist file;) :<br />
<code><br />
DCIMChangedExternally<br />
LastFileGroupNumber-100<br />
  999<br />
LastFileGroupNumber-101<br />
  173<br />
LastFileGroupNumber-102<br />
  102<br />
LastFileGroupNumber-103<br />
  60<br />
LastFileGroupNumber-104<br />
  127<br />
LastFileGroupNumber-105<br />
  58<br />
LastFileGroupNumber-106<br />
  7<br />
LastFileGroupNumber-107<br />
  17<br />
LastFileGroupNumber-108<br />
  38<br />
LastFileGroupNumber-109<br />
  51<br />
</code></p>
<p><strong>Step 2.</strong></p>
<p>Copy that <tt>Info.plist</tt> back after modifying it to both <tt>DCIM/.MISC/</tt> and <tt>PhotoData/MISC/</tt>.</p>
<p><strong>Step 3.</strong></p>
<p>What if the db is corrupt?  Well, that&#8217;s actually quite likely (in my experience) to happen.  Delete it and it&#8217;ll get recreated as the phone traverses the <tt>DCIM</tt> folders and examines photos.  But here&#8217;s the rub, the order they get added is important.  And the order the phone traverses the <tt>DCIM</tt> folders is basically alphabetical.  Why is this an issue? Because the iPhone decides to bump which folder it stores photos in each time you update it / restore.  Which means your photos are likely scattered in a random order over these folders, with batches of consecutive numbers mixed up.  Apple uses the primary key to order the photos displayed in the App &#8211; not the date they were captured  (seriously, bad apple, there&#8217;s even a capture date field it could use).  I don&#8217;t know why and it sucks, but a rebuilt database will have your photos in a weird order.</p>
<p>Lets fix the db.  Long story short, the db layout is a bit odd.  There&#8217;s a bolt-on lat-long db for iPhone 4 maps, and there&#8217;s an PhotoAux table that records some metadata for quick access.   The App uses the primary key to order the photos, so we&#8217;re going to have to reorder primary keys.  That sucks.</p>
<p>Delete those db files from your phone (back up if you like).  Open Photos app on the phone and let it recreate them.  Quit it when it&#8217;s done (make sure it&#8217;s really quit using the task switcher in iOS4).</p>
<p>Grab <tt>Photos.sqlite</tt> and <tt>PhotosAux.sqlite</tt> and put them somewhere together.</p>
<p>Run this script&#8230; Caveat emptor it&#8217;s poorly written, requires <tt>sqlite3</tt> to be installed (you can get it from fink).  And it may or may not be correct.</p>
<p><code><br />
#!/bin/sh</p>
<p>cp Photos.sqlite Photos-mod.sqlite<br />
cp PhotosAux.sqlite PhotosAux-mod.sqlite</p>
<p>sqlite3 Photos-mod.sqlite "DELETE FROM Photo;"<br />
sqlite3 PhotosAux-mod.sqlite "DELETE FROM AuxPhoto;"<br />
sqlite3 Photos.sqlite "SELECT primaryKey FROM Photo ORDER BY captureTime;" > keys.txt</p>
<p># move all the ids fwd (better hope 999999 is max, could always get max fk)<br />
sqlite3 Photos-mod.sqlite "UPDATE PhotoExtras SET foreignKey=foreignKey+999999";</p>
<p>vars="type,title,captureTime,width,height,userRating,flagged,thumbnailIndex,orientation,directory,filename,duration,recordModDate"<br />
let i=1<br />
cat keys.txt | while read line; do<br />
	echo "${line}";<br />
	r=`sqlite3 -csv Photos.sqlite "SELECT $vars FROM Photo WHERE primaryKey=${line};"`;<br />
	r=`echo $r | sed -e 's/\([^,]*\)/"\1"/g'`<br />
	echo "INSERT INTO Photo (primaryKey,${vars}) VALUES ($i,$r);";<br />
	sqlite3 Photos-mod.sqlite "INSERT INTO Photo (primaryKey,${vars}) VALUES ($i,$r);";</p>
<p>	fk=$((${line}+999999));<br />
	echo "UPDATE PhotoExtras SET foreignKey=$i WHERE foreignKey=${fk}";<br />
	sqlite3 Photos-mod.sqlite "UPDATE PhotoExtras SET foreignKey=$i WHERE foreignKey=${fk}";</p>
<p>	r=`sqlite3 -csv PhotosAux.sqlite "SELECT latitude,longitude FROM AuxPhoto WHERE primaryKey=$line"`;<br />
	if [[ $r != "," ]]; then<br />
		r=`echo $r | sed -e 's/\([^,]*\)/"\1"/g'`;<br />
		echo "INSERT INTO AuxPhoto (primaryKey,latitude,longitude) VALUES ($i,$r);";<br />
		sqlite3 PhotosAux-mod.sqlite "INSERT INTO AuxPhoto (primaryKey,latitude,longitude) VALUES ($i,$r);";<br />
	else<br />
		echo "INSERT INTO AuxPhoto (primaryKey) VALUES ($i);";<br />
		sqlite3 PhotosAux-mod.sqlite "INSERT INTO AuxPhoto (primaryKey) VALUES ($i);";<br />
	fi</p>
<p>	let i=$i+1;<br />
done</p>
<p>mv Photos.sqlite Photos-old.sqlite<br />
mv PhotosAux.sqlite PhotosAux-old.sqlite</p>
<p>mv Photos-mod.sqlite Photos.sqlite<br />
mv PhotosAux-mod.sqlite PhotosAux.sqlite<br />
</code></p>
<p>It&#8217;ll make two new db files to copy back to the iPhone.  Better make sure you quit Photos app on the phone first.  First of all, it&#8217;s sucking the <tt>Photo</tt> table into a new db because we need to reorder the primary keys.  It now occurs to me we might have been able to shift the primary keys range (though this might bork things for subsequently added photos).  The could be improved upon in terms of it&#8217;s escaping here.  We also update the <tt>PhotoExtras</tt> to shift it&#8217;s references to the reordered <tt>Photo</tt> table.  Finally we keep the lat long data in the second db in sync. Note that there are also <tt>PhotoAlbum</tt> tables and a table which notes how to join the albums together.  I didn&#8217;t mess with these since I don&#8217;t sync back albums to the phone.  If I did, it&#8217;s possible this would just work, maybe not &#8211; YMMV.  But hey, it&#8217;s a start.  Took a long while to figure out how to muck with stuff to have a hope in hell of not having to do a restore.  If only apple rebuilt the db in date order, or queried it with a <tt>captureDate</tt> index&#8230; this wouldn&#8217;t have been needed.</p>
<p>That&#8217;s it.  Restart your phone.  Everything should be good again.</p>
]]></content:encoded>
			<wfw:commentRss>http://george-graphics.co.uk/blog/2010/08/14/fixing-the-iphones-photo-library/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Posting vimeo vids to wordpress</title>
		<link>http://george-graphics.co.uk/blog/2010/04/28/posting-vimeo-vids-to-wordpress/</link>
		<comments>http://george-graphics.co.uk/blog/2010/04/28/posting-vimeo-vids-to-wordpress/#comments</comments>
		<pubDate>Wed, 28 Apr 2010 16:19:33 +0000</pubDate>
		<dc:creator>geohar</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://george-graphics.co.uk/blog/?p=556</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[ <p><object type="application/x-shockwave-flash" data="http://vimeo.com/moogaloop.swf" width="500" height="313"><param name="allowscriptaccess" value="always"/><param name="allowfullscreen" value="true"/><param name="movie" value="http://vimeo.com/moogaloop.swf"/><param name="flashvars" value="clip_id=8462405&amp;color=00adef&amp;fullscreen=1&amp;server=vimeo.com&amp;show_byline=1&amp;show_portrait=1&amp;show_title=1"/></object></p>
]]></content:encoded>
			<wfw:commentRss>http://george-graphics.co.uk/blog/2010/04/28/posting-vimeo-vids-to-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fog over the city</title>
		<link>http://george-graphics.co.uk/blog/2009/05/15/fog-over-the-city/</link>
		<comments>http://george-graphics.co.uk/blog/2009/05/15/fog-over-the-city/#comments</comments>
		<pubDate>Fri, 15 May 2009 15:55:02 +0000</pubDate>
		<dc:creator>geohar</dc:creator>
				<category><![CDATA[PhotoBlog]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://george-graphics.co.uk/blog/2009/05/15/fog-over-the-city/</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[]]></content:encoded>
			<wfw:commentRss>http://george-graphics.co.uk/blog/2009/05/15/fog-over-the-city/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sunset at Volunteer Park</title>
		<link>http://george-graphics.co.uk/blog/2009/05/09/sunset-at-volunteer-park/</link>
		<comments>http://george-graphics.co.uk/blog/2009/05/09/sunset-at-volunteer-park/#comments</comments>
		<pubDate>Sat, 09 May 2009 21:42:04 +0000</pubDate>
		<dc:creator>geohar</dc:creator>
				<category><![CDATA[PhotoBlog]]></category>

		<guid isPermaLink="false">http://george-graphics.co.uk/blog/?p=544</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[]]></content:encoded>
			<wfw:commentRss>http://george-graphics.co.uk/blog/2009/05/09/sunset-at-volunteer-park/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>All NY-Poster style</title>
		<link>http://george-graphics.co.uk/blog/2009/05/09/all-ny-poster-style/</link>
		<comments>http://george-graphics.co.uk/blog/2009/05/09/all-ny-poster-style/#comments</comments>
		<pubDate>Sat, 09 May 2009 21:24:00 +0000</pubDate>
		<dc:creator>geohar</dc:creator>
				<category><![CDATA[PhotoBlog]]></category>

		<guid isPermaLink="false">http://george-graphics.co.uk/blog/?p=540</guid>
		<description><![CDATA[I think I might prefer it in B&#38;W]]></description>
			<content:encoded><![CDATA[<p>I think I might prefer it in B&amp;W</p>
]]></content:encoded>
			<wfw:commentRss>http://george-graphics.co.uk/blog/2009/05/09/all-ny-poster-style/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>From the Space Needle at night</title>
		<link>http://george-graphics.co.uk/blog/2009/05/09/from-the-space-needle-at-night/</link>
		<comments>http://george-graphics.co.uk/blog/2009/05/09/from-the-space-needle-at-night/#comments</comments>
		<pubDate>Sat, 09 May 2009 21:20:20 +0000</pubDate>
		<dc:creator>geohar</dc:creator>
				<category><![CDATA[PhotoBlog]]></category>

		<guid isPermaLink="false">http://george-graphics.co.uk/blog/?p=536</guid>
		<description><![CDATA[Seattle looks like a little model town, all glowing]]></description>
			<content:encoded><![CDATA[<p>Seattle looks like a little model town, all glowing</p>
]]></content:encoded>
			<wfw:commentRss>http://george-graphics.co.uk/blog/2009/05/09/from-the-space-needle-at-night/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Space Needle at Night</title>
		<link>http://george-graphics.co.uk/blog/2009/05/09/space-needle-at-night-2/</link>
		<comments>http://george-graphics.co.uk/blog/2009/05/09/space-needle-at-night-2/#comments</comments>
		<pubDate>Sat, 09 May 2009 21:19:09 +0000</pubDate>
		<dc:creator>geohar</dc:creator>
				<category><![CDATA[PhotoBlog]]></category>

		<guid isPermaLink="false">http://george-graphics.co.uk/blog/?p=533</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[]]></content:encoded>
			<wfw:commentRss>http://george-graphics.co.uk/blog/2009/05/09/space-needle-at-night-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sunset at Crescent lake</title>
		<link>http://george-graphics.co.uk/blog/2009/05/09/sunset-at-crescent-lake/</link>
		<comments>http://george-graphics.co.uk/blog/2009/05/09/sunset-at-crescent-lake/#comments</comments>
		<pubDate>Sat, 09 May 2009 21:09:11 +0000</pubDate>
		<dc:creator>geohar</dc:creator>
				<category><![CDATA[PhotoBlog]]></category>

		<guid isPermaLink="false">http://george-graphics.co.uk/blog/?p=530</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[]]></content:encoded>
			<wfw:commentRss>http://george-graphics.co.uk/blog/2009/05/09/sunset-at-crescent-lake/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

