Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-09-2012, 05:13 AM   PM User | #1
mitchsamuels
New to the CF scene

 
Join Date: Jan 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
mitchsamuels is an unknown quantity at this point
Setting User-pasted image url as Canvas Background

Okay, so I have a canvas, and I want the user to be able to copy an image url and paste it into an input box, that will then set it as the canvas background image.

Does anyone know how I can do this?

I was thinking about using the OnChange method in the text input, but I cannot find any help with that online.


My current Canvas Background is (In <head><script>)

Code:
var imgObg = new Image();
imageObj.src = "images/bg.png";
And my text input is

Code:
<form name="input" action="" method="get">
<input type="text" id="textboxBG" onchange="??" />
<input type="submit" value="Submit" />
</form>
If you need more code, or would like to help me out more in depth, I would gladly paypal you a little money. I know this can't be too difficult! I REALLY want this done!
mitchsamuels is offline   Reply With Quote
Old 01-09-2012, 06:34 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,185
Thanks: 59
Thanked 3,995 Times in 3,964 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
You don't show where you *USE* the imgObj to establish the background for the canvas. We have to see that.

I should note that any changes to the background can only apply to the ONE USER who changes them. No other users will see the change. And even the change by the one user will only persist to another page or another session if you store the URL in a cookie.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 01-10-2012, 02:29 AM   PM User | #3
mitchsamuels
New to the CF scene

 
Join Date: Jan 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
mitchsamuels is an unknown quantity at this point
Oh wow I am dumb!

And yeah, I understand it will only be for the one user. I basically want the user to be able to draw on their image they choose.

I am just learning Canvas, so I thought I would make a little sample site. I think this would be good, but I cannot figure it out, and I cannot find any tutorials!

Here is my full (ish) code,

Basically, my textbox is "usrimg" and the image I want to change is "imageObj"

Code:
<html>
    <head>      
        <script>
 
            window.onload = function(){
                var canvas = document.getElementById("myCanvas");
                var context = canvas.getContext("2d");
                var topLeftCornerX = 5;
    				var topLeftCornerY = 5;
    				var width = 640;
   				 var height = 480;
   				 //Image
   				      var destX = 5;
  					  var destY = 5;
   				 var destWidth = 640;
   				 var destHeight = 480;
  					  var imageObj = new Image();

  					               imageObj.src = "images/cat1small.png";
  					  

  					     
    					
    					imageObj.onload = function(){
        context.drawImage(imageObj, destX, destY, destWidth, destHeight);
    };            

        </script>
    </head>
    <body background="images/bg.png" >

<!-- TABLE TABLE TABLE TABLE TABLE -->
	<table border="0">
		<tr>
			<td>
			
			<!-- Background URL FORM -->
<form name="input" action="" method="get">
<input id="usrimg"/>
<input type="submit" value="Submit" style="border: none;"/>
</form>
			<!--END FORM-->

			</td>

		<td><canvas id="myCanvas" width="655" height="490" align="right"></canvas>

		</td>
		</tr>
	</table>
	<BR>
<BR>

</body>
</html>
mitchsamuels is offline   Reply With Quote
Old 01-10-2012, 03:27 AM   PM User | #4
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,454
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
you can't render off-site images to a canvas. you can render off-site images to a div's background-image, and you can position that div behind the canvas.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Old 01-10-2012, 03:32 AM   PM User | #5
mitchsamuels
New to the CF scene

 
Join Date: Jan 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
mitchsamuels is an unknown quantity at this point
Quote:
Originally Posted by rnd me View Post
you can't render off-site images to a canvas. you can render off-site images to a div's background-image, and you can position that div behind the canvas.
Dang it!
I couldn't export the div with the canvas after they are done drawing though, correct?


What query would I search if I want to be able to have a user upload an image (from their computer) to the canvas background?

What is that called?

Do you know of any tutorials?
mitchsamuels is offline   Reply With Quote
Reply

Bookmarks

Tags
html, image, onchange

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:19 AM.


Advertisement
Log in to turn off these ads.