Source Code

/**
 * Create a fake polaroid effect using Pixenate's ImageMagick bridge plugin.
 *
 * Pixenate plugin development in Javascript - Yay!
 */ 
function polaroid(degrees, text)
{
    //
    // image is the current image being edited (see PXN8.initialize())
    //
    var image = PXN8.ImageMagick.start();

    var size = PXN8.getImageSize();
    //
    // crop the image to a square shape.
    //
    image.Method("Crop",{height: size.height, width: size.height, x: (size.width-size.height)/2});

    var xBorderWidth = size.height / 8;
    var yBorderWidth = xBorderWidth * 2;
    
    //
    // create a polaroid-style border
    //
    var border = new PXN8.ImageMagick();
    border.Method("Set", {size:  (size.height + xBorderWidth*2) + "x" + (size.height + yBorderWidth*2)});
    border.Method("Read", "xc:#ffffff");
    //
    // superimpose the cropped photo on top of the border
    //
    border.Method("Composite", {image: image, compose: "Over", x: xBorderWidth, y: xBorderWidth});
    border.Method("Annotate", {text: text, gravity: "South", y: xBorderWidth, pointsize: 12});

    // 
    // create a drop-shadow
    var shadow = new PXN8.ImageMagick();
    shadow.Method("Set",{size: (size.height + (xBorderWidth * 2) + 4) + "x" + (size.height + (yBorderWidth*2)+4)});
    shadow.Method("Read","xc:white");
    shadow.Method("Draw",{primitive: "Rectangle",points: "1,1," +(size.height+ (xBorderWidth* 2 + 1)) + "," + (size.height + (yBorderWidth*2)+1), fill: "#808080"});
    shadow.Method("Blur","2.0x2.0");
    //
    // superimpose the border on top of the shadow
    //
    shadow.Method("Composite",{image: border, compose: "Over", x: 1, y: 1});
    // 
    // rotate the image slightly
    //
    shadow.Method("Rotate", {degrees: degrees, background: "white"});
    
    PXN8.ImageMagick.end(shadow);
}