Save Image (download) - Forum

Forum Navigation
You need to log in to create posts and topics.

Save Image (download)

Hi..

I use Picture object and in source property i use a url of a image (Images/Example.jpg) The question is how i will save it locally (download) by pressing a button. Image is not loaded in any variable, is just external source.

Thanks

@smartmedia if the image is located in the same domain than your app (no CORS) just use something like this:

neoDownloadURL "./img/my-image.jpg"

Else you can try:

BeginJS
// get the image element by its ID
const image = document.getElementById("Image1");

// create a canvas element and draw the image onto it
const canvas = document.createElement("canvas");
canvas.width = image.width;
canvas.height = image.height;
const ctx = canvas.getContext("2d");
ctx.drawImage(image, 0, 0, canvas.width, canvas.height);

// convert the canvas to a data URL
$App.dataURL = canvas.toDataURL("image/jpeg");
EndJS
Wait 500
  neoDownloadData "[dataURL]" "my-image.jpg" "image/jpeg"
EndWait

Let me know if it works.

Regards.

smartmedia has reacted to this post.
smartmedia

Hi @luishp,

neoDownloadURL did the work smoothly. Thanks a lot..

@smartmedia

Image is not loaded in any variable, is just external source.

You can use the GetObjectAttribute command to obtain the "src" attribute of the Image object hosting your picture ... this worked for me ...

GetObjectAttribute "Image1" "src" "[myvar]"
..AlertBox "ImageURL" "[myvar]" ""
neoDownloadURL "[myvar]"

 

luishp and smartmedia have reacted to this post.
luishpsmartmedia