Jump to content

Dynamically load image to canvas & add data to array/object


Recommended Posts

for(var i=0; i < result.rows.length; i++) {
            
            var item = result.rows.item(i);
            
            if ($('#test').attr('src') != item.photo) {
                
                $('#test').attr('src', item.photo);
                
                var canvas  = document.getElementById('canvas2');
                var context = canvas.getContext('2d');
                
                $('#test').load(function() {
                    
                    context.drawImage(this, 0, 0);
                    
                    item.uploadPhoto = canvas.toDataURL();

                    console.log("PHOTOS");
                    console.log(item);

                    _modifiedData[table].push(item.uploadPhoto);
         
                });
                
            }

I basically have image pathways coming from a DB and I want to get the canvas dataurl information for them. My idea is to retrieve the data push the image pathway to the image object load that into a canvas object get the data to an object.

 

Once the data is in an object I need to preform a AJAX call to push this data to a PHP server to save the image. 

 

The problem I am having is the image load is happening after the AJAX call, and I can't figure out how to delay it. 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.