Illustrator script to create symbols from images in folder

Time to give back to the community...
Here is a script I recently devised to bulk create symbols from images in a folder. Tested with Illustrator CC 2014.
// Import Folder's Files as Symbols - Illustrator CC script
// Description: Creates symbols from images in the designated folder into current document
// Author     : Oscar Rines (oscarrines (at) gmail.com)
// Version    : 1.0.0 on 2014-09-21
// Reused code from "Import Folder's Files as Layers - Illustrator CS3 script"
// by Nathaniel V. KELSO ([email protected])
#target illustrator
function getFolder() {
  return Folder.selectDialog('Please select the folder to be imported:', Folder('~'));
function symbolExists(seekInDoc, seekSymbol) {
    for (var j=0; j < seekInDoc.symbols.length; j++) {
        if (seekInDoc.symbols[j].name == seekSymbol) {
            return true;
    return false;
function importFolderContents(selectedFolder) {
    var activeDoc = app.activeDocument;     //Active object reference
  // if a folder was selected continue with action, otherwise quit
  if (selectedFolder) {
        var newsymbol;              //Symbol object reference
        var placedart;              //PlacedItem object reference
        var fname;                  //File name
        var sname;                  //Symbol name
        var symbolcount = 0;        //Number of symbols added
        var templayer = activeDoc.layers.add(); //Create a new temporary layer
        templayer.name = "Temporary layer"
        var imageList = selectedFolder.getFiles(); //retrieve files in the folder
        // Create a palette-type window (a modeless or floating dialog),
        var win = new Window("palette", "SnpCreateProgressBar", {x:100, y:100, width:750, height:310});
        win.pnl = win.add("panel", [10, 10, 740, 255], "Progress"); //add a panel to contain the components
        win.pnl.currentTaskLabel = win.pnl.add("statictext", [10, 18, 620, 33], "Examining: -"); //label indicating current file being examined
        win.pnl.progBarLabel = win.pnl.add("statictext", [620, 18, 720, 33], "0/0"); //progress bar label
        win.pnl.progBarLabel.justify = 'right';
        win.pnl.progBar = win.pnl.add("progressbar", [10, 35, 720, 60], 0, imageList.length-1); //progress bar
        win.pnl.symbolCount = win.pnl.add("statictext", [10, 70, 710, 85], "Symbols added: 0"); //label indicating number of symbols created
        win.pnl.symbolLabel = win.pnl.add("statictext", [10, 85, 710, 100], "Last added symbol: -"); //label indicating name of the symbol created
        win.pnl.errorListLabel = win.pnl.add("statictext", [10, 110, 720, 125], "Error log:"); //progress bar label
        win.pnl.errorList = win.pnl.add ("edittext", [10, 125, 720, 225], "", {multiline: true, scrolling: true}); //errorlist
        //win.pnl.errorList.graphics.font = ScriptUI.newFont ("Arial", "REGULAR", 7);
        //win.pnl.errorList.graphics.foregroundColor = win.pnl.errorList.graphics.newPen(ScriptUIGraphics.PenType.SOLID_COLOR, [1, 0, 0, 1], 1);
        win.doneButton = win.add("button", [640, 265, 740, 295], "OK"); //button to dispose the panel
        win.doneButton.onClick = function () //define behavior for the "Done" button
            win.close();
        win.center();
        win.show();
        //Iterate images
        for (var i = 0; i < imageList.length; i++) {
            win.pnl.currentTaskLabel.text = 'Examining: ' + imageList[i].name; //update current file indicator
            win.pnl.progBarLabel.text = i+1 + '/' + imageList.length; //update file count
            win.pnl.progBar.value = i+1; //update progress bar
            if (imageList[i] instanceof File) {         
                fname = imageList[i].name.toLowerCase(); //convert file name to lowercase to check for supported formats
                if( (fname.indexOf('.eps') == -1) &&
                    (fname.indexOf('.png') == -1)) {
                    win.pnl.errorList.text += 'Skipping ' + imageList[i].name + '. Not a supported type.\r'; //log error
                    continue; // skip unsupported formats
                else {
                    sname = imageList[i].name.substring(0, imageList[i].name.lastIndexOf(".") ); //discard file extension
                    // Check for duplicate symbol name;
                    if (symbolExists(activeDoc, sname)) {
                        win.pnl.errorList.text += 'Skipping ' + imageList[i].name + '. Duplicate symbol for name: ' + sname + '\r'; //log error
                    else {
                        placedart = activeDoc.placedItems.add(); //get a reference to a new placedItem object
                        placedart.file = imageList[i]; //link the object to the image on disk
                        placedart.name =  sname; //give the placed item a name
                        placedart.embed();   //make this a RasterItem
                        placedart = activeDoc.rasterItems.getByName(sname); //get a reference to the newly created raster item
                        newsymbol = activeDoc.symbols.add(placedart); //add the raster item to the symbols                 
                        newsymbol.name = sname; //name the symbol
                        symbolcount++; //update the count of symbols created
                        placedart.remove(); //remove the raster item from the canvas
                        win.pnl.symbolCount.text = 'Symbols added: ' + symbolcount; //update created number of symbols indicator
                        win.pnl.symbolLabel.text = 'Last added symbol: ' + sname; //update created symbol indicator
            else {
                win.pnl.errorList.text += 'Skipping ' + imageList[i].name + '. Not a regular file.\r'; //log error
            win.update(); //required so pop-up window content updates are shown
        win.pnl.currentTaskLabel.text = ''; //clear current file indicator
        // Final verdict
        if (symbolcount >0) {
            win.pnl.symbolLabel.text = 'Symbol library changed. Do not forget to save your work';
        else {
            win.pnl.symbolLabel.text = 'No new symbols added to the library';
        win.update(); //update window contents
        templayer.remove(); //remove the temporary layer
    else {
        alert("Action cancelled by user");
if ( app.documents.length > 0 ) {
    importFolderContents( getFolder() );
else{
    Window.alert("You must open at least one document.");

Thank you, nice job & I am looking forward to trying it out!

Similar Messages

  • Can I batch create symbols from layers?

    I have Illustrator files of some fairly complicated schematics that I will be bringing in to Flash. The layers are already well organized and named so I would like to select particular layers, hit a "create symbols" button and have all of the selected layers turned into separate symbols that have the same name as their layer name. I would even be willing to code something to do this but I can't find any information about how it can be done.
    I know that I can import an Illustrator file into Flash and select layers that I can then make into movie clips but again, I have to manually select the layer, tell it to be a movie clip and then give it an instance name. I would be happy to try to automate that process as well but haven't found any info on how it can be done either.
    Does anyone have any ideas on how I can batch create symbols from my existing layers?

    I figured this out using recursion. Pasted here in case it helps someone else:
    #target Illustrator
    var docRef = app.activeDocument;
    var layersRef = app.activeDocument.layers;
    var layersCount = layersRef.length;
    var mySymbolInstance = null;
    if ( app.documents.length > 0 ) {
        // if the file is not empty, loop through all levels
        recurseLayers(docRef.layers);
        clearEmptyLayers();
        alert("I'm done");
    function recurseLayers(objArray) {
        // loop through main layers
        for (var l = 0; l < objArray.length; l++) {
            // loop through secondary layers
            if (objArray[l].layers.length > 0) {
                recurseLayers(objArray[l].layers);
            // loop through first level groups
            if (objArray[l].groupItems.length > 0) {
                recurseGroups(objArray[l].groupItems);
                // create a group
                var layerGrp = objArray[l].groupItems.add();
                //give new group the same name as the old group
                var layerName = objArray[l].name;
                layerGrp.name = layerName;
                // get all page items from group
                var layerGrpPageItems =  objArray[l].pageItems;
                //alert("how many group page items: " + layerGrpPageItems.length);
                for (var li= layerGrpPageItems.length-1; li >0; li--) {
                    // will become the symbol name
                    var layerPageItemName = layerGrpPageItems[li].name;
                    // if it's not already a symbol, make it into one
                    if (layerGrpPageItems[li].typename == "SymbolItem") {
                        layerGrpPageItems[li].moveToBeginning(layerGrp);
                    } else {
                        // create symbols
                        createSymbol(layerGrpPageItems[li], layerGrpPageItems[li].name);
                        // add symbols to group
                        mySymbolInstance.moveToBeginning(layerGrp);
                        // remove original content
                        layerGrpPageItems[li].remove();
                // create symbols from layer
                createSymbol(layerGrp, layerName);
                // remove original layer content
                layerGrp.remove();
    function recurseGroups(objArray) {
        for (var g = 0; g < objArray.length; g++) {
            // loop through second level groups
            if (objArray[g].groupItems.length > 0) {
                recurseGroups(objArray[g].groupItems);
                // create a group
                var grp = objArray[g].groupItems.add();
               //give new group the same name as the old group
                var groupName = objArray[g].name;
                grp.name = groupName;
                //alert("which group is this? " + groupName);
                // get all page items from group
                var grpPageItems =  objArray[g].pageItems;
                //alert("how many group page items: " + grpPageItems.length);
                for (var gi= grpPageItems.length-1; gi >0; gi--) {
                    // will become the symbol name
                    var pageItemName = groupName + "_" + grpPageItems[gi].name;
                    createSymbol(grpPageItems[gi], pageItemName);
                    // add symbols to group
                    mySymbolInstance.moveToBeginning(grp);
                    // remove original content
                    grpPageItems[gi].remove();
    function createSymbol(element, elementName) {
        //alert("elementName" + elementName);
        // create symbols from all items in the group
        var symbolRef = docRef.symbols.add(element);
        //alert("element unnamed before: " + elementName);
        // if the element name is empty, give it a name
        var addElementIndex = 0;
        if(elementName == "") {
            elementName = "unnamed" + addElementIndex;
            addElementIndex++;
        // loop through all the symbols in the document
        var symbolCount = docRef.symbols.length;
            for(var s=0; s<symbolCount; s++)  {
                // existing symbols
                var symbolCheck = docRef.symbols[s];
                //alert(symbolCheck.name);
                var addIndex = 0;
                // if the name already exists, add the index number to it and increment
                if(elementName == symbolCheck.name) {
                    elementName = elementName + addIndex;
                    addIndex++;
        symbolRef.name = elementName;
        //alert("symbol name: " + symbolRef.name);
        mySymbolInstance = docRef.symbolItems.add(symbolRef);
        mySymbolInstance.left = element.left;
        mySymbolInstance.top = element.top;
    function clearEmptyLayers() {
        if (documents.length > 0 && activeDocument.pathItems.length >= 0){
            for (var ni = layersCount - 1; ni >= 0; ni-- ) {
                // get sub layers
                var topLayer = docRef.layers[ni];
                for(var ii = topLayer.layers.length - 1; ii >=0; ii--) {
                    // delete empty sub layers
                    if ( topLayer.layers[ni].pageItems.length == 0 ) {
                        topLayer.layers[ni].remove();

  • Get the ID of a dynamically created symbol from library, INSIDE another symbol.

    Hi everyone,
    I'm trying to get the id from a dynamic created symbol from library.
    When dynamically creating the symbol directly on the stage (or composition level), there's no problem.
    But I just can't get it to work when creating the symbol inside another symbol. 
    Below some examples using both "getChildSymbols()" and "aSymbolInstances" 
    // USING "getChildSymbols()" ///////////////////////////////////////////////////////////////////////// 
    // ON THE STAGE 
    var m_item = sym.createChildSymbol("m_item","Stage");
    var symbolChildren = sym.getChildSymbols(); 
    console.log(symbolChildren[0].getSymbolElement().attr('id')); // ok eid_1391853893203
    // INSIDE ANOTHER SYMBOL
    var m_item = sym.createChildSymbol("m_item", sym.getSymbol("holder").getSymbolElement()); 
    var symbolChildren = sym.getSymbol("holder").getChildSymbols(); // Am i using this wrong maybe?
    console.log(symbolChildren.length) // returns 0 so can't get no ID either
    // USING "aSymbolInstances"" ////////////////////////////////////////////////////////////////////////// 
    // ON THE STAGE
    var m_item = sym.createChildSymbol("m_item","Stage"); 
    console.log(sym.aSymbolInstances[0]); // ok (i guess) x.fn.x.init[1] 0: div#eid_1391854141436
    // INSIDE ANOTHER SYMBOL
    var m_item = sym.createChildSymbol("m_item", sym.getSymbol("holder").getSymbolElement());
    console.log(sym.getSymbol("holder").aSymbolInstances[0]); // Javascript error in event handler! Event Type = element 
    In this post http://forums.adobe.com/message/5691824 is written: "mySym.aSymbolInstances will give you an array with all "names" when you create symbols"
    Could it be this only works on the stage/ composition level only and not inside a symbol? 
    The following methods to achieve the same are indeed possible, but i simply DON'T want to use them in this case:
    1) Storing a reference of the created symbol in an array and call it later by index.
    2) Giving the items an ID manually on creation and use document.getElementById() afterwards.
    I can't believe this isn't possible. I am probably missing something here.
    Forgive me I am a newbie using Adobe Edge!
    I really hope someone can help me out here.
    Anyway, thnx in advance people!
    Kind Regards,
    Lester.

    Hi,
    Thanks for the quick response!
    True this is also a possibility. But this method is almost the same of "Giving the items an ID manually on creation and use document.getElementById() afterwards".
    In this way (correct me if i'm wrong) you have to give it an unique ID yourself. In a (very) big project this isn't the most practical way.
    Although I know it is possible.
    Now when Edge creates a symbol dynamically on the Stage (or composition level) or inside another symbol it always gives the symbol an ID like "eid_1391853893203".
    I want to reuse this (unique) ID given by Edge after creation.
    If created on the stage directly you can get this ID very easy. Like this;
    var m_item = sym.createChildSymbol("m_item","Stage");
    var symbolChildren = sym.getChildSymbols(); 
    console.log(symbolChildren[0].getSymbolElement().attr('id')); // ok eid_1391853893203
    I want to do exactly the same when created INSIDE another symbol.
    var m_item = sym.createChildSymbol("m_item", sym.getSymbol("holder").getSymbolElement());
    Now how can I accomplish this? How can I get the Id of a dynamically created symbol INSIDE another symbol instead of created directly on the stage?
    This is what i'm after.
    Thnx in advance!

  • Create symbol from "scratch"

    Hello all!
    I've been busy and haven't checked in here for awhile - I guess for me that's good :-)
    I've got a question that I know I'm not the only one and was wondering what others do...
    I have a stage with everything on it I want, including 6 buttons.  Now I want to create "symbols" that each button will call.  Is there a "correct" way to do this?
    I know I could add a small rectangle off stage, create a symbol from it and then remove it from the stage and create what I want.
    Is there a better way?
    Just curious :-)
    James

    Hey James,
    You can also create symbols and then export them and reuse them in other compositions.
    I usually create all my symbol elements, right-click on all the divs and then convert to symbol. then, if it is something I think I could reuse somewhere else, I export it.
    But different people have different ways of doing things.

  • Create symbol from layer PageItems

    I'm having trouble figuring out how to create a single symbol from all the objects within a single layer.
    Despite what the reference docs say, it doesn't seem that PageItems is a valid argument to pass into Symbols.add()...
    Anyone have any insight or maybe some example code?
    Thanks in advance!

    Hmm..  Creating a group seems to be troublesome as well...
    The following code gives me
    undefined is not an object
    on line
    var group = doc.groups.add(itemArray);
    var doc =app.activeDocument;
    var layer = doc.activeLayer;
    layer.hasSelectedArtwork = true;
    var itemArray = new Array;
    for (var i in selection)
        itemArray.push(i);
    var group = doc.groups.add(itemArray);
    Symbols.Add(group);
    My goal is simply to take all the objects on a given layer and create a symbol from them...  Sounded simple when I set out to figure it out.   Turning out not to be so simple...

  • Creating video from images

    I am trying to make video from images
    here is my program
    import java.awt.Dimension;
    import java.awt.Image;
    import javax.media.*;
    import javax.media.control.*;
    import javax.media.protocol.*;
    import javax.media.protocol.DataSource;
    import javax.media.datasink.*;
    import javax.media.format.VideoFormat;
    import javax.media.util.ImageToBuffer;
    import java.io.*;
    import java.util.*;
    *For AVI files, each frame must have a time stamp set. See the following message from the jmf-interest archives for details:
    http://archives.java.sun.com/cgi-bin/wa?A2=ind0107&L=jmf-interest&P=R34660
    public class AviCreator implements ControllerListener, DataSinkListener
    private boolean doIt(
    int width,
    int height,
    int frameRate,
    MediaLocator outML)
         File folder=new File("c:/images1");     
              File [] files=folder.listFiles();
    ImageDataSource ids = new ImageDataSource(width, height, frameRate,files);
    Processor p;
    try
    System.err.println(
    "- create processor for the image datasource ...");
    p = Manager.createProcessor(ids);
    catch (Exception e)
    System.err.println(
    "Yikes! Cannot create a processor from the data source.");
    return false;
    p.addControllerListener(this);
    // Put the Processor into configured state so we can set
    // some processing options on the processor.
    p.configure();
    if (!waitForState(p, Processor.Configured))
    System.err.println("Failed to configure the processor.");
    return false;
    // Set the output content descriptor to QuickTime.
    p.setContentDescriptor(
    new ContentDescriptor(FileTypeDescriptor.MSVIDEO));
    // Query for the processor for supported formats.
    // Then set it on the processor.
    TrackControl tcs[] = p.getTrackControls();
    Format f[] = tcs[0].getSupportedFormats();
    if (f == null || f.length <= 0)
    System.err.println(
    "The mux does not support the input format: "
    + tcs[0].getFormat());
    return false;
    tcs[0].setFormat(f[0]);
    System.err.println("Setting the track format to: " + f[0]);
    // We are done with programming the processor. Let's just
    // realize it.
    p.realize();
    if (!waitForState(p, Processor.Realized))
    System.err.println("Failed to realize the processor.");
    return false;
    // Now, we'll need to create a DataSink.
    DataSink dsink;
    if ((dsink = createDataSink(p, outML)) == null)
    System.err.println(
    "Failed to create a DataSink for the given output MediaLocator: "
    + outML);
    return false;
    dsink.addDataSinkListener(this);
    fileDone = false;
    System.err.println("start processing...");
    // OK, we can now start the actual transcoding.
    try
    p.start();
    dsink.start();
    catch (IOException e)
    System.err.println("IO error during processing");
    return false;
    // Wait for EndOfStream event.
    waitForFileDone();
    // Cleanup.
    try
    dsink.close();
    catch (Exception e)
    p.removeControllerListener(this);
    System.err.println("...done processing.");
    return true;
    * Create the DataSink.
    private DataSink createDataSink(Processor p, MediaLocator outML)
    DataSource ds;
    if ((ds = p.getDataOutput()) == null)
    System.err.println(
    "Something is really wrong: the processor does not have an output DataSource");
    return null;
    DataSink dsink;
    try
    System.err.println("- create DataSink for: " + outML);
    dsink = Manager.createDataSink(ds, outML);
    dsink.open();
    catch (Exception e)
    System.err.println("Cannot create the DataSink: " + e);
    return null;
    return dsink;
    private Object waitSync = new Object();
    private boolean stateTransitionOK = true;
    * Block until the processor has transitioned to the given state.
    * Return false if the transition failed.
    private boolean waitForState(Processor p, int state)
    synchronized (waitSync)
    try
    while (p.getState() < state && stateTransitionOK)
    waitSync.wait();
    catch (Exception e)
    return stateTransitionOK;
    * Controller Listener.
    public void controllerUpdate(ControllerEvent evt)
    if (evt instanceof ConfigureCompleteEvent
    || evt instanceof RealizeCompleteEvent
    || evt instanceof PrefetchCompleteEvent)
    synchronized (waitSync)
    stateTransitionOK = true;
    waitSync.notifyAll();
    else if (evt instanceof ResourceUnavailableEvent)
    synchronized (waitSync)
    stateTransitionOK = false;
    waitSync.notifyAll();
    else if (evt instanceof EndOfMediaEvent)
    evt.getSourceController().stop();
    evt.getSourceController().close();
    private Object waitFileSync = new Object();
    private boolean fileDone = false;
    private boolean fileSuccess = true;
    * Block until file writing is done.
    private boolean waitForFileDone()
    synchronized (waitFileSync)
    try
    while (!fileDone)
    waitFileSync.wait();
    catch (Exception e)
    return fileSuccess;
    * Event handler for the file writer.
    public void dataSinkUpdate(DataSinkEvent evt)
    if (evt instanceof EndOfStreamEvent)
    synchronized (waitFileSync)
    fileDone = true;
    waitFileSync.notifyAll();
    else if (evt instanceof DataSinkErrorEvent)
    synchronized (waitFileSync)
    fileDone = true;
    fileSuccess = false;
    waitFileSync.notifyAll();
    public static String[] createParam()
         File folder=new File("c:/images1");     
         String [] files=folder.list();
         String param[]=new String[files.length+8];          
    param[0]="-w";
    param[1]="400";
    param[2]="-h";
    param[3]="300";
    param[4]="-f";
    param[5]="1";
    param[6]="-o";
    param[7]="file:/c:/images/abc.avi";          
         for(int i=8;i<files.length+8;i++)     
              param="file:/c:/images1/"+files[i-8];
    return param;     
    public static void main(String args1[]) throws Exception
    //jpegCreator.main(null);
    //if (args.length == 0)
    // prUsage();
              //String [] args ={"-w","320" ,"-h","240", "-f","1", "-o", "file:/c:/images/abc.mov","file:/c:/images/surya_jo1.jpg", "file:/c:/temp/flower1_jpg.jpg" };
              String [] args=createParam();
    // Parse the arguments.
    int i = 0;
    int width = -1, height = -1, frameRate = 1;
    Vector inputFiles = new Vector();
    inputFiles.add("file:/c:/images/surya_jo1.jpg");
    inputFiles.add("file:/c:/images/flower1_jpg.jpg");
    String outputURL = null;
    width = 128;
    height = 128;
    outputURL = "file:/c:/images/abc.avi";
    // Generate the output media locators.
    MediaLocator oml;
    if ((oml = createMediaLocator(outputURL)) == null)
    System.err.println("Cannot build media locator from: " + outputURL);
    System.exit(0);
    AviCreator imageToMovie = new AviCreator();
    imageToMovie.doIt(width, height, frameRate, oml);
    System.exit(0);
    static void prUsage()
    System.err.println(
    "Usage: java JpegImagesToMovie -w <width> -h <height> -f <frame rate> -o <output URL> <input JPEG file 1> <input JPEG file 2> ...");
    System.exit(-1);
    * Create a media locator from the given string.
    private static MediaLocator createMediaLocator(String url)
    MediaLocator ml;
    if (url.indexOf(":") > 0 && (ml = new MediaLocator(url)) != null)
    return ml;
    if (url.startsWith(File.separator))
    if ((ml = new MediaLocator("file:" + url)) != null)
    return ml;
    else
    String file =
    "file:" + System.getProperty("user.dir") + File.separator + url;
    if ((ml = new MediaLocator(file)) != null)
    return ml;
    return null;
    // Inner classes.
    * A DataSource to read from a list of JPEG image files and
    * turn that into a stream of JMF buffers.
    * The DataSource is not seekable or positionable.
    /************************************************* private class ImageDataSource extends PullBufferDataSource
    private ImageSourceStream streams[];
    ImageDataSource(int width, int height, int frameRate)
    streams = new ImageSourceStream[1];
    streams[0] = new ImageSourceStream(width, height, frameRate);
    public void setLocator(MediaLocator source)
    public MediaLocator getLocator()
    return null;
    public String getContentType()
    return ContentDescriptor.RAW;
    public void connect()
    public void disconnect()
    public void start()
    public void stop()
    public PullBufferStream[] getStreams()
    return streams;
    public Time getDuration()
    System.out.println("dur is " + streams[0].nextImage);
    //return new Time(1000000000);
    return DURATION_UNKNOWN;
    public Object[] getControls()
    return new Object[0];
    public Object getControl(String type)
    return null;
    * A DataSource to read from a list of JPEG image files or
    * java.awt.Images, and
    * turn that into a stream of JMF buffers.
    * The DataSource is not seekable or positionable.
    private static class ImageDataSource extends PullBufferDataSource {
    private final Time durTime;
    private final PullBufferStream[] streams = new JpegSourceStream[1];
    * Constructor for creating movies out of jpegs
    ImageDataSource(int width, int height, int frameRate, File[] jpegFiles) {
    streams[0] = new JpegSourceStream(width, height, frameRate, jpegFiles);
    this.durTime = new Time(jpegFiles.length / frameRate);
    * Constructor for creating movies out of Images
    * NOTE - this is all done IN MEMORY, so you'd better have enough
    /*ImageDataSource(int width, int height, int frameRate, Image[] images) {
    streams[0] = new AWTImageSourceStream(width, height, frameRate, images);
    this.durTime = new Time(images.length / frameRate);
    public void setLocator(MediaLocator source) {
    public MediaLocator getLocator() {
    return null;
    * Content type is of RAW since we are sending buffers of video
    * frames without a container format.
    public String getContentType() {
    return ContentDescriptor.RAW;
    public void connect() {
    public void disconnect() {
    public void start() {
    public void stop() {
    * Return the ImageSourceStreams.
    public PullBufferStream[] getStreams() {
    return streams;
    public Time getDuration() {
    return durTime;
    public Object[] getControls() {
    return new Object[0];
    public Object getControl(String type) {
    return null;
    * The jpeg-based source stream to go along with ImageDataSource.
    private static class JpegSourceStream implements PullBufferStream {
    private final File[] jpegFiles;
    private final int width, height;
    private final VideoFormat videoFormat;
    private int nextImage = 0; // index of the next image to be read.
    private boolean ended = false;
    // Bug fix from Forums - next one line
    long seqNo = 0;
    public JpegSourceStream(int width, int height, int frameRate, File[] jpegFiles) {
    this.width = width;
    this.height = height;
    this.jpegFiles = jpegFiles;
    this.videoFormat = new VideoFormat(VideoFormat.JPEG,
    new Dimension(width, height),
    Format.NOT_SPECIFIED,
    Format.byteArray,
    (float)frameRate);
    * We should never need to block assuming data are read from files.
    public boolean willReadBlock() {
    return false;
    * This is called from the Processor to read a frame worth
    * of video data.
    public void read(final Buffer buf) {
    try {
    // Check if we've finished all the frames.
    if (nextImage >= jpegFiles.length) {
    // We are done. Set EndOfMedia.
    System.out.println("Done reading all images.");
    buf.setEOM(true);
    buf.setOffset(0);
    buf.setLength(0);
    ended = true;
    return;
    File imageFile = jpegFiles[nextImage];
    nextImage++;
    System.out.println(" - reading image file: " + imageFile);
    // Open a random access file for the next image.
    RandomAccessFile raFile = new RandomAccessFile(imageFile, "r");
    byte[] data = (byte[])buf.getData();
    // Check to see the given buffer is big enough for the frame.
    if (data == null || data.length < raFile.length()) {
    // allocate larger buffer
    data = new byte[(int)raFile.length()];
    buf.setData(data);
    // Read the entire JPEG image from the file.
    raFile.readFully(data, 0, (int)raFile.length());
    System.out.println(" read " + raFile.length() + " bytes.");
    // Bug fix for AVI files from Forums ( next 3 lines).
    long time = (long) (seqNo * (1000 / videoFormat.getFrameRate()) * 1000000);
    buf.setTimeStamp(time);
    buf.setSequenceNumber(seqNo++);
    buf.setOffset(0);
    buf.setLength((int)raFile.length());
    buf.setFormat(videoFormat);
    buf.setFlags(buf.getFlags() | buf.FLAG_KEY_FRAME);
    // Close the random access file.
    raFile.close();
    } catch (Exception e) {
    // it's important to print the stack trace here because the
    // sun class that calls this method silently ignores
    // any IOExceptions that get thrown
    e.printStackTrace();
    throw new RuntimeException(e);
    * Return the format of each video frame. That will be JPEG.
    public Format getFormat() {
    return videoFormat;
    public ContentDescriptor getContentDescriptor() {
    return new ContentDescriptor(ContentDescriptor.RAW);
    public long getContentLength() {
    return LENGTH_UNKNOWN;
    public boolean endOfStream() {
    return ended;
    public Object[] getControls() {
    return new Object[0];
    public Object getControl(String type) {
    return null;
    * The source stream to go along with ImageDataSource.
    /*************************************************************** class ImageSourceStream implements PullBufferStream
    final int width, height;
    final VideoFormat format;
    // Bug fix from Forums - next two lines
    float frameRate;
    long seqNo = 0;
    int nextImage = 0; // index of the next image to be read.
    boolean ended = false;
    public ImageSourceStream(int width, int height, int frameRate)
    this.width = width;
    this.height = height;
    // Bug fix from Forums (next line)
    this.frameRate = (float) frameRate;
    final int rMask = 0x00ff0000;
    final int gMask = 0x0000FF00;
    final int bMask = 0x000000ff;
    format =
    new javax.media.format.RGBFormat(
    new Dimension(width, height),
    Format.NOT_SPECIFIED,
    Format.intArray,
    frameRate,
    32,
    rMask,
    gMask,
    bMask);
    public boolean willReadBlock()
    return false;
    public void read(Buffer buf) throws IOException
    // Check if we've finished all the frames.
    if (nextImage >= 100)
    // We are done. Set EndOfMedia.
    System.err.println("Done reading all images.");
    buf.setEOM(true);
    buf.setOffset(0);
    buf.setLength(0);
    ended = true;
    return;
    nextImage++;
    int data[] = null;
    // Check the input buffer type & size.
    if (buf.getData() instanceof int[])
    data = (int[]) buf.getData();
    // Check to see the given buffer is big enough for the frame.
    if (data == null || data.length < width * height)
    data = new int[width * height];
    buf.setData(data);
    // Bug fix from Forums ( next 3 lines).
    long time = (long) (seqNo * (1000 / frameRate) * 1000000);
    buf.setTimeStamp(time);
    buf.setSequenceNumber(seqNo++);
    java.awt.Color clr = java.awt.Color.red;
    if (nextImage > 30)
    clr = java.awt.Color.GREEN;
    if (nextImage > 60)
    clr = java.awt.Color.BLUE;
    for (int i = 0; i < width * height; i++)
    // TODO - figure what the guy was trying to do here.
    data[i] = clr.getRGB();
    buf.setOffset(0);
    buf.setLength(width * height);
    buf.setFormat(format);
    buf.setFlags(buf.getFlags() | Buffer.FLAG_KEY_FRAME);
    public Format getFormat()
    return format;
    public ContentDescriptor getContentDescriptor()
    return new ContentDescriptor(ContentDescriptor.RAW);
    public long getContentLength()
    return 0;
    public boolean endOfStream()
    return ended;
    public Object[] getControls()
    return new Object[0];
    public Object getControl(String type)
    return null;
    * The java.awt.Image-based source stream to go along with ImageDataSource.
    * Not sure yet if this class works.
    private static class AWTImageSourceStream implements PullBufferStream {
    private final Image[] images;
    private final int width, height;
    private final VideoFormat videoFormat;
    private int nextImage = 0; // index of the next image to be read.
    private boolean ended = false;
    // Bug fix from Forums - next one line
    private long seqNo = 0;
    public AWTImageSourceStream(int width, int height, int frameRate, Image[] images) {
    this.width = width;
    this.height = height;
    this.images = images;
    // not sure if this is correct, especially the VideoFormat value
    this.videoFormat = new VideoFormat(VideoFormat.RGB,
    new Dimension(width, height),
    Format.NOT_SPECIFIED,
    Format.byteArray,
    (float)frameRate);
    * We should never need to block assuming data are read from files.
    public boolean willReadBlock() {
    return false;
    * This is called from the Processor to read a frame worth
    * of video data.
    public void read(final Buffer buf) throws IOException {
    try {
    // Check if we've finished all the frames.
    if (nextImage >= images.length) {
    // We are done. Set EndOfMedia.
    System.out.println("Done reading all images.");
    buf.setEOM(true);
    buf.setOffset(0);
    buf.setLength(0);
    ended = true;
    return;
    Image image = images[nextImage];
    nextImage++;
    // Open a random access file for the next image.
    //RandomAccessFile raFile = new RandomAccessFile(imageFile, "r");
    Buffer myBuffer = ImageToBuffer.createBuffer(image, videoFormat.getFrameRate());
    buf.copy(myBuffer);
    // Bug fix for AVI files from Forums ( next 3 lines).
    long time = (long) (seqNo * (1000 / videoFormat.getFrameRate()) * 1000000);
    buf.setTimeStamp(time);
    buf.setSequenceNumber(seqNo++);
    //buf.setOffset(0);
    //buf.setLength((int)raFile.length());
    //buf.setFormat(videoFormat);
    //buf.setFlags(buf.getFlags() | buf.FLAG_KEY_FRAME);
    } catch (Exception e) {
    // it's important to print the stack trace here because the
    // sun class that calls this method silently ignores
    // any Exceptions that get thrown
    e.printStackTrace();
    throw new RuntimeException(e);
    * Return the format of each video frame.
    public Format getFormat() {
    return videoFormat;
    public ContentDescriptor getContentDescriptor() {
    return new ContentDescriptor(ContentDescriptor.RAW);
    public long getContentLength() {
    return LENGTH_UNKNOWN;
    public boolean endOfStream() {
    return ended;
    public Object[] getControls() {
    return new Object[0];
    public Object getControl(String type) {
    return null;
    bit i am getting following exception at run time
    1
    2
    3
    4
    5
    6
    - create processor for the image datasource ...
    Setting the track format to: JPEG
    - create DataSink for: file:/c:/images/abc.mov
    start processing...
    - reading image file: file:/c:/images/surya_jo1.jpg
    - reading image file: file:/c:/images/flower1_jpg.jpg
    Done reading all images.
    Exception in thread "JMF thread: SendEventQueue: com.sun.media.processor.unknown.Handler" java.lang.NullPointerException
    at com.sun.media.multiplexer.video.QuicktimeMux.writeVideoSampleDescription(QuicktimeMux.java:936)
    at com.sun.media.multiplexer.video.QuicktimeMux.writeSTSD(QuicktimeMux.java:925)
    at com.sun.media.multiplexer.video.QuicktimeMux.writeSTBL(QuicktimeMux.java:905)
    at com.sun.media.multiplexer.video.QuicktimeMux.writeMINF(QuicktimeMux.java:806)
    at com.sun.media.multiplexer.video.QuicktimeMux.writeMDIA(QuicktimeMux.java:727)
    at com.sun.media.multiplexer.video.QuicktimeMux.writeTRAK(QuicktimeMux.java:644)
    at com.sun.media.multiplexer.video.QuicktimeMux.writeMOOV(QuicktimeMux.java:582)
    at com.sun.media.multiplexer.video.QuicktimeMux.writeFooter(QuicktimeMux.java:519)
    at com.sun.media.multiplexer.BasicMux.close(BasicMux.java:142)
    at com.sun.media.BasicMuxModule.doClose(BasicMuxModule.java:172)
    at com.sun.media.PlaybackEngine.doClose(PlaybackEngine.java:872)
    at com.sun.media.BasicController.close(BasicController.java:261)
    at com.sun.media.BasicPlayer.doClose(BasicPlayer.java:229)
    at com.sun.media.BasicController.close(BasicController.java:261)
    at JpegImagesToMovie.controllerUpdate(JpegImagesToMovie.java:196)
    at com.sun.media.BasicController.dispatchEvent(BasicController.java:1254)
    at com.sun.media.SendEventQueue.processEvent(BasicController.java:1286)
    at com.sun.media.util.ThreadedEventQueue.dispatchEvents(ThreadedEventQueue.java:65)
    at com.sun.media.util.ThreadedEventQueue.run(ThreadedEventQueue.java:92)
    plz help me
    thanks in advance

    Step 1) Copy that code into a .java file
    Step 2) Compile it
    Step 3) Run it
    Step 4) Look at the output
    Step 5 (optional)) If it didn't work, post a specific question about the code, and use [co[b]de] tags.

  • Script to create tables from  an existing database

    I need a script to create tables without storage parameters from existing database

    Please repost your question in the database forum, General Database Discussions

  • Create thumnail from image

    Can we create thumbnail from a image in Oracle 11g database?

    The image is stored as blob secure file in oracle 11g database.
    What is the difference between blob and ORDImage?
    Can I create thumbnail from a image and store it in the database?

  • Javascript to create vector from image and save as eps

    Hi,
    I started writing a script which open all images in a folder and i need to turn those into vectors.
    How do i write the following in JavaScript:
    Open the JPG file
    Select the image layer/object
    Create a vector from the image using the Image Trace for high fidelity 
    Reduce the new vector objec size by %50.
    save as eps
    any help with any of the stages would be very helpful.
    thank you

    PERFECT!!!!!!
    This is exactly what I was going to build.  No need to create when it is already done.
    Thank you very much.
    -Mike

  • Unusual Bug when creating pdf from image files

    Hi I have a very mindboggling problem which I cant seem to get my head around.
    basically I am trying to create a pdf using a large amount of image files, these images are scans of pages of a book. so I have been trying to create a pdf file from these images, and everytime i try, it all looks ok except for one page which comes up smaller in size than the rest which is a big problem and very unusual. If I change the view of acrobat so that it shows two pages at a time then this is clearly visable where one page is normal and the page next to it is like a third of the size. Ive checked the image file properties for that page and they are more or less the same as the rest, the dimensions of the image file too, but when I add it into a PDF it seems to shrink in size, any ideas as to why? any help would be much appreciated! (and I hope what I said made sense lol )
    Thanks
    Nav

    Hi Davew000
    Can you please tell the steps you are doing to create the PDF ?
    Thanks,
    Tanvi

  • Any applications to batch create qts from image sequences.

    I've got about 15 tiff image sequences that I've got to creates qts of. QTPro does a great job, but it would be great if I could just drag all the folders to an application that would do all the grunt work for me (hey I know, I'm a lazy so and so and this kind of task happens every month or so).

    I am sure this is something an Apple Script could do.
    I had someone create something for me recently to do a similar thing. Afraid I cant help, you would need to ask arounda to see if someone can compile one for you
    theres also an Apple Script discussion here:
    http://discussions.apple.com/forum.jspa?forumID=724
    Gary

  • Script to Create Database from an Existing One

    I believe there is way to generate a script for re-creating a database from an existing database. But I forgot how. Anyone can Help. Thanks.

    Hi,
    Run the dbca.bat which in the oracle installer,
    In the last option you will get two options
    1)to create database
    2)create the script
    Here generate the script and run it in sql,
    Before that create the oracleservice and connect to the instance
    and run the script.
    Regards,
    Nirmal

  • Unable to create cd from Image file

    I downloaded the Solaris 8 for Intel, unzipped the files. I have been unsuccessful creating an image file for the file sol-8-1_01-fcs-bin-ia-v1. I have tried various CD writing applications.
    I was able to create images from the other files.
    Thanks

    You are not supposed to create an image file from the unzipped data. These unzipped files are image
    files! You just have to rename them using the proper file extension so that your CD-R burning software
    recognizes them as cd image files. (common extension are .ISO or .RAW; check with your CD recording
    software)

  • Creating Outline From Image

    Hello,
    I would like to know if it is possible to create an outline out of the image, instead of manually tracing with a pen, is it possible in Illustrator using some plugins to create the outline?
    The image I'd like to do so with is this one:
    http://25.media.tumblr.com/tumblr_mc1b233iBE1qerx9uo1_500.jpg
    Basically would like the camo pieces to be outline one by one separately.
    Thank you.

    Sorry for the brevity.
    Make your tracing panel to these settings:
    Then click on the Expand button.
    Then Ungroup.
    Then, draw a marquee or select on the edge where the next screen shot shows.
    What will be selected is the outline of what would have been the White fill...then delete it.
    Your pieces are all individual. You can select by color and group each color individually if desired. If you don't know how to do this, please look in the help. But in brief, select one colored item, Select menu, Same, Fill Color. This will make changing the color of all like-colored items easy.
    Mike

  • Creating BufferedImage from Image

    I've figured out one way to create a BufferedImage from an Image, but I'm sure it's not the best way.Image im = Toolkit.getDefaultToolkit().getImage(files.getAbsolutePath());
    JLabel jl = new JLabel(new ImageIcon(im));
    BufferedImage bim = new BufferedImage(im.getWidth(null), im.getHeight(null), BufferedImage.TYPE_BYTE_INDEXED);
    Graphics g = bim.getGraphics();
    jl.paint(bim.getGraphics());
    This works, but I'm sure there has to be a better/easier way. Any suggestions?
    Thanks,
    m

    close, the best way is this...
    public BufferedImage createBufferedImage(Image img)
    BufferedImage bimg = new BufferedImage(img.getWidth(null),img.getHeight(null),BufferedImage.TYPE_INT_RGB);//or whatever type is appropriate
    bimg.getGraphics().drawImage(img,0,0,null);
    return bimg;
    }

Maybe you are looking for

  • BOXI 3.1 installation problem on solaris

    Installed BOXIr3.1 on solaris using the oracle 11g as CMS database and oralce net client 10.2 as client database then we got the error after installation and the CMS is not starting. -- Sqlplus is working fine -- Recreated the SIA however its not wor

  • Training & Event Management: Restrict Change to Business Event

    Hi, Does anyone know if there is a way to restrict change to Business Event (eg. changes to the Event Schedule) based on certain business criteria? My criteria cannot restrict by authorization. For eg. let say if something happens (based on business

  • SQL script runs under SQL Devoper, will not run under UNIX, SQLPlus

    I have a sql program I developed under the SQL Developer tool and it runs fine. I have ftp'd the sql to the Unix server and I am trying to run the same program under SQL Plus in unix. The program echo's back the line number that is the last line numb

  • Business Rules and Business Intelligence in Java CAPS 6

    Dear All, I have two doubts. 1. Is there any way to add a Business Rule component and write Business rules in Java CAPS 6? As you may know, this is possible through eInsight in JCAPS 5.1.2. Is this feature readily available in Java CAPS 6? If yes, ca

  • How to insert custom text inside a text object?.

    Hi, I'm trying to do something like this: Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scram