/*--- title: Resize and crop images group: Media summary: imagelib: dimensions, a thumbnail, a crop and an inline preview. ---*/ requirelib("filelib"); requirelib("imagelib"); var src = "user:/Photo/sunset.jpg"; var size = imagelib.getImageDimension(src); console.log("Original: " + size[0] + " x " + size[1]); if (!filelib.fileExists("user:/Photo/thumbs")) { filelib.mkdir("user:/Photo/thumbs"); } // A height of 0 keeps the aspect ratio. imagelib.resizeImage(src, "user:/Photo/thumbs/sunset_200.jpg", 200, 0); imagelib.cropImage(src, "user:/Photo/thumbs/sunset_crop.png", 160, 100, 320, 200); var thumb = imagelib.getImageDimension("user:/Photo/thumbs/sunset_200.jpg"); console.log("Thumbnail: " + thumb[0] + " x " + thumb[1]); // renderPreview with an empty destination returns a data URL, which the // Response tab shows as an image. var preview = imagelib.renderPreview(src, "", 320, 200); sendResp(preview.dataURL);