determine image type

  • Hi folks,
    I have a lot of files from MacOS 9 on the server, but they doesn't
    contain file extensions nor have correct file type in the header. I
    know that it's a mix of jpg, psd and tiff files and I'm able to
    create icons for them. it means I can create a NSImage of the data.
    How can I find which type of NSImage I have?

    Thanks
    Robert
  • Great,
    that's it.

    Thanks
    Robert

    On 5.10.2006, at 12:02, Heinrich Giesen wrote:

    > Hello,
    >
    > On 04.10.2006, at 18:07, Robert Cerny wrote:
    >
    >> I have a lot of files from MacOS 9 on the server, but they doesn't
    >> contain file extensions nor have correct file type in the header. I
    >> know that it's a mix of jpg, psd and tiff files and I'm able to
    >> create icons for them. it means I can create a NSImage of the data.
    >> How can I find which type of NSImage I have?
    >
    > Let us assume you create an image with:
    >
    > NSData *imgData = [[NSData alloc] initWithContentsOfFile:filePath];
    > NSImage *img = [[NSImage alloc] initWithData:imgData];
    >
    > Now position to the contents of imgData:
    >
    > const char *buffer = [imgData bytes];
    > and check the first bytes of the buffer, i.e. check the magic numbers.
    >
    > (some examples):
    >
    > BOOL isJPEG = (buffer[0]==0xFF) && (buffer[1]==0xD8) && (buffer[2]
    > ==0xFF);
    > BOOL isLitteEndianTIFF = (buffer[0]=='I') && (buffer[1]=='I');
    > BOOL isBigEndianTIFF = (buffer[0]=='M') && (buffer[1]=='M');
    > BOOL isGIF = (buffer[0]=='G') && (buffer[1]=='I') && (buffer[2]=='F');
    > BOOL isBMP = (buffer[0]=='B') && (buffer[1]=='M');
    > BOOL isPSD = (buffer[0]=='8') && (buffer[1]=='B') && (buffer[2]
    > =='P') && (buffer[3]=='S');
    > BOOL isPNG = (buffer[0]==0x89) && (buffer[1]=='P') && (buffer[2]
    > =='N') && (buffer[3]=='G')
    > && (buffer[4]==0x0d) && (buffer[5]==0x0a) && (buffer[6]==0x1a)
    > && (buffer[7]==0x0a);
    >
    > NSImage and NSImageRep do the same to identify the image type.
    >
    > Good luck
    > Heinrich
    >
    > --
    > Heinrich Giesen
    > <giesenH...>
    >
    >
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today