MSIE hangs when trying to load .jpg images

Bea recently started getting complaints from her blog readers that they couldn’t see the images on her site. I thought that it was strange that neither of us would have noticed this, but sure enough, they were right. The problem was infuriatingly difficult to debug, so I figured that I would post my fix here. But I was lucky: I wasted an entire weekend on this exact problem about 3 years ago, so I had a sense of what I was looking for after I remembered the details.

The symptom is this: MSIE on Windows stops loading graphics. Everything else loads fine, but the graphics just refused to load. You can sniff packets, look at HTTP headers and everything will be normal. But broken at the same time.
Basically, certain applications on the Mac platform (like Photoshop) put large quantities of XML into the header of .jpg images. The XML looks like this:

<plist version="1.0">
<dict>
<key>com.apple.print.PageFormat.PMHorizontalRes</key>
</dict><dict>
<key>com.apple.print.ticket.creator</key>
<string>com.apple.printingmanager</string>
<key>com.apple.print.ticket.itemArray</key>
<array>
<dict>
<key>com.apple.print.PageFormat.PMHorizontalRes</key>
<real>72</real>
<key>com.apple.print.ticket.client</key>
<string>com.apple.printingmanager</string>
<key>com.apple.print.ticket.modDate</key>
<date>2006-07-16T23:01:52Z</date>
<key>com.apple.print.ticket.stateFlag</key>
<integer>0</integer>
</dict>
</array>
 
...</dict></plist>

Whenever MSIE encounters one of these large XML chunks in a jpg, all images from then on will not load until the browser is restarted. So it’s like a tripwire: once you set it off, everything breaks.

The fix? Well, I used a few lines of perl and some netpbm utilities. Make a file with all of the offending images and feed it to this script:

#!/usr/bin/perl -w
 
use strict;
 
open (F, "/tmp/bad-images.txt");
while () {
my $file = $_;
chomp($file);
print $file, "n";
 
$file =~ s/(/(/g;
$file =~ s/)/)/g;
$file =~ s/ / /g;
 
my $command = "cp $file /tmp/ &#038;&#038; anytopnm $file | pnmtojpeg > $file.2 &#038;&#038; mv $file.2 $file";
system($command);
 
}

If you’re going to have any luck with this, you’ll probably be running on some kind of Unix server with netpbm installed.

There’s some more info on this photo.net article.

4 thoughts on “MSIE hangs when trying to load .jpg images

  1. Hi P.

    Bea sent me here because I’m having problems with banner images not showing for IE users and I use iphoto. I set up the image as a background url from flickr using my blogger template (Type was still the title thru blogger). Looks great in firefox and safari, but came up blank on IE. But all the other photos I’d uploaded on posts appeared fine. I’ve taken it down, but any ideas on how to fix this would be appreciated.

    thanks in advance,
    Catherine

  2. You can open up the image in Photoshop and use “Save for web” instead of “Save as”.

    But if you’re using this as a background or something using CSS, there could be other reasons such as browser incompatibilities. If it’s the problem that I describe here, you can test by loading up the image’s URL in MSIE and seeing if all images on other sites refused to load.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">