#include int main(int argc, const char *argv[]) { if (argc != 3) { printf("usage: imageconvert \n"); exit(EXIT_FAILURE); } const char *in_path = argv[1]; const char *out_path = argv[2]; CFStringRef in_path_string = CFStringCreateWithCString( kCFAllocatorDefault, in_path, kCFStringEncodingUTF8); CFURLRef in_path_url = CFURLCreateWithFileSystemPath( kCFAllocatorDefault, in_path_string, kCFURLPOSIXPathStyle, FALSE); CGImageSourceRef image_source = CGImageSourceCreateWithURL( in_path_url, NULL); CGImageRef image = CGImageSourceCreateImageAtIndex( image_source, 0, NULL); CFStringRef out_path_string = CFStringCreateWithCString( kCFAllocatorDefault, out_path, kCFStringEncodingUTF8); CFURLRef out_path_url = CFURLCreateWithFileSystemPath( kCFAllocatorDefault, out_path_string, kCFURLPOSIXPathStyle, FALSE); CFStringRef out_extension = CFStringCreateWithCString( kCFAllocatorDefault, strrchr(out_path, '.') + 1, kCFStringEncodingUTF8); CFStringRef out_type = UTTypeCreatePreferredIdentifierForTag( kUTTagClassFilenameExtension, out_extension, NULL); CGImageDestinationRef image_destination = CGImageDestinationCreateWithURL( out_path_url, out_type, 1, NULL); CGImageDestinationAddImage( image_destination, image, NULL); CGImageDestinationFinalize(image_destination); CFRelease(image_destination); CFRelease(out_type); CFRelease(out_extension); CFRelease(out_path_url); CFRelease(out_path_string); CFRelease(image); CFRelease(image_source); CFRelease(in_path_url); CFRelease(in_path_string); return EXIT_SUCCESS; }