ImageReference

An image inside an OmniGraffle document. The image can be part of the fill for more than one Solid graphic, and all of them will refer to the same ImageReference.

Instance Properties

Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Donec id elit non mi porta gravida at eget metus. Maecenas sed diam eget risus varius blandit sit amet non magna. Nullam id dolor id nibh ultricies vehicula ut id elit.

Counting Images

Curabitur blandit tempus porttitor.

imageCount = images.length title = 'IMAGE COUNT' if (imageCount == 0){ message = 'There are no images in this document.' } else if (imageCount == 1){ message = 'There is one image in this document.' } else { message = 'There are ' + imageCount + ' images in this document.' } new Alert(title, message).show(function(result){})
omnigraffle:///omnijs-run?script=imageCount%20%3D%20images%2Elength%0Atitle%20%3D%20%27IMAGE%20COUNT%27%0Aif%20%28imageCount%20%3D%3D%200%29%7B%0A%09message%20%3D%20%27There%20are%20no%20images%20in%20this%20document%2E%27%0A%7D%20else%20if%20%28imageCount%20%3D%3D%201%29%7B%0A%09message%20%3D%20%27There%20is%20one%20image%20in%20this%20document%2E%27%0A%7D%20else%20%7B%0A%09message%20%3D%20%27There%20are%20%27%20%2B%20imageCount%20%2B%20%27%20images%20in%20this%20document%2E%27%0A%7D%0Anew%20Alert%28title%2C%20message%29%2Eshow%28function%28result%29%7B%7D%29

Checking for Single Selected Image

Donec sed odio dui. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Nullam quis risus eget urna mollis ornare vel eu leo. Donec id elit non mi porta gravida at eget metus. Donec ullamcorper nulla non metus auctor fringilla. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Donec ullamcorper nulla non metus auctor fringilla.

if (document.windows[0].selection.solids.length != 1){ title = "SELECTION ERROR" message = "Please select a single solid." new Alert(title, message).show(function(result){}) } else { cnvs = document.windows[0].selection.canvas solid = document.windows[0].selection.solids[0] if (solid.image instanceof ImageReference){ // processing code goes here } else { title = "NO IMAGE" message = "The solid does not contain an image." new Alert(title, message).show(function(result){}) } }
omnigraffle:///omnijs-run?script=if%20%28document%2Ewindows%5B0%5D%2Eselection%2Egraphics%2Elength%20%21%3D%201%29%7B%0A%09title%20%3D%20%22SELECTION%20ERROR%22%0A%09message%20%3D%20%22Please%20select%20a%20single%20graphic%2E%22%0A%09new%20Alert%28title%2C%20message%29%2Eshow%28function%28result%29%7B%7D%29%0A%7D%20else%20%7B%0A%09cnvs%20%3D%20document%2Ewindows%5B0%5D%2Eselection%2Ecanvas%0A%09graphic%20%3D%20document%2Ewindows%5B0%5D%2Eselection%2Egraphics%5B0%5D%0A%09if%20%28graphic%2Eimage%20instanceof%20ImageReference%29%7B%0A%09%09%2F%2F%20processing%20code%20goes%20here%0A%09%7D%20else%20%7B%0A%09%09title%20%3D%20%22NO%20IMAGE%22%0A%09%09message%20%3D%20%22The%20graphic%20does%20not%20contain%20an%20image%2E%22%0A%09%09new%20Alert%28title%2C%20message%29%2Eshow%28function%28result%29%7B%7D%29%0A%09%7D%0A%7D

Sizing Containing Graphic to Fit Image

Etiam porta sem malesuada magna mollis euismod. Maecenas sed diam eget risus varius blandit sit amet non magna. Maecenas faucibus mollis interdum. Donec ullamcorper nulla non metus auctor fringilla. Nullam id dolor id nibh ultricies vehicula ut id elit. Integer posuere erat a ante venenatis dapibus posuere velit aliquet.

if (document.windows[0].selection.solids.length != 1){ title = "SELECTION ERROR" message = "Please select a single solid." new Alert(title, message).show(function(result){}) } else { cnvs = document.windows[0].selection.canvas solid = document.windows[0].selection.solids[0] if (solid.image instanceof ImageReference){ newGeometry = solid.geometry newGeometry.size = solid.image.originalSize solid.geometry = newGeometry } else { title = "NO IMAGE" message = "The solid does not contain an image." new Alert(title, message).show(function(result){}) } }
omnigraffle:///omnijs-run?script=if%20%28document%2Ewindows%5B0%5D%2Eselection%2Esolids%2Elength%20%21%3D%201%29%7B%0A%09title%20%3D%20%22SELECTION%20ERROR%22%0A%09message%20%3D%20%22Please%20select%20a%20single%20solid%2E%22%0A%09new%20Alert%28title%2C%20message%29%2Eshow%28function%28result%29%7B%7D%29%0A%7D%20else%20%7B%0A%09cnvs%20%3D%20document%2Ewindows%5B0%5D%2Eselection%2Ecanvas%0A%09solid%20%3D%20document%2Ewindows%5B0%5D%2Eselection%2Esolids%5B0%5D%0A%09if%20%28solid%2Eimage%20instanceof%20ImageReference%29%7B%0A%09%09newGeometry%20%3D%20solid%2Egeometry%0A%09%09newGeometry%2Esize%20%3D%20solid%2Eimage%2EoriginalSize%0A%09%09solid%2Egeometry%20%3D%20newGeometry%0A%09%7D%20else%20%7B%0A%09%09title%20%3D%20%22NO%20IMAGE%22%0A%09%09message%20%3D%20%22The%20solid%20does%20not%20contain%20an%20image%2E%22%0A%09%09new%20Alert%28title%2C%20message%29%2Eshow%28function%28result%29%7B%7D%29%0A%09%7D%0A%7D

Importing images

Maecenas faucibus mollis interdum. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Donec id elit non mi porta gravida at eget metus. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Donec id elit non mi porta gravida at eget metus.

Import a Chosen Image File

The following example script demonstrates how to import a chosen image file into an OmniGraffle document.

The dialog presented by the choose() method (line 1) is “modal,” which means the script will not continue until the user has either selected a file or performed a tap|click on the dialog’s Cancel button. A positive selection returns the related URL object, and a cancellation returns a null value, that may be used as an indication to throw an error in order to stop the script (line 2).

Lines 3 through 5 of the script are designed to extract a URL string from the URL object, and to derive the unencoded file name of the chosen image.

imageURL = URL.choose('public.image') if (imageURL == null){throw new Error('user cancelled')} urlString = imageURL.string var imageFileName = urlString.substr(urlString.lastIndexOf('/') + 1) imageFileName = decodeURIComponent(imageFileName) imageURL.fetch(function(data){ cnvs = document.windows[0].selection.canvas aGraphic = cnvs.newShape() aGraphic.strokeThickness = 0 aGraphic.shadowColor = null aGraphic.fillColor = null aGraphic.image = addImage(data) aGraphic.name = imageFileName imageSize = aGraphic.image.originalSize imgX = imageSize.width imgY = imageSize.height aRect = new Rect(aGraphic.geometry.x, aGraphic.geometry.y, imgX, imgY) aGraphic.geometry = aRect document.windows[0].selection.view.select([aGraphic]) })
omnigraffle:///omnijs-run?script=imageURL%20%3D%20URL%2Echoose%28%27public%2Eimage%27%29%0Aif%20%28imageURL%20%3D%3D%20null%29%7Bthrow%20new%20Error%28%27user%20cancelled%27%29%7D%0AurlString%20%3D%20imageURL%2Estring%0Avar%20imageFileName%20%3D%20urlString%2Esubstr%28urlString%2ElastIndexOf%28%27%2F%27%29%20%2B%201%29%0AimageFileName%20%3D%20decodeURIComponent%28imageFileName%29%0AimageURL%2Efetch%28function%28data%29%7B%0A%09cnvs%20%3D%20document%2Ewindows%5B0%5D%2Eselection%2Ecanvas%0A%09aGraphic%20%3D%20cnvs%2EnewShape%28%29%0A%09aGraphic%2EstrokeThickness%20%3D%200%0A%09aGraphic%2EshadowColor%20%3D%20null%0A%09aGraphic%2EfillColor%20%3D%20null%0A%09aGraphic%2Eimage%20%3D%20addImage%28data%29%0A%09aGraphic%2Ename%20%3D%20imageFileName%0A%09imageSize%20%3D%20aGraphic%2Eimage%2EoriginalSize%0A%09imgX%20%3D%20imageSize%2Ewidth%0A%09imgY%20%3D%20imageSize%2Eheight%0A%09aRect%20%3D%20new%20Rect%28aGraphic%2Egeometry%2Ex%2C%20aGraphic%2Egeometry%2Ey%2C%20imgX%2C%20imgY%29%0A%09aGraphic%2Egeometry%20%3D%20aRect%0A%09document%2Ewindows%5B0%5D%2Eselection%2Eview%2Eselect%28%5BaGraphic%5D%29%0A%7D%29

The importation of the image file into the document is accomplished by using the fetch() method (line 6 — 18), an asynchronous handler that employs a call-back function to provide the means for dealing with the imported image. In other words, the fetch process runs separate from any remaining script statements, and when done with its import, executes the call-back function passed to it as its direct parameter. The call-back function contains the code for creating and manipulating the graphic that contains the image.

Note the use of the addImage() method (line 11) to insert the image data passed to the call-back function by the fetch() method, into the graphic object previously created using the newShape() method (line 7). The created graphic is named to match the image file name (line 12), and then its dimensions are adjusted to match the default size of the imported image (lines 13 — 16).

The last script statement selects the created image graphic in the document (line 17).

Importing an Image from the Internet

Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec ullamcorper nulla non metus auctor fringilla. Etiam porta sem malesuada magna mollis euismod. Nullam quis risus eget urna mollis ornare vel eu leo. Nullam id dolor id nibh ultricies vehicula ut id elit.

// Download image from internet and add to document urlString = "https://omni-automation.com/gfx/18207.jpg" var imageFileName = urlString.substr(urlString.lastIndexOf('/') + 1) var url = URL.fromString(urlString) url.fetch(function (data){ cnvs = document.windows[0].selection.canvas aGraphic = cnvs.newShape() aGraphic.strokeThickness = 0 aGraphic.shadowColor = null aGraphic.fillColor = null aGraphic.image = addImage(data) aGraphic.name = imageFileName imageSize = aGraphic.image.originalSize imgX = imageSize.width imgY = imageSize.height aRect = new Rect(aGraphic.geometry.x, aGraphic.geometry.y, imgX, imgY) aGraphic.geometry = aRect document.windows[0].selection.view.select([aGraphic]) })
omnigraffle:///omnijs-run?script=urlString%20%3D%20%22https%3A%2F%2Fomni-automation%2Ecom%2Fgfx%2F18207%2Ejpg%22%0Avar%20imageFileName%20%3D%20urlString%2Esubstr%28urlString%2ElastIndexOf%28%27%2F%27%29%20%2B%201%29%0Avar%20url%20%3D%20URL%2EfromString%28urlString%29%0Aurl%2Efetch%28function%20%28data%29%7B%0A%09cnvs%20%3D%20document%2Ewindows%5B0%5D%2Eselection%2Ecanvas%0A%09aGraphic%20%3D%20cnvs%2EnewShape%28%29%0A%09aGraphic%2EstrokeThickness%20%3D%200%0A%09aGraphic%2EshadowColor%20%3D%20null%0A%09aGraphic%2EfillColor%20%3D%20null%0A%09aGraphic%2Eimage%20%3D%20addImage%28data%29%0A%09aGraphic%2Ename%20%3D%20imageFileName%0A%09imageSize%20%3D%20aGraphic%2Eimage%2EoriginalSize%0A%09imgX%20%3D%20imageSize%2Ewidth%0A%09imgY%20%3D%20imageSize%2Eheight%0A%09aRect%20%3D%20new%20Rect%28aGraphic%2Egeometry%2Ex%2C%20aGraphic%2Egeometry%2Ey%2C%20imgX%2C%20imgY%29%0A%09aGraphic%2Egeometry%20%3D%20aRect%0A%09document%2Ewindows%5B0%5D%2Eselection%2Eview%2Eselect%28%5BaGraphic%5D%29%0A%7D%29
UNDER CONSTRUCTION

This webpage is in the process of being developed. Any content may change and may not be accurate or complete at this time.

DISCLAIMER