Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial import

  • Loading branch information...
commit f6c179c690320cf956003e4c485734452fc8090b 0 parents
@pokeb authored
2  .gitattributes
@@ -0,0 +1,2 @@
+*.pbxproj -crlf -diff -merge
+
5 .gitignore
@@ -0,0 +1,5 @@
+build
+*.pbxuser
+*.mode1v3
+.DS_Store
+
59 ASIWebPageThumbnailGenerator.h
@@ -0,0 +1,59 @@
+//
+// ASIWebPageThumbnailGenerator.h
+//
+// Created by Ben Copsey on 05/12/2008.
+// Copyright 2008 All-Seeing Interactive. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+#import <Webkit/Webkit.h>
+
+@interface ASIWebPageThumbnailGenerator : NSObject {
+ NSURL *url;
+ NSString *thumbnailSavePath;
+ NSWindow *window ;
+ int timeoutSeconds;
+ BOOL complete;
+ BOOL failed;
+ WebView *webView;
+ BOOL enableJava;
+ BOOL enableJavaScript;
+ BOOL enablePlugins;
+ NSString *pageTitle;
+ int destinationWidth;
+ int destinationHeight;
+ int sourceWidth;
+ int sourceHeight;
+ int sourceX;
+ int sourceY;
+ int pageWidth;
+ int pageHeight;
+}
+
+
+- (void)cleanUpWebPreview;
+- (void)timeoutRequest;
+- (void)go;
+
+@property (assign) BOOL failed;
+@property (assign) BOOL complete;
+@property (retain) NSURL *url;
+@property (retain) NSString *thumbnailSavePath;
+@property (retain) NSWindow *window;
+@property (assign) int timeoutSeconds;
+@property (retain) WebView *webView;
+
+@property (assign) BOOL enableJava;
+@property (assign) BOOL enableJavaScript;
+@property (assign) BOOL enablePlugins;
+@property (retain) NSString *pageTitle;
+
+@property (assign) int destinationWidth;
+@property (assign) int destinationHeight;
+@property (assign) int sourceWidth;
+@property (assign) int sourceHeight;
+@property (assign) int sourceX;
+@property (assign) int sourceY;
+@property (assign) int pageWidth;
+@property (assign) int pageHeight;
+@end
241 ASIWebPageThumbnailGenerator.m
@@ -0,0 +1,241 @@
+//
+// ASIWebPageThumbnailGenerator.m
+//
+// Created by Ben Copsey on 05/12/2008.
+// Copyright 2008 All-Seeing Interactive. All rights reserved.
+//
+
+#import "ASIWebPageThumbnailGenerator.h"
+
+
+@implementation ASIWebPageThumbnailGenerator
+
+- (id)init
+{
+ self = [super init];
+ [self setEnableJava:NO];
+ [self setEnablePlugins:YES];
+ [self setEnableJavaScript:YES];
+ [self setDestinationWidth:0];
+ [self setDestinationHeight:0];
+ [self setSourceWidth:0];
+ [self setSourceHeight:0];
+ [self setSourceX:0];
+ [self setSourceY:0];
+ [self setPageWidth:0];
+ [self setPageHeight:0];
+ return self;
+}
+
+- (void)dealloc
+{
+ [url release];
+ [thumbnailSavePath release];
+ [webView release];
+ [window release];
+ [pageTitle release];
+ [super dealloc];
+}
+
+- (void)go
+{
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ // Make an offscreen window
+ NSRect r = NSMakeRect(-2500,-2500,800,600);
+ [self setWindow:[[[NSWindow alloc] initWithContentRect:r styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO] autorelease]];
+ [self setWebView:[[[WebView alloc] initWithFrame:r frameName:nil groupName:nil] autorelease]];
+
+ WebPreferences *prefs = [[[WebPreferences alloc] initWithIdentifier:@"ThumbnailGenerator"] autorelease];
+ [prefs setJavaEnabled:[self enableJava]];
+ [prefs setJavaScriptEnabled:[self enableJavaScript]];
+ [prefs setPlugInsEnabled:[self enablePlugins]];
+ [webView setPreferences:prefs];
+
+ [window setContentView:webView];
+ [webView setHostWindow:window];
+ [[[webView mainFrame] frameView] setAllowsScrolling:NO];
+
+ [[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:url]];
+ [webView setFrameLoadDelegate:self];
+
+ NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
+
+ // Record when the request started, so we can timeout if nothing happens
+ NSDate *startTime = [[NSDate date] retain];
+
+ // Wait for the request to finish
+ while (!complete) {
+
+ NSDate *now = [NSDate date];
+
+ // See if we need to timeout
+ if (timeoutSeconds > 0) {
+ if ([now timeIntervalSinceDate:startTime] > timeoutSeconds) {
+ [self timeoutRequest];
+ break;
+ }
+ }
+
+ [runLoop runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.5]];
+
+ [pool release];
+ pool = [[NSAutoreleasePool alloc] init];
+
+ }
+
+ [startTime release];
+
+ [pool release];
+ pool = nil;
+
+}
+
+- (void)timeoutRequest
+{
+ if ([webView estimatedProgress] > 0.6) {
+ [self webView:webView didFinishLoadForFrame:[webView mainFrame]];
+ return;
+ }
+ failed = YES;
+ [self cleanUpWebPreview];
+}
+
+- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
+{
+ if (frame != [sender mainFrame]) {
+ return;
+ }
+
+ NSView *docView = [[[sender mainFrame] frameView] documentView];
+ NSSize size = [docView bounds].size;
+
+ if (pageWidth > 0 && pageHeight > 0) {
+ size = NSMakeSize(pageWidth,pageHeight);
+ } else if (pageWidth > 0) {
+ size = NSMakeSize(pageWidth, size.height);
+ } else if (pageHeight > 0) {
+ size = NSMakeSize(size.width, pageHeight);
+ } else {
+ size = NSMakeSize(size.width+40,size.height+40);
+ }
+
+ if (size.width == 0 || size.height == 0) {
+ [self cleanUpWebPreview];
+ failed = YES;
+ [sender stopLoading:nil];
+ return;
+ }
+ [window setFrameOrigin:NSMakePoint(0-size.width-300, 0-size.height-300)];
+ [window setContentSize:size];
+
+
+
+ [[[sender mainFrame] frameView] scrollPoint:NSMakePoint(0,[docView bounds].size.height-size.height)];
+ [window display];
+ [window orderFront:nil];
+ [sender lockFocus];
+ NSBitmapImageRep *rep = [[[NSBitmapImageRep alloc] initWithFocusedViewRect:[sender bounds]] autorelease];
+ [sender unlockFocus];
+
+ if (rep) {
+ NSImage *img = [[[NSImage alloc] initWithData:[rep TIFFRepresentation]] autorelease];
+ [img setScalesWhenResized:YES];
+ [img lockFocus];
+ [[NSGraphicsContext currentContext] setImageInterpolation: NSImageInterpolationHigh];
+ [img unlockFocus];
+
+
+ float sW = sourceWidth;
+ if (sW == 0) {
+ sW = [img size].width;
+ }
+ float sH = sourceHeight;
+ if (sH == 0) {
+ sH = [img size].height;
+ }
+ double scale = 1;
+ NSSize thumbnailSize;
+ if (destinationWidth > 0 && destinationHeight > 0) {
+ thumbnailSize = NSMakeSize(destinationWidth,destinationHeight);
+ scale = destinationWidth/sW;
+ } else {
+
+ if (destinationWidth > 0) {
+ scale = destinationWidth/sW;
+ } else if (destinationHeight > 0) {
+ scale = destinationHeight/sH;
+ }
+ thumbnailSize = NSMakeSize(sW*scale,sH*scale);
+ }
+
+ NSImage *destinationImage = [[[NSImage alloc] initWithSize:thumbnailSize] autorelease];
+ [destinationImage lockFocus];
+ [[NSGraphicsContext currentContext] setImageInterpolation: NSImageInterpolationHigh];
+
+ NSRect r = NSMakeRect(sourceX, ([img size].height-(thumbnailSize.height/scale))-sourceY, thumbnailSize.width/scale, thumbnailSize.height/scale);
+ [img drawInRect:NSMakeRect(0,0,thumbnailSize.width,thumbnailSize.height) fromRect:r operation:NSCompositeSourceOver fraction:1.0];
+ [destinationImage unlockFocus];
+
+
+ NSData *data = [[NSBitmapImageRep imageRepWithData:[destinationImage TIFFRepresentation]] representationUsingType:NSPNGFileType properties:nil];
+ [data writeToFile:thumbnailSavePath atomically:NO];
+
+ }
+
+ [self cleanUpWebPreview];
+}
+
+- (void)webView:(WebView *)sender didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame
+{
+ if (frame != [sender mainFrame]) {
+ return;
+ }
+ failed = YES;
+ [self cleanUpWebPreview];
+}
+
+
+- (void)webView:(WebView *)sender didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame
+{
+ if (frame != [sender mainFrame]) {
+ return;
+ }
+ failed = YES;
+ [self cleanUpWebPreview];
+}
+
+- (void)webView:(WebView *)sender didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame
+{
+ [self setPageTitle:title];
+}
+
+- (void)cleanUpWebPreview
+{
+ if (window) {
+ [webView stopLoading:nil];
+ [window orderOut:nil];
+ }
+ complete = YES;
+}
+
+@synthesize failed;
+@synthesize complete;
+@synthesize url;
+@synthesize thumbnailSavePath;
+@synthesize window;
+@synthesize timeoutSeconds;
+@synthesize webView;
+@synthesize enableJava;
+@synthesize enableJavaScript;
+@synthesize enablePlugins;
+@synthesize pageTitle;
+@synthesize destinationWidth;
+@synthesize destinationHeight;
+@synthesize sourceWidth;
+@synthesize sourceHeight;
+@synthesize sourceX;
+@synthesize sourceY;
+@synthesize pageWidth;
+@synthesize pageHeight;
+@end
481 ASIWebThumbnail.xcodeproj/project.pbxproj
@@ -0,0 +1,481 @@
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 45;
+ objects = {
+
+/* Begin PBXBuildFile section */
+ 8DD76F770486A8DE00D96B5E /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 08FB7796FE84155DC02AAC07 /* main.m */; settings = {ATTRIBUTES = (); }; };
+ B5068E260EEBE71A000F351A /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5068E250EEBE71A000F351A /* Cocoa.framework */; };
+ B5068E350EEBE740000F351A /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5068E340EEBE740000F351A /* WebKit.framework */; };
+ B5068EF30EEBEDD0000F351A /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5068EF20EEBEDD0000F351A /* AppKit.framework */; };
+ B50690640EEC04FA000F351A /* ASIWebPageThumbnailGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = B50690630EEC04FA000F351A /* ASIWebPageThumbnailGenerator.m */; };
+ B50690820EEC0839000F351A /* ASIWebThumbnailGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = B50690810EEC0839000F351A /* ASIWebThumbnailGenerator.m */; };
+ B50690880EEC09D3000F351A /* AppController.m in Sources */ = {isa = PBXBuildFile; fileRef = B50690870EEC09D3000F351A /* AppController.m */; };
+ B506908A0EEC0A3B000F351A /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = B50690890EEC0A3B000F351A /* MainMenu.xib */; };
+ B50690C20EEC0AAE000F351A /* test-app-main.m in Sources */ = {isa = PBXBuildFile; fileRef = B50690C10EEC0AAE000F351A /* test-app-main.m */; };
+ B5C8952D0EEFE22C001CE72D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 08FB7796FE84155DC02AAC07 /* main.m */; };
+ B5C8952E0EEFE234001CE72D /* ASIWebPageThumbnailGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = B50690630EEC04FA000F351A /* ASIWebPageThumbnailGenerator.m */; };
+ B5C8953B0EEFE279001CE72D /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5068E340EEBE740000F351A /* WebKit.framework */; };
+ B5C8953D0EEFE282001CE72D /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5C8953C0EEFE282001CE72D /* CoreFoundation.framework */; };
+ B5C895950EEFE311001CE72D /* BundledThumbnailGenerator.app in Resources */ = {isa = PBXBuildFile; fileRef = B5C895250EEFE1F9001CE72D /* BundledThumbnailGenerator.app */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXFileReference section */
+ 08FB7796FE84155DC02AAC07 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
+ 09AB6884FE841BABC02AAC07 /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = /System/Library/Frameworks/CoreFoundation.framework; sourceTree = "<absolute>"; };
+ 8DD76F7E0486A8DE00D96B5E /* webthumbnail */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = webthumbnail; sourceTree = BUILT_PRODUCTS_DIR; };
+ B5068E250EEBE71A000F351A /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
+ B5068E340EEBE740000F351A /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; };
+ B5068EF20EEBEDD0000F351A /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
+ B50690620EEC04FA000F351A /* ASIWebPageThumbnailGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASIWebPageThumbnailGenerator.h; sourceTree = "<group>"; };
+ B50690630EEC04FA000F351A /* ASIWebPageThumbnailGenerator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASIWebPageThumbnailGenerator.m; sourceTree = "<group>"; };
+ B50690780EEC0803000F351A /* Test Application.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Test Application.app"; sourceTree = BUILT_PRODUCTS_DIR; };
+ B506907A0EEC0803000F351A /* Test Application-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Test Application-Info.plist"; sourceTree = "<group>"; };
+ B50690800EEC0839000F351A /* ASIWebThumbnailGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASIWebThumbnailGenerator.h; sourceTree = "<group>"; };
+ B50690810EEC0839000F351A /* ASIWebThumbnailGenerator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASIWebThumbnailGenerator.m; sourceTree = "<group>"; };
+ B50690860EEC09D3000F351A /* AppController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppController.h; sourceTree = "<group>"; };
+ B50690870EEC09D3000F351A /* AppController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppController.m; sourceTree = "<group>"; };
+ B50690890EEC0A3B000F351A /* MainMenu.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MainMenu.xib; sourceTree = "<group>"; };
+ B50690C10EEC0AAE000F351A /* test-app-main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "test-app-main.m"; sourceTree = "<group>"; };
+ B50692450EEC1EF4000F351A /* webthumbnail.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = webthumbnail.plist; sourceTree = "<group>"; };
+ B52DE06C0EEC3FE700586E27 /* GenerateThumbnail.app */ = {isa = PBXFileReference; lastKnownFileType = wrapper.application; path = GenerateThumbnail.app; sourceTree = "<group>"; };
+ B5C895250EEFE1F9001CE72D /* BundledThumbnailGenerator.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = BundledThumbnailGenerator.app; sourceTree = BUILT_PRODUCTS_DIR; };
+ B5C895270EEFE1F9001CE72D /* BundledThumbnailGenerator-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "BundledThumbnailGenerator-Info.plist"; sourceTree = "<group>"; };
+ B5C8953C0EEFE282001CE72D /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+ 8DD76F780486A8DE00D96B5E /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ B5068E260EEBE71A000F351A /* Cocoa.framework in Frameworks */,
+ B5068E350EEBE740000F351A /* WebKit.framework in Frameworks */,
+ B5068EF30EEBEDD0000F351A /* AppKit.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ B50690760EEC0803000F351A /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ B5C895230EEFE1F9001CE72D /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ B5C8953B0EEFE279001CE72D /* WebKit.framework in Frameworks */,
+ B5C8953D0EEFE282001CE72D /* CoreFoundation.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+ 08FB7794FE84155DC02AAC07 /* MakeThumbnail */ = {
+ isa = PBXGroup;
+ children = (
+ B52DE06C0EEC3FE700586E27 /* GenerateThumbnail.app */,
+ 08FB7795FE84155DC02AAC07 /* Source */,
+ 08FB779DFE84155DC02AAC07 /* External Frameworks and Libraries */,
+ 19C28FBDFE9D53C911CA2CBB /* Products */,
+ B5068E250EEBE71A000F351A /* Cocoa.framework */,
+ B5068E340EEBE740000F351A /* WebKit.framework */,
+ B5068EF20EEBEDD0000F351A /* AppKit.framework */,
+ B50690890EEC0A3B000F351A /* MainMenu.xib */,
+ B50692450EEC1EF4000F351A /* webthumbnail.plist */,
+ B506907A0EEC0803000F351A /* Test Application-Info.plist */,
+ B5C895270EEFE1F9001CE72D /* BundledThumbnailGenerator-Info.plist */,
+ B5C8953C0EEFE282001CE72D /* CoreFoundation.framework */,
+ );
+ name = MakeThumbnail;
+ sourceTree = "<group>";
+ };
+ 08FB7795FE84155DC02AAC07 /* Source */ = {
+ isa = PBXGroup;
+ children = (
+ B506919A0EEC1613000F351A /* Command Line Tool */,
+ B5C8951E0EEFE14D001CE72D /* CocoaThumbnailGenerator */,
+ B50691990EEC15F8000F351A /* Sample Application */,
+ );
+ name = Source;
+ sourceTree = "<group>";
+ };
+ 08FB779DFE84155DC02AAC07 /* External Frameworks and Libraries */ = {
+ isa = PBXGroup;
+ children = (
+ 09AB6884FE841BABC02AAC07 /* CoreFoundation.framework */,
+ );
+ name = "External Frameworks and Libraries";
+ sourceTree = "<group>";
+ };
+ 19C28FBDFE9D53C911CA2CBB /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ 8DD76F7E0486A8DE00D96B5E /* webthumbnail */,
+ B50690780EEC0803000F351A /* Test Application.app */,
+ B5C895250EEFE1F9001CE72D /* BundledThumbnailGenerator.app */,
+ );
+ name = Products;
+ sourceTree = "<group>";
+ };
+ B50691990EEC15F8000F351A /* Sample Application */ = {
+ isa = PBXGroup;
+ children = (
+ B50690860EEC09D3000F351A /* AppController.h */,
+ B50690870EEC09D3000F351A /* AppController.m */,
+ B50690C10EEC0AAE000F351A /* test-app-main.m */,
+ );
+ name = "Sample Application";
+ sourceTree = "<group>";
+ };
+ B506919A0EEC1613000F351A /* Command Line Tool */ = {
+ isa = PBXGroup;
+ children = (
+ 08FB7796FE84155DC02AAC07 /* main.m */,
+ B50690620EEC04FA000F351A /* ASIWebPageThumbnailGenerator.h */,
+ B50690630EEC04FA000F351A /* ASIWebPageThumbnailGenerator.m */,
+ );
+ name = "Command Line Tool";
+ sourceTree = "<group>";
+ };
+ B5C8951E0EEFE14D001CE72D /* CocoaThumbnailGenerator */ = {
+ isa = PBXGroup;
+ children = (
+ B50690800EEC0839000F351A /* ASIWebThumbnailGenerator.h */,
+ B50690810EEC0839000F351A /* ASIWebThumbnailGenerator.m */,
+ );
+ name = CocoaThumbnailGenerator;
+ sourceTree = "<group>";
+ };
+/* End PBXGroup section */
+
+/* Begin PBXNativeTarget section */
+ 8DD76F740486A8DE00D96B5E /* Standalone Command Line Tool */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 1DEB924708733DCA0010E9CD /* Build configuration list for PBXNativeTarget "Standalone Command Line Tool" */;
+ buildPhases = (
+ 8DD76F760486A8DE00D96B5E /* Sources */,
+ 8DD76F780486A8DE00D96B5E /* Frameworks */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = "Standalone Command Line Tool";
+ productInstallPath = "$(HOME)/bin";
+ productName = MakeThumbnail;
+ productReference = 8DD76F7E0486A8DE00D96B5E /* webthumbnail */;
+ productType = "com.apple.product-type.tool";
+ };
+ B50690770EEC0803000F351A /* Test Application */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = B506907D0EEC0805000F351A /* Build configuration list for PBXNativeTarget "Test Application" */;
+ buildPhases = (
+ B50690740EEC0803000F351A /* Resources */,
+ B50690750EEC0803000F351A /* Sources */,
+ B50690760EEC0803000F351A /* Frameworks */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = "Test Application";
+ productName = "Test Application";
+ productReference = B50690780EEC0803000F351A /* Test Application.app */;
+ productType = "com.apple.product-type.application";
+ };
+ B5C895240EEFE1F9001CE72D /* BundledThumbnailGenerator */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = B5C8952A0EEFE1F9001CE72D /* Build configuration list for PBXNativeTarget "BundledThumbnailGenerator" */;
+ buildPhases = (
+ B5C895210EEFE1F9001CE72D /* Resources */,
+ B5C895220EEFE1F9001CE72D /* Sources */,
+ B5C895230EEFE1F9001CE72D /* Frameworks */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = BundledThumbnailGenerator;
+ productName = BundledThumbnailGenerator;
+ productReference = B5C895250EEFE1F9001CE72D /* BundledThumbnailGenerator.app */;
+ productType = "com.apple.product-type.application";
+ };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+ 08FB7793FE84155DC02AAC07 /* Project object */ = {
+ isa = PBXProject;
+ buildConfigurationList = 1DEB924B08733DCA0010E9CD /* Build configuration list for PBXProject "ASIWebThumbnail" */;
+ compatibilityVersion = "Xcode 3.1";
+ hasScannedForEncodings = 1;
+ mainGroup = 08FB7794FE84155DC02AAC07 /* MakeThumbnail */;
+ projectDirPath = "";
+ projectRoot = "";
+ targets = (
+ 8DD76F740486A8DE00D96B5E /* Standalone Command Line Tool */,
+ B50690770EEC0803000F351A /* Test Application */,
+ B5C895240EEFE1F9001CE72D /* BundledThumbnailGenerator */,
+ );
+ };
+/* End PBXProject section */
+
+/* Begin PBXResourcesBuildPhase section */
+ B50690740EEC0803000F351A /* Resources */ = {
+ isa = PBXResourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ B5C895950EEFE311001CE72D /* BundledThumbnailGenerator.app in Resources */,
+ B506908A0EEC0A3B000F351A /* MainMenu.xib in Resources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ B5C895210EEFE1F9001CE72D /* Resources */ = {
+ isa = PBXResourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXResourcesBuildPhase section */
+
+/* Begin PBXSourcesBuildPhase section */
+ 8DD76F760486A8DE00D96B5E /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 8DD76F770486A8DE00D96B5E /* main.m in Sources */,
+ B50690640EEC04FA000F351A /* ASIWebPageThumbnailGenerator.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ B50690750EEC0803000F351A /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ B50690820EEC0839000F351A /* ASIWebThumbnailGenerator.m in Sources */,
+ B50690880EEC09D3000F351A /* AppController.m in Sources */,
+ B50690C20EEC0AAE000F351A /* test-app-main.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ B5C895220EEFE1F9001CE72D /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ B5C8952D0EEFE22C001CE72D /* main.m in Sources */,
+ B5C8952E0EEFE234001CE72D /* ASIWebPageThumbnailGenerator.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin XCBuildConfiguration section */
+ 1DEB924808733DCA0010E9CD /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ APPLY_RULES_IN_COPY_FILES = NO;
+ COPY_PHASE_STRIP = NO;
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_ENABLE_FIX_AND_CONTINUE = YES;
+ GCC_MODEL_TUNING = G5;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GENERATE_PKGINFO_FILE = YES;
+ INFOPLIST_FILE = webthumbnail.plist;
+ INFOPLIST_PREPROCESS = NO;
+ INSTALL_PATH = /usr/local/bin;
+ MACH_O_TYPE = mh_execute;
+ OTHER_LDFLAGS = "";
+ PRODUCT_NAME = webthumbnail;
+ };
+ name = Debug;
+ };
+ 1DEB924908733DCA0010E9CD /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ APPLY_RULES_IN_COPY_FILES = NO;
+ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+ GCC_MODEL_TUNING = G5;
+ GENERATE_PKGINFO_FILE = YES;
+ INFOPLIST_FILE = webthumbnail.plist;
+ INFOPLIST_PREPROCESS = NO;
+ INSTALL_PATH = /usr/local/bin;
+ MACH_O_TYPE = mh_execute;
+ OTHER_LDFLAGS = "";
+ PRODUCT_NAME = webthumbnail;
+ };
+ name = Release;
+ };
+ 1DEB924C08733DCA0010E9CD /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ARCHS = "$(ARCHS_STANDARD_32_BIT)";
+ GCC_C_LANGUAGE_STANDARD = c99;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ ONLY_ACTIVE_ARCH = YES;
+ PREBINDING = NO;
+ SDKROOT = macosx10.5;
+ };
+ name = Debug;
+ };
+ 1DEB924D08733DCA0010E9CD /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ARCHS = "$(ARCHS_STANDARD_32_BIT)";
+ GCC_C_LANGUAGE_STANDARD = c99;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ PREBINDING = NO;
+ SDKROOT = macosx10.5;
+ };
+ name = Release;
+ };
+ B506907B0EEC0804000F351A /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ COPY_PHASE_STRIP = NO;
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_ENABLE_FIX_AND_CONTINUE = YES;
+ GCC_MODEL_TUNING = G5;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h";
+ INFOPLIST_FILE = "Test Application-Info.plist";
+ INSTALL_PATH = "$(HOME)/Applications";
+ OTHER_LDFLAGS = (
+ "-framework",
+ Foundation,
+ "-framework",
+ AppKit,
+ );
+ PREBINDING = NO;
+ PRODUCT_NAME = "Test Application";
+ };
+ name = Debug;
+ };
+ B506907C0EEC0804000F351A /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ COPY_PHASE_STRIP = YES;
+ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+ GCC_ENABLE_FIX_AND_CONTINUE = NO;
+ GCC_MODEL_TUNING = G5;
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h";
+ INFOPLIST_FILE = "Test Application-Info.plist";
+ INSTALL_PATH = "$(HOME)/Applications";
+ OTHER_LDFLAGS = (
+ "-framework",
+ Foundation,
+ "-framework",
+ AppKit,
+ );
+ PREBINDING = NO;
+ PRODUCT_NAME = "Test Application";
+ ZERO_LINK = NO;
+ };
+ name = Release;
+ };
+ B5C895280EEFE1F9001CE72D /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ COPY_PHASE_STRIP = NO;
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_ENABLE_FIX_AND_CONTINUE = YES;
+ GCC_MODEL_TUNING = G5;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h";
+ INFOPLIST_FILE = "BundledThumbnailGenerator-Info.plist";
+ INSTALL_PATH = "$(HOME)/Applications";
+ OTHER_LDFLAGS = (
+ "-framework",
+ Foundation,
+ "-framework",
+ AppKit,
+ );
+ PREBINDING = NO;
+ PRODUCT_NAME = BundledThumbnailGenerator;
+ };
+ name = Debug;
+ };
+ B5C895290EEFE1F9001CE72D /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ COPY_PHASE_STRIP = YES;
+ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+ GCC_ENABLE_FIX_AND_CONTINUE = NO;
+ GCC_MODEL_TUNING = G5;
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h";
+ INFOPLIST_FILE = "BundledThumbnailGenerator-Info.plist";
+ INSTALL_PATH = "$(HOME)/Applications";
+ OTHER_LDFLAGS = (
+ "-framework",
+ Foundation,
+ "-framework",
+ AppKit,
+ );
+ PREBINDING = NO;
+ PRODUCT_NAME = BundledThumbnailGenerator;
+ ZERO_LINK = NO;
+ };
+ name = Release;
+ };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+ 1DEB924708733DCA0010E9CD /* Build configuration list for PBXNativeTarget "Standalone Command Line Tool" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 1DEB924808733DCA0010E9CD /* Debug */,
+ 1DEB924908733DCA0010E9CD /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ 1DEB924B08733DCA0010E9CD /* Build configuration list for PBXProject "ASIWebThumbnail" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 1DEB924C08733DCA0010E9CD /* Debug */,
+ 1DEB924D08733DCA0010E9CD /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ B506907D0EEC0805000F351A /* Build configuration list for PBXNativeTarget "Test Application" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ B506907B0EEC0804000F351A /* Debug */,
+ B506907C0EEC0804000F351A /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ B5C8952A0EEFE1F9001CE72D /* Build configuration list for PBXNativeTarget "BundledThumbnailGenerator" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ B5C895280EEFE1F9001CE72D /* Debug */,
+ B5C895290EEFE1F9001CE72D /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+/* End XCConfigurationList section */
+ };
+ rootObject = 08FB7793FE84155DC02AAC07 /* Project object */;
+}
45 ASIWebThumbnailGenerator.h
@@ -0,0 +1,45 @@
+//
+// ASIWebThumbnailGenerator.h
+// ASIWebThumbnail
+//
+// Created by Ben Copsey on 07/12/2008.
+// Copyright 2008 All-Seeing Interactive. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface ASIWebThumbnailGenerator : NSOperation {
+ NSString *url;
+ NSString *savePath;
+ NSString *pageTitle;
+ BOOL enableJava;
+ BOOL enableJavaScript;
+ BOOL enablePlugins;
+ NSPoint sourceOrigin;
+ NSSize destinationSize;
+ NSSize sourceSize;
+ NSSize pageSize;
+ int timeoutSeconds;
+ NSObject *representedObject;
+ id delegate;
+}
+- (void)main;
+- (NSImage *)image;
+
+@property (retain) NSString *url;
+@property (retain) NSString *savePath;
+@property (retain) NSString *pageTitle;
+@property (assign) BOOL enableJava;
+@property (assign) BOOL enableJavaScript;
+@property (assign) BOOL enablePlugins;
+@property (assign) NSPoint sourceOrigin;
+@property (assign) NSSize destinationSize;
+@property (assign) NSSize sourceSize;
+@property (assign) NSSize pageSize;
+
+@property (assign) int timeoutSeconds;
+@property (retain) NSObject *representedObject;
+@property (assign) id delegate;
+
+@end
157 ASIWebThumbnailGenerator.m
@@ -0,0 +1,157 @@
+//
+// ASIWebThumbnailGenerator.m
+// ASIWebThumbnail
+//
+// Created by Ben Copsey on 07/12/2008.
+// Copyright 2008 All-Seeing Interactive. All rights reserved.
+//
+
+#import "ASIWebThumbnailGenerator.h"
+
+
+@implementation ASIWebThumbnailGenerator
+
+
+- (id)init
+{
+ self = [super init];
+ [self setUrl:nil];
+ [self setSavePath:nil];
+ [self setEnableJava:NO];
+ [self setEnableJavaScript:YES];
+ [self setEnablePlugins:YES];
+ [self setSourceOrigin:NSMakePoint(0,0)];
+ [self setDestinationSize:NSMakeSize(0,0)];
+ [self setSourceSize:NSMakeSize(0,0)];
+ [self setPageSize:NSMakeSize(0,0)];
+ [self setTimeoutSeconds:0];
+ return self;
+}
+
+- (void)dealloc
+{
+ [url release];
+ [savePath release];
+ [pageTitle release];
+ [representedObject release];
+ [super dealloc];
+}
+
+- (void)main
+{
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ NSTask *task = [[[NSTask alloc] init] autorelease];
+
+ // Setup arugments
+ NSMutableArray *args = [NSMutableArray array];
+
+
+ if (enableJava) {
+ [args addObject:@"-j"];
+ } else {
+ [args addObject:@"-J"];
+ }
+ if (enableJavaScript) {
+ [args addObject:@"-s"];
+ } else {
+ [args addObject:@"-S"];
+ }
+ if (enablePlugins) {
+ [args addObject:@"-p"];
+ } else {
+ [args addObject:@"-P"];
+ }
+ if (destinationSize.width > 0) {
+ [args addObject:[NSString stringWithFormat:@"-w%f",destinationSize.width]];
+ }
+ if (destinationSize.height > 0) {
+ [args addObject:[NSString stringWithFormat:@"-h%f",destinationSize.height]];
+ }
+ if (sourceSize.width > 0) {
+ [args addObject:[NSString stringWithFormat:@"-W%f",sourceSize.width]];
+ }
+ if (sourceSize.height > 0) {
+ [args addObject:[NSString stringWithFormat:@"-H%f",sourceSize.height]];
+ }
+ if (pageSize.width > 0) {
+ [args addObject:[NSString stringWithFormat:@"-a%f",pageSize.width]];
+ }
+ if (pageSize.height > 0) {
+ [args addObject:[NSString stringWithFormat:@"-b%f",pageSize.height]];
+ }
+ if (sourceOrigin.x > 0) {
+ [args addObject:[NSString stringWithFormat:@"-x%f",sourceOrigin.x]];
+ }
+ if (sourceOrigin.y > 0) {
+ [args addObject:[NSString stringWithFormat:@"-y%f",sourceOrigin.y]];
+ }
+ if (timeoutSeconds > 0) {
+ [args addObject:[NSString stringWithFormat:@"-z%hi",timeoutSeconds]];
+ }
+ [args addObject:@"-t"];
+
+ [args addObject:url];
+ if (!savePath) {
+ [self setSavePath:[NSTemporaryDirectory() stringByAppendingPathComponent:[[NSProcessInfo processInfo] globallyUniqueString]]];
+ }
+ [args addObject:savePath];
+
+
+ [task setArguments:args];
+
+ NSString *path = [[[[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"BundledThumbnailGenerator.app"] stringByAppendingPathComponent:@"Contents"] stringByAppendingPathComponent:@"MacOS"] stringByAppendingPathComponent:@"BundledThumbnailGenerator"];
+ [task setLaunchPath:path];
+
+
+ NSPipe *errorPipe = [NSPipe pipe];
+ [task setStandardError:errorPipe];
+
+ NSPipe *outputPipe = [NSPipe pipe];
+ [task setStandardOutput:outputPipe];
+
+ [task launch];
+
+ [task waitUntilExit];
+
+ NSData *outputData = [[outputPipe fileHandleForReading] readDataToEndOfFile];
+ [self setPageTitle:[[[NSString alloc] initWithBytes:[outputData bytes] length:[outputData length] encoding:NSUTF8StringEncoding] autorelease]];
+
+ //If something went wrong, log the error and stop
+ if ([task terminationStatus] != 0) {
+
+ NSData *errorData = [[errorPipe fileHandleForReading] readDataToEndOfFile];
+ NSString *error = [[[NSString alloc] initWithBytes:[errorData bytes] length:[errorData length] encoding:NSUTF8StringEncoding] autorelease];
+
+ NSLog(@"Output: %@",pageTitle);
+ NSLog(@"Error: %@",error);
+ } else {
+
+ if ([delegate respondsToSelector:@selector(thumbnailGenerationSucceededFor:)]) {
+ [delegate performSelectorOnMainThread:@selector(thumbnailGenerationSucceededFor:) withObject:self waitUntilDone:NO];
+ }
+ }
+
+ [pool release];
+
+}
+
+- (NSImage *)image
+{
+ return [[[NSImage alloc] initWithContentsOfFile:savePath] autorelease];
+}
+
+@synthesize url;
+@synthesize savePath;
+@synthesize pageTitle;
+@synthesize enableJava;
+@synthesize enableJavaScript;
+@synthesize enablePlugins;
+@synthesize sourceOrigin;
+@synthesize destinationSize;
+@synthesize sourceSize;
+@synthesize pageSize;
+@synthesize timeoutSeconds;
+@synthesize representedObject;
+@synthesize delegate;
+@end
20 AppController.h
@@ -0,0 +1,20 @@
+//
+// AppController.h
+// ASIWebThumbnail
+//
+// Created by Ben Copsey on 07/12/2008.
+// Copyright 2008 All-Seeing Interactive. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface AppController : NSObject {
+ IBOutlet NSMatrix *matrix;
+ IBOutlet NSProgressIndicator *progress;
+ NSOperationQueue *queue;
+}
+
+- (IBAction)generateThumbnail:(id)sender;
+
+@end
55 AppController.m
@@ -0,0 +1,55 @@
+//
+// AppController.m
+// ASIWebThumbnail
+//
+// Created by Ben Copsey on 07/12/2008.
+// Copyright 2008 All-Seeing Interactive. All rights reserved.
+//
+
+#import "AppController.h"
+#import "ASIWebThumbnailGenerator.h"
+
+@implementation AppController
+
+- (IBAction)generateThumbnail:(id)sender
+{
+ [progress setDoubleValue:0];
+ [queue cancelAllOperations];
+ [queue release];
+ queue = [[NSOperationQueue alloc] init];
+ [queue setMaxConcurrentOperationCount:4];
+
+ NSArray *urls = [NSArray arrayWithObjects:
+ @"http://slashdot.org",
+ @"http://wired.com",
+ @"http://news.bbc.co.uk",
+ @"http://theregister.co.uk",
+ @"http://github.com",
+ @"http://adobe.com",
+ @"http://allseeing-i.com/ASIHTTPRequest",
+ @"http://stackoverflow.com",
+ @"http://www.yellow5.com/pokey/archive/index422.html",
+ nil];
+
+
+ int i=0;
+ for (NSString *url in urls) {
+ ASIWebThumbnailGenerator *generator = [[[ASIWebThumbnailGenerator alloc] init] autorelease];
+ [generator setUrl:url];
+ [generator setPageSize:NSMakeSize(1000,0)];
+ [generator setSourceSize:NSMakeSize(1000,700)];
+ [generator setDestinationSize:NSMakeSize(300,200)];
+ [generator setRepresentedObject:[[matrix cells] objectAtIndex:i]];
+ [generator setDelegate:self];
+ [queue addOperation:generator];
+ i++;
+ }
+}
+
+- (void)thumbnailGenerationSucceededFor:(ASIWebThumbnailGenerator *)generator
+{
+ [(NSImageCell *)[generator representedObject] setImage:[generator image]];
+ [progress setDoubleValue:[progress doubleValue]+1];
+}
+
+@end
26 BundledThumbnailGenerator-Info.plist
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleExecutable</key>
+ <string>ThumbnailGenerator</string>
+ <key>CFBundleIdentifier</key>
+ <string>com.allseeinginteractive.thumbnailgenerator</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1.0</string>
+ <key>LSBackground</key>
+ <string>1</string>
+ <key>NSMainNibFile</key>
+ <string>MainMenu</string>
+ <key>NSPrincipalClass</key>
+ <string>NSApplication</string>
+</dict>
+</plist>
24 LICENSE
@@ -0,0 +1,24 @@
+* Copyright (c) 2008, All-Seeing Interactive
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+* * Neither the name of the All-Seeing Interactive nor the
+* names of its contributors may be used to endorse or promote products
+* derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY All-Seeing Interactive ''AS IS'' AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL All-Seeing Interactive BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3,410 MainMenu.xib
3,410 additions, 0 deletions not shown
6 README.textile
@@ -0,0 +1,6 @@
+ASIWebThumbnail is:
+* A command line tool for Mac OS X that generates thumbnails from web pages "See examples >":http://allseeing-i.com/ASIWebThumbnail/Examples
+* An API to use an embedded version of the tool in your Cocoa applications "Read more >":http://allseeing-i.com/ASIWebThumbnail/API-Documentation
+ASIWebThumbnail uses the "WebKit":http://webkit.org framework built-in Mac OS X to render web pages. As such, it should support any content that WebKit supports, including HTML/XML + CSS, SVG, content rendered by Javascript (Canvas, AJAX, DOM etc), Java, as well as Flash and other plugins.
+
+Documentation is available "here":http://allseeing-i.com/ASIWebThumbnail.
24 Test Application-Info.plist
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIdentifier</key>
+ <string>com.yourcompany.${PRODUCT_NAME:identifier}</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1.0</string>
+ <key>NSMainNibFile</key>
+ <string>MainMenu</string>
+ <key>NSPrincipalClass</key>
+ <string>NSApplication</string>
+</dict>
+</plist>
188 main.m
@@ -0,0 +1,188 @@
+//
+// webthumbnail
+//
+// Created by Ben Copsey on 05/12/2008.
+// Copyright 2008 All-Seeing Interactive. All rights reserved.
+//
+// See: http://www.gnu.org/software/libtool/manual/libc/Getopt.html#Getopt
+// And: http://www-128.ibm.com/developerworks/aix/library/au-unix-getopt.html
+// ...for hints on how getopt_long works
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <getopt.h>
+#include <Cocoa/Cocoa.h>
+#import "ASIWebPageThumbnailGenerator.h"
+
+// Valid arguments
+static const struct option longOptions[] =
+{
+ {"enable-java", no_argument, NULL, 'j'},
+ {"disable-java", no_argument, NULL, 'J'},
+ {"enable-javascript", no_argument, NULL, 's'},
+ {"disable-javascript", no_argument, NULL, 'S'},
+ {"enable-plugins", no_argument, NULL, 'p'},
+ {"disable-plugins", no_argument, NULL, 'P'},
+ {"page-width", required_argument, NULL, 'a'},
+ {"page-height", required_argument, NULL, 'b'},
+ {"width", required_argument, NULL, 'w'},
+ {"height", required_argument, NULL, 'h'},
+ {"source-width", required_argument, NULL, 'W'},
+ {"source-height", required_argument, NULL, 'H'},
+ {"source-x", required_argument, NULL, 'x'},
+ {"source-y", required_argument, NULL, 'y'},
+ {"timeout", required_argument, NULL, 'z'},
+ {"launch", no_argument, NULL, 'l'},
+ {"print-page-title", no_argument, NULL, 't'},
+ {"help", no_argument, NULL, '?'},
+ { NULL, no_argument, NULL, 0 }
+};
+
+
+static const NSString *usage = @"Usage: webthumbnail <options> http://myurl.com/mypage.html /path/to/save.png\nRun webthumbnail --help for information on valid options\n";
+static const NSString *help = @"webthumbnail - Copyright All-Seeing Interactive, 2008\n\nUsage: webthumbnail <options> http://myurl.com/mypage.html /path/to/save.png\n\nControlling the generated image (All measurements are specified in pixels)\n\n--width (-w) Set the width of the generated thumbnail (Defaults to page-width)\n--height (-h) Set the height of the generated thumbnail (Defaults to page-height)\n--source-width (-W) Set the width of the area to be rendered in the source image (Defaults to page-width)\n--source-height (-H) Set the height of the area to be rendered in the source image (Defaults to page-height)\n--source-x (-x) Set the left point in the source image (Defaults to 0)\n--source-y (-y) Set the top point in the source image (Defaults to 0)\n--page-width (-a) Set the width of the page to be used when rendering (Defaults to the computed width of the page)\n--page-height (-b) Set the height of the page to be used when rendering (Defaults to the computed height of the page)\n\nHandling web content\n\n--enable-java (-j) Enable Java (Default is OFF)\n--disable-java (-J) Disable Java\n--enable-javascript (-s) Enable JavaScript (Default is ON)\n--disable-javascript (-S) Disable JavaScript\n--enable-plugins (-p) Enable Plugins (Flash etc, Default in ON)\n--disable-plugins (-P) Disable Plugins\n--timeout (-z) Timeout after the specified number of seconds (Default is never timeout)\n\nGeneral options\n\n--print-page-title (-t) Print the title of an HTML page, if one was found\n--launch (-l) Open the generated image when rendering is complete\n--help (-?) Show these instructions\n\nExamples\n\n$ webthumbnail http://www.allseeing-i.com image.png\nRenders an image of the website at full size, containing the full page\n\n$ webthumbnail --width=300 --height=200 --source-height=600 http://www.allseeing-i.com image.png\nRenders an image of the website to a 300x200 thumbnail, cropping the source page to 600 pixels tall\n\n$ webthumbnail -w300 -h200 -H600 http://www.allseeing-i.com image.png\nDoes the same thing, using the shorter syntax\n\n$ webthumbnail -w300 -h200 -W300 -h200 -x100 -y100 -l http://www.allseeing-i.com image.png\nRenders a 300x200 portion of the page, at full size, starting from left:100 pixels top:100 pixels, and opens the image\n";
+
+static const char *optionsString = "jJsSpPw:h:W:H:x:y:a:b:z:lt?";
+
+int main (int argc, char **argv) {
+
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ ASIWebPageThumbnailGenerator *generator = [[[ASIWebPageThumbnailGenerator alloc] init] autorelease];
+ [generator setTimeoutSeconds:10];
+
+ BOOL showHelp = NO;
+ BOOL badParameters = NO;
+
+ int optionIndex = 0;
+ int option = getopt_long (argc, argv, optionsString, longOptions, &optionIndex);
+
+ BOOL printPageTitle = NO;
+ BOOL launchThumbnail = NO;
+
+ while (option != -1) {
+
+ switch (option)
+ {
+ case 'j':
+ [generator setEnableJava:YES];
+ break;
+ case 'J':
+ [generator setEnableJava:NO];
+ break;
+ case 's':
+ [generator setEnableJavaScript:YES];
+ break;
+ case 'S':
+ [generator setEnableJavaScript:NO];
+ break;
+ case 'p':
+ [generator setEnablePlugins:YES];
+ break;
+ case 'P':
+ [generator setEnablePlugins:NO];
+ break;
+ case 'w':
+ [generator setDestinationWidth:[[NSString stringWithCString:optarg encoding:NSUTF8StringEncoding] intValue]];
+ break;
+ case 'h':
+ [generator setDestinationHeight:[[NSString stringWithCString:optarg encoding:NSUTF8StringEncoding] intValue]];
+ break;
+ case 'W':
+ [generator setSourceWidth:[[NSString stringWithCString:optarg encoding:NSUTF8StringEncoding] intValue]];
+ break;
+ case 'H':
+ [generator setSourceHeight:[[NSString stringWithCString:optarg encoding:NSUTF8StringEncoding] intValue]];
+ break;
+ case 'x':
+ [generator setSourceX:[[NSString stringWithCString:optarg encoding:NSUTF8StringEncoding] intValue]];
+ break;
+ case 'y':
+ [generator setSourceY:[[NSString stringWithCString:optarg encoding:NSUTF8StringEncoding] intValue]];
+ break;
+ case 'a':
+ [generator setPageWidth:[[NSString stringWithCString:optarg encoding:NSUTF8StringEncoding] intValue]];
+ break;
+ case 'b':
+ [generator setPageHeight:[[NSString stringWithCString:optarg encoding:NSUTF8StringEncoding] intValue]];
+ break;
+ case 'z':
+ [generator setTimeoutSeconds:[[NSString stringWithCString:optarg encoding:NSUTF8StringEncoding] intValue]];
+ break;
+ case 't':
+ printPageTitle = YES;
+ break;
+ case 'l':
+ launchThumbnail = YES;
+ break;
+ case '?':
+ showHelp = YES;
+ break;
+ default:
+ badParameters = YES;
+ break;
+ }
+
+ option = getopt_long (argc, argv, optionsString, longOptions, &optionIndex);
+ }
+
+
+ if (!showHelp && !badParameters) {
+
+ int numInputFiles = argc - optind;
+
+ // The url and path to save to aren't set, give up
+ if (numInputFiles > 2) {
+ CFShow((CFStringRef *)@"ERROR: Too many parameters given\n");
+ badParameters = YES;
+ } else if (numInputFiles < 2) {
+ CFShow((CFStringRef *)@"ERROR: Missing URL and/or save path\n");
+ badParameters = YES;
+
+ // Grab the url and path to save to from the end of the arguments
+ } else {
+ char **sourceAndDestination = argv + optind;
+ NSString *url = [NSString stringWithCString:*sourceAndDestination encoding:NSUTF8StringEncoding];
+ sourceAndDestination++;
+ NSString *destinationPath = [NSString stringWithCString:*sourceAndDestination encoding:NSUTF8StringEncoding];
+ if (!url || !destinationPath) {
+ CFShow((CFStringRef *)@"ERROR: Missing URL and/or save path\n");
+ badParameters = YES;
+ }
+ [generator setUrl:[[[NSURL alloc] initWithString:url] autorelease]];
+ [generator setThumbnailSavePath:destinationPath];
+ }
+
+ }
+
+
+ int err = 0;
+
+ if (badParameters) {
+ CFShow((CFStringRef *)usage);
+
+ } else if (showHelp) {
+ CFShow((CFStringRef *)help);
+
+ // We got valid arguments, let's attempt to generate the thumbnail
+ } else {
+ [NSApplication sharedApplication]; // Connect to the window server
+ [generator go];
+ err = (!generator || [generator failed]);
+ if (err == 0) {
+ if (printPageTitle) {
+ CFShow((CFStringRef*)[generator pageTitle]);
+ }
+ if (launchThumbnail) {
+ [[NSWorkspace sharedWorkspace] openFile:[generator thumbnailSavePath]];
+ }
+ }
+
+ }
+
+
+ [pool release];
+
+ return err;
+
+}
14 test-app-main.m
@@ -0,0 +1,14 @@
+//
+// main.m
+// CocoaTrails
+//
+// Created by Ben Copsey on 27/12/2006.
+// Copyright All-Seeing Interactive, 2007. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+int main(int argc, char *argv[])
+{
+ return NSApplicationMain(argc, (const char **) argv);
+}
20 webthumbnail.plist
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleExecutable</key>
+ <string>webthumbnail</string>
+ <key>CFBundleIdentifier</key>
+ <string>com.allseeing-i.webthumbnail</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>webthumbnail</string>
+ <key>CFBundleVersion</key>
+ <string>0.3</string>
+ <key>LSBackgroundOnly</key>
+ <string>1</string>
+</dict>
+</plist>
Please sign in to comment.
Something went wrong with that request. Please try again.