1

Photoshop is making me quite confused.

I am able to create a multi-layer tif image from photoshop and read it into my program (cocoa build)

I am able to create a multi-layer tif in my program and have it read by tiffutil.

photoshop, however, will not recognize my file as a multi-layer tif. Only the first image comes in.

what sort of information do I need to include? And how do I go about doing that? When I write out a gif (kUTTypeGIF) instead of a tif (kUTTypeTIFF) everything turns out fine.


Here's a bit of code to show what I'm doing... (Using Xcode 4.1 CoreFoundation) The below code should take in 3 JPEG images and create separate layers writing out a multi-layer tiff file. It works fine with GIF but not with TIFF

// create CFURLRef for 3 separate images.
NSString *filePath1 = [[NSBundle mainBundle] pathForResource:@"1image" ofType:@"jpg"];
CFURLRef url1 = (CFURLRef)[NSURL fileURLWithPath:filePath1];

NSString *filePath2 = [[NSBundle mainBundle] pathForResource:@"2image" ofType:@"jpg"];
CFURLRef url2 = (CFURLRef)[NSURL fileURLWithPath:filePath2];

NSString *filePath3 = [[NSBundle mainBundle] pathForResource:@"3image" ofType:@"jpg"];
CFURLRef url3 = (CFURLRef)[NSURL fileURLWithPath:filePath3];


// setup to write to data object
NSMutableData          * finalImageData = [NSMutableData data];
CGImageSourceRef       imageSourceRef = nil;
// this one does not work
CGImageDestinationRef  imageDestRef = CGImageDestinationCreateWithData((CFMutableDataRef)finalImageData, kUTTypeTIFF, 3, nil);
// This one works
// CGImageDestinationRef  imageDestRef = CGImageDestinationCreateWithData((CFMutableDataRef)finalImageData, kUTTypeGIF, 3, nil);

// build the final image
imageSourceRef = CGImageSourceCreateWithURL(url1, nil);
CGImageDestinationAddImageFromSource(imageDestRef, imageSourceRef, 0, nil);

imageSourceRef = CGImageSourceCreateWithURL(url2, nil);
CGImageDestinationAddImageFromSource(imageDestRef, imageSourceRef, 0, nil);

imageSourceRef = CGImageSourceCreateWithURL(url3, nil);
CGImageDestinationAddImageFromSource(imageDestRef, imageSourceRef, 0, nil);

CGImageDestinationFinalize(imageDestRef);
CFRelease(imageDestRef);
CFRelease(imageSourceRef);

// write out the final image data
[finalImageData writeToFile:@"outfile.tif" atomically:YES];
// [finalImageData writeToFile:@"outfile.gif" atomically:YES];
P-Rod
  • 471
  • 1
  • 5
  • 18
  • 1
    I guess you need to provide some more info, code snippet, what library you use to create these files ... for people to be able to help you, – Ali Oct 22 '12 at 19:59
  • Okay. Good idea. I've added code above. – P-Rod Oct 23 '12 at 00:04
  • ok, what does the file size tell you, does it like the three layers are in there but photoshop cant find them, or its like only one gets in there? – Ali Oct 23 '12 at 02:00
  • yes. All the images are in the file. In fact if I use tiffutil to get information on the file I see each representation. I can access them in my program if I want to see them. Just not in photoshop. And strangely if I use tiffutil to get information on the photoshop generated multi-layer tiff I only see information for 1 representation – P-Rod Oct 23 '12 at 03:32
  • My gut tells me that I should add some property value during the CGImageDestinationCreateWithData phase. But I can't find anything that seems appropriate. – P-Rod Oct 23 '12 at 03:44
  • When I load the image into another program such as "ViewIt" all layers are identified. – P-Rod Oct 23 '12 at 06:17
  • your best bet is to either find the standard Photoshop follows/expects, or contact Adobe developers, OR make two files with the same set of layers once with photoshop and once with your code and compare them to see what is different – Ali Oct 23 '12 at 12:33
  • I found a hint to what's going on in the Adobe File Formats PDF. "Photoshop reads the first Image File Directory (IFD) and writes one IFD per file." this explains why photoshop doesn't read my tiff correctly. For some reason they write all image representations into one IFD. I'm not sure how or why. But it also explains why a multi-layer tiff from photoshop only shows 1 representation with tiffutil. – P-Rod Oct 23 '12 at 16:32
  • So, how then, do I create subIFDs such that each of my images is a subIFD of a solitary IFD? – P-Rod Oct 23 '12 at 17:28
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/18493/discussion-between-ali-and-p-rod) – Ali Oct 23 '12 at 19:03
  • Try replacing all of your "nil" with "NULL" – Albert Renshaw Jan 22 '13 at 03:47

0 Answers0