If the user has write permissions on the directory in which the original image lies it must write the newly created thumbnail to the local .thumbnails directory. Within this directory it must consider the size of course (see 'Directory Structure'). The following example shows the procedure for a writeable directory in detail:
Example 2. Storing thumbnails in local dir.
A program needs a thumbnail for ~/photos/me.jpeg with 64x64 in size.
The file ~/photos/.thumbnails/64x64/me.jpeg.png does not exist and there isn't one stored in the global dir.
So the program must create a new one.
We assume that the program has write permissions in ~/photos so it must create the dir ~/photos/.thumbnails/64x64 if it doesn't exist yet.
Then save the new thumbnail as ~/photos/.thumbnails/64x64/me.jpeg.png.
As mentioned previously the global thumbnail directory is used when the original lies in a read-only dir. Since it's likely that there are files with the same name in different directories it's not sufficient to apply the mechanism described above.
Instead you must provide the full qualified path to the original file and must recreate the directory structure within the dimension directory. A little example will clear this:
Example 3. Storing thumbnails in global dir.
A program needs a thumbnail for /opt/foo/portrait.tiff with 96x96 in size.
The file /opt/foo/.thumbnails/96x96/portrait.tiff.png does not exist and so does ~/.thumbnails/96x96/opt/foo/portrait.tiff.png.
So the program must create a new one.
Since the user has no write permissions in /opt/foo/ it must use the global dir and thus recreates the path within ~/.thumbnails/96x96. The resulting structure will be ~/.thumbnails/96x96/opt/foo.
Then it saves the new thumbnail as ~/.thumbnails/96x96/opt/foo/portrait.tiff.png.
If an program wants to save a thumbnail for a non local file (like http://my.server.net/image/img.png) it must do this in the global thumbnail dir. It must create single directories for the URI method, the domain name and the rest of the uri. The mentioned example would result in: ~/.thumbnails/96x96/http:/my.server.net/image/img.png.png.
As with the filenameing scheme problems occure if the maximum path length is hit. The solution is the same: don't create persistent thumbnails for these files.