Information wants to be free...

EXIF Remover

It would seem that some websites have started to use over-zealous (and faulty) detection algorithms when uploading images. I have had problems uploading images that are rotated 90 degrees, because the websites in question decides to look at the EXIF data in the JPEG images instead of the actual bitmap, and then counter-rotates the images! To fix this problem, I have made a simple program to just strip away all the EXIF data in a JPEG image.

Here is the C code:

#include <stdio.h>

int main(void)
{
  int c, jpeg_marker_found, length_low, length_high, in_exif;

  jpeg_marker_found = in_exif = 0;
  while ((c = fgetc(stdin)) != EOF) {

    if (in_exif > 0) {
      in_exif--;
      continue;
    }

    if (jpeg_marker_found && c == 0xE1) { /* APP1 marker, used by EXIF. */
      if ((length_high = fgetc(stdin)) == EOF)
        return 1;
      if ((length_low = fgetc(stdin)) == EOF)
        return 1;
      /* Remove one byte to avoid printing the next marker's first 0xFF... */
      in_exif = length_low + (length_high * 0x100) - 1;
      /* ...and this marker's 0xE1 will also not be printed. */
    } else {
      fputc(c, stdout);
    }

    jpeg_marker_found = (c == 0xFF) ? 1 : 0;
  }

  return 0;
}
          


Topic: Scripts and Code, by Kjetil @ 11/12-2010, Article Link