We are about to switch to a new forum software. Until then we have removed the registration on this forum.
More more question on images...
I have implemented the drop p5 example http://p5js.org/examples/examples/Dom_Drop.php
function setup() { // create canvas var c = createCanvas(710, 400); background(100); // Add an event for when a file is dropped onto the canvas c.drop(gotFile); } function draw() { fill(255); noStroke(); textSize(24); textAlign(CENTER); text('Drag an image file onto the canvas.', width/2, height/2); noLoop(); } function gotFile(file) { // If it's an image file if (file.type === 'image') { // Create an image DOM element but don't show it var img = createImg(file.data).hide(); // Draw the image onto the canvas image(img, 0, 0, width, height); } else { println('Not an image file!'); } }
and I am trying to merge this code with some p5 image processing code that makes use of the loadImage() function:
eg.
img = loadImage("..\test.jpg");
because using loadImage lets me use the get() function
eg,
img.get()
using the drop example and createImage instead of loadImage doesn't allow me to use get()
how can I do droping of files but use the loadImage function with the data the example above gives me
put another way
if I try to use img.get() using the drop example I get the following error:
"Uncaught TypeError: img.get is not a function"
cheers!
Answers
Quotes from: http://forum.Processing.org/two/discussion/11608/i-can-t-display-images-dynamically-loaded-from-web-with-p5-js-always-a-cross-domain-issue#latest
JS Canvas API prohibits any direct pixel access from tainted images! :-SS
Dunno whether it might work but take your chances w/ loadImage() within your drop() callback? :-??
Another thing: Don't mix up createImage() & createImg(): :-\"
Only the former returns a p5.Image object.
While the latter returns an HTMLImageElement.
tried playing with that a bit, do you know what other attributes 'file' has beyond type and .data ? maybe there is something like file.path that I can use instead?
If drop()'s parameter is indeed an HTMLImageElement, it's gotta have a scr property too.
https://developer.Mozilla.org/en-US/docs/Web/API/HTMLImageElement
Found this link about drop()'s Event:
https://developer.Mozilla.org/en-US/docs/Web/Events/drop
Maybe we should rely on its target property just like I did w/ the CORS hack for loadImage()? $-)
not sure I follow
btw file looks to also hold .name .type .subtype
but that doesn't help me much as I can just get the name not a url link
I barely knew about drop() before. As said the property to seek out is target.
And if that happens to be an HTMLImageElement, look for property scr.
will give it a try.. suggestions for otherways to allow simple file upload that works with loadImage?
Function loadImage() accepts a
string
for the URL path. So you rly need drop()'s URL: 8-Xhttp://p5js.org/reference/#/p5/loadImage
ya I guess I could ask a user to enter in a url manually, less than ideal
when I try this now I get:
Image from origin 'http://www.SOMEWEBSITE.com' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.SOMEWEBSITE.com' is therefore not allowed access.
Have you read my 1st reply where I passed the forum link w/ CORS fix for loadImage()? [-(
yes I am playing with it now sorry but getting issues of it not redrawing properly :( I am starting to really hate p5
The above fix gets the image on the screen but then breaks reading the pixel/color values (which is a major part of my program).
ok this is now really breaking my whole program, any other solutions at this point? I am pretty pissed I wrote an app that was supposed to be web based that I can't upload an image too.
All I can think now is creating an image upload site and let me store files on my server so i can access them locally, seems like a crazy approach
Maybe this site can interest you? http://CrossOrigin.me
thanks for all your help! I will keep on trying, next time I will just go straight javascript :p
Sweet merciful crap that link saved my life! thanks!