Image

An image object. New images can be imported using a Document's addImage: function. The image object's CGImage accessors can be used to access the underlying image data.
 
Multiple image objects can reference the same underlying document image data, but also have differing opacity and cropRect settings. This allows several shapes to use the same underlying image fill.
 
Settings

Image Representations

Creating Copies

cropRect

returns CGRect; settable

Gets / Sets the crop rectangle of the image. This property specifies the placement and scale of the image within its parent shape. The default crop rect is { 0, 0, 1, 1 }.
 

Example: scale and center the image fill of the frontmost selected shape

var shape = [[[app activeDocument] selectedShapes] lastObject]
var img = [[shape fill] image]

if(img)
    img.cropRect = CGRectMake(-0.5, -0.5, 2, 2)

CGImage

returns CGImage

Gets a CGImage representation of the underlying image data.
 

Example: create a new document and path shape using the frontmost selected shape's image fill

var shape = [[[app activeDocument] selectedShapes] lastObject]
var img = [[shape fill] image]

if(img)
{
    var cgImage = [img CGImage]
    var size = CGSizeMake(CGImageGetWidth(cgImage), CGImageGetHeight(cgImage))
    var doc = [app addDocument]
    var newImg = [doc addImage:cgImage]

    // create a new path with the image bounds
    var path = [doc addPath]
    [path addMoveTo:CGPointMake(0, 0)]
    [path addLineTo:CGPointMake(size.width, 0)]
    [path addLineTo:CGPointMake(size.width, size.height)]
    [path addLineTo:CGPointMake(0, size.height)]
    [path addClose]

    // create a new path shape and set the image fill 
    var shape = [[doc activeLayer] addPathShape:path]
    [shape fill].image = newImg
    [shape stroke].width = 0
}

duplicate

returns Image

Creates and returns a duplicate of this image object, referencing the same underlying document image data. The duplicate image object can be applied as another shape's fill and have different cropRect and opacity settings.

opacity

returns Float; settable

Gets / Sets the opacity of the image. The opacity value is between 0 and 1.
 

Example: set the image fill of the frontmost selected shape to 50% opacity

var shape = [[[app activeDocument] selectedShapes] lastObject]
var img = [[shape fill] image]

if(img)
    img.opacity = 0.50

thumbnailCGImageToFitSize:

returns Float; input CGSize

Gets / Sets the opacity of the image. The opacity value is between 0 and 1.
 

Example: create a new document and shape using a thumbnail of the frontmost selected shape's image fill

var shape = [[[app activeDocument] selectedShapes] lastObject]
var img = [[shape fill] image]

if(img)
{
    var size = CGSizeMake(128, 128)
    var cgImage = [img thumbnailCGImageToFitSize:size]
    var doc = [app addDocument]
    var newImg = [doc addImage:cgImage]

    // create a new path with the image bounds
    var path = [doc addPath]
    [path addMoveTo:CGPointMake(0, 0)]
    [path addLineTo:CGPointMake(size.width, 0)]
    [path addLineTo:CGPointMake(size.width, size.height)]
    [path addLineTo:CGPointMake(0, size.height)]
    [path addClose]

    // create a new path shape and set the image fill 
    var shape = [[doc activeLayer] addPathShape:path]
    [shape fill].image = newImg
    [shape stroke].width = 0
}

Next: Appearance