Need help converting PSD layers to individual images.
Posted: 2007-03-01T22:05:10-07:00
I'm not quite sure what I'm doing wrong here. I'm trying to load a PSD and save each of it's layers as individual images. If I attempt to output PSDs for each layer all I get is black but if I output in any other format, I sometimes get something that resembles the layer, but has diagonal stripes of colors all over.
Here is the code I am using:
All this does is search for any layers that begin with a period and attempt to save that layer out as <file name>.<layer name>.<extension>.
Any help would be appreciated!
Here is the code I am using:
Code: Select all
int main( int argc, char ** argv)
{
Magick::InitializeMagick(*argv);
std::string filePath = "C:\\test.psd";
std::string fileName = filePath;
RemoveFileNamePath( fileName );
RemoveFileNameExtension( fileName );
ImageInfo* image_info = CloneImageInfo((ImageInfo *) NULL);
strncpy_s(image_info->filename, filePath.c_str(), MaxTextExtent - 1);
ExceptionInfo exception;
GetExceptionInfo(&exception);
printf( "Processing File: %s\n\n", filePath.c_str() );
Image* image = ReadImage( image_info, &exception );
// Loop through all the layers
for ( ; image != (Image *)NULL; image = GetNextImageInList(image) )
{
// Get layer name
const char* szLayerName = GetImageProperty( image, "label" );
if( !szLayerName || szLayerName[0] != '.' )
continue;
std::string outFileName( fileName );
outFileName += szLayerName;
std::string outFilePath( "C:\\" );
outFilePath += outFileName;
outFilePath += ".tif";
std::transform( outFilePath.begin(), outFilePath.end(), outFilePath.begin(), tolower );
strncpy_s( image->filename, outFilePath.c_str(), MaxTextExtent - 1 );
strncpy_s( image_info->filename, outFilePath.c_str(), MaxTextExtent - 1 );
printf( "\tSaving layer %s as file %s... ", szLayerName, outFilePath.c_str() );
// Write out layer.
WriteImage( image_info, image );
printf( "Complete\n" );
}
/* Clean up */
DestroyImageInfo( image_info );
(void)DestroyExceptionInfo( &exception );
DestroyMagick();
printf( "\nProcessing Complete.\n\n" );
system("PAUSE");
return 0;
}
Any help would be appreciated!