title: how can I save an NSImageView layer to a PNG on disk?
body: <p>I'm trying to do the following batch processing:</p>
  
  <ol>
  <li>load an image    </li>
  <li>scale it</li>
  <li>add a rounded border to it</li>
  <li>save the new
      image as PNG</li>
  </ol>
  
  <p>So far, I came up with this:</p>
  
  <pre><code>CGPoint center = CGPointMake(self.window.frame.size.width / 2., self.window.frame.size.height / 2.);
        [[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh];
        NSImage * newThumbnail = [[NSImage alloc] initWithData:[NSData dataWithContentsOfURL:[files objectAtIndex:0]]];
        NSImageView *imageView = [[NSImageView alloc] initWithFrame:CGRectMake(center.x - (57/2.), center.y - (80/2.), 57, 80)];
        [imageView setWantsLayer:YES];
  
        imageView.layer.borderColor = [[NSColor blackColor] CGColor];
        imageView.layer.cornerRadius = 4;
        imageView.layer.masksToBounds = YES;
        imageView.layer.borderWidth = 1.0;
        imageView.image = newThumbnail;
  </code></pre>
  
  <p>And now I think I'm missing telling the layer to redender to some context?
  maybe something like <code>[imageView.layer drawInContext: some context (NS o CG?)];</code> and saving that context to disk. But I'm confused as to:</p>
  
  <p>what context, </p>
  
  <p>whether to go from context to NSData to disk, </p>
  
  <p>or if I need an intermediate image somewhere before saving. </p>
  
  <p>Basically, between CALayers and CGLayers and NS objects and UI objects (I know I'm in OS X Cocoa here and it's no UIKit and I'm also not using CG stuff so far) I have no idea how to turn the above into a png.</p>