javascript - Upload image onto canvas -
I have a canvas on which I can currently add text layers and images to Flickr, which I try to do It makes it possible to upload an image to the canvas with HTML input.
I'm using it to upload images from Flickr:
$ ("search form.image-search"). Submit (function () {$ (".. Search"). Remove (); $ .getJSON ("http://api.flickr.com/services/feeds/photos_public.gne?tags=" + $ (" .search input [name = q] "). Val () +" and tagmode = any and format = Jason and JasonSolac =? ", Function (data) {$. Each (data.itm, function (i, item) {Var img = $ ("& lt; img / & gt;"). Attr ("src", item.media.m); img.attr ("title", item .title); $ ("& lt; Li & gt; & lt; / li & gt; "). Attachments (IMG) .appendTo (" search ul "); if (i == 8) return;});}); return false;}) ; $ (".img search"). Live ("click", function () {jCollage.addLayer ($ (this) .context) .setTitle ($ (this) .attr ("title"); update layer (jCollage GetLayers ()); $ (" # Layer_ "+ (jCollage.getLayers (. Length) - 1)) AddClass (" selected ");}); I had an image upload function to work on an old canvas, but now I have started working with another canvas which was better because I do not have it anymore Tax found My first method of uploading an image to a canvas was:
var imageLoader = document.getElementById ('Uploader'); ImageLoader.addEventListener ('change', handle image, wrong); Var canvas = document. GetElementById ('canvas1'); Var ctx = canvas.getContext ('2d'); Function Handle Image (E) {var Reader = New FileReader (); Reader.loads = function (event) {var imgNew = new image (); ImgNew.onload = function () {s.addShape (new size (60, 60, IMG New Wide / 2, IMG New Hight / 2, IMGENE)); } ImgNew.src = event.target.result; } Reader.readAsDataURL (e.target.files [0]); } I have tried a few things to implement it in my new canvas, but since I am not experiencing a lot with javascript, I can not get it done Could
Here is a work (old) version of my canvas that is more clear and tested for you:
If someone does this to me It can be very good to help!
The common general approach should work. However, your new library will be replaced by and lt; Img & gt; DOM element is expected to add a layer. The following is what you need to do:
$ ("# Uploader"). Change (function (e) {var reader = new FileReader (); var title = e.target.value.replace (/.*[\\/] | (. [^ \.] + $) / G, "" ); Reader.onload = event (event) {var $ img = $ ("& lt; img / & gt;"). Attr ("src", Event.arget.result); jCollage.addLayer ($ img.get (0)) setTitle; Updated layer (jCollage.getLayers ()); $ ("# layer_" + (jCollage.getLayers (. Length-1)) .addClass ("selected");} reader.readAsDataURL (E.target.files [0]);});
Comments
Post a Comment