Question

Asked on 2011-05-09 at 22:13:25ID: 27360748

javascript show images on canvas

by: debbieau1500

Rating8.8Very Good

I have multiple image coordinates saved in a database.  I want to pull out the values with a php script.  The following works, but I want to make it more efficient with php loop.  I am currently using two queries to make it work and I think there would be a better way than how I am doing it.  I still need to make sure the images have loaded first.  It would be good to get advice.

<script type="text/javascript">
      window.onload = function() {
            var c=document.getElementById("myCanvas");
var cxt=c.getContext("2d");
var IsImage1Loaded = false;
var IsImage2Loaded = false;

var img=new Image()
img.src="background.jpg";
var secimage=new Image()
secimage.src="../images/<?php echo $_GET['img'];?>.png";
img.onload = function() {
IsImage1Loaded = true;
if(IsImage2Loaded) finalCallback();
}

secimage.onload = function() {
IsImage2Loaded = true;
if(IsImage1Loaded) finalCallback();
}
function finalCallback(){
  document.getElementById('loader').style.display = 'none';
    cxt.drawImage(img,0,0);
      <?php $thenumb = 1;?>
<?php do { ?>
var secimageXcoord<?php echo $thenumb++;?> = <?php echo $row_rssignplace['coordx']; ?>-20;
var secimageYcoord<?php echo $thenumb++;?> = <?php echo $row_rssignplace['coordy']; ?>-40;      
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
<?php $thenumb = 1;?>
<?php do { ?>
                        cxt.drawImage(secimage,secimageXcoord<?php echo $thenumb++; ?>,secimageYcoord<?php echo $thenumb++; ?>);
  <?php } while ($row_Recordset2 = mysql_fetch_assoc($Recordset2)); ?>       
};
      }
            </script>

Related Solutions

Solution

Sign up now to view this solution! It's quick, easy, and secure to subscribe. We will return you to this solution, unlocked, when you’re done.

About this Solution

View This Solution - Start Your 30 Day Free Trial
Zone
general
Tags
javascipt canvas PHP
Participating Experts
1
Solution Grade
A

Replies

 by: Roads_Roads

Posted on 2011-05-09 at 22:51:16ID: 36812548

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by: debbieau1

Posted on 2011-05-09 at 22:54:08ID: 36812549

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by: Roads_Roads

Posted on 2011-05-09 at 22:57:13ID: 36812550

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by: debbieau1

Posted on 2011-05-09 at 23:10:51ID: 36812551

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by: Roads_Roads

Posted on 2011-05-09 at 23:26:41ID: 36812552

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by: debbieau1

Posted on 2011-05-09 at 23:51:14ID: 36812553

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 by: debbieau1

Posted on 2011-05-09 at 23:51:16ID: 36812554

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

Log In

Forgot your password?Sign up

Top Experts

  1. mplungjan

    1,840

    0 points yesterday

    Profile

BrowseAre you an Expert?