This repository has been archived by the owner on Feb 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.m
66 lines (57 loc) · 2.18 KB
/
main.m
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//
// main.m
// quickiee
//
// Created by Dieter Komendera on 11/14/07. http://komendera.com
// Licence: DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
// http://sam.zoy.org/wtfpl/COPYING
#import <Cocoa/Cocoa.h>
#import <QuickLook/QuickLook.h>
#import "NSImage+QuickLook.h"
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
if(argc < 3) {
return -1;
}
NSString *srcfile = [[NSString stringWithUTF8String: argv[1]] stringByExpandingTildeInPath];
NSString *dstfile = [[NSString stringWithUTF8String: argv[2]] stringByExpandingTildeInPath];
NSSize dstsize;
if(argc >= 4) {
NSArray *sizes = [[NSString stringWithUTF8String: argv[3]] componentsSeparatedByString:@"x"];
int maxwidth = [[sizes objectAtIndex: 0] intValue];
int maxheight = [[sizes objectAtIndex: 1] intValue];
dstsize = NSMakeSize(maxwidth, maxheight);
} else {
dstsize = NSMakeSize(200,200);
}
NSString *format;
if(argc >= 5) {
format = [NSString stringWithUTF8String:argv[4]];
} else {
format = @"png";
}
NSImage *image = [NSImage imageWithPreviewOfFileAtPath:srcfile
ofSize:dstsize
asIcon:NO];
NSBitmapImageRep *rep = [[image representations] objectAtIndex: 0];
NSData *data;
if([format caseInsensitiveCompare:@"png"] == 0) {
data = [rep representationUsingType: NSPNGFileType properties: nil];
} else if([format caseInsensitiveCompare:@"tiff"] == 0) {
data = [rep representationUsingType: NSTIFFFileType properties: nil];
} else if([format caseInsensitiveCompare:@"bmp"] == 0) {
data = [rep representationUsingType: NSBMPFileType properties: nil];
} else if([format caseInsensitiveCompare:@"gif"] == 0) {
data = [rep representationUsingType: NSGIFFileType properties: nil];
} else if([format caseInsensitiveCompare:@"jpg"] == 0){
data = [rep representationUsingType: NSJPEGFileType properties: nil];
} else {
printf("unknown format: ");
printf([format UTF8String]);
printf("\n");
return -1;
}
[data writeToFile: dstfile atomically: NO];
[pool release];
return 0;
}