fabSaveAsPNG issues - Forum

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

fabSaveAsPNG issues

Hi @luishp

I tried using the fabrics demo. There seems to be inconsistent issue with the fabSaveAsPNG function. On my iPad and iPhone, it opens a new window on browser and image is downloaded. But on Android phone and MAC Safari, the new tab is blank. Have anyone experienced similar symptom?

i also noticed there is a subroutine prueba2 which contains

window.open(window(“Canvas”+containerId].toDataURL(‘png’));

Is the subroutine needed?

what could have caused the inconsistency in the PNG saving?

I think the subroutine was my unsuccessful attempt to force the file download instead of opening the image in a new tab.
If you use this code, you will save the canvas content as a base64 encoded PNG into the variable [myvar]:

BeginJS
containername="Container1";
$App["myvar"]=window["Canvas"+containername].toDataURL('png');
EndJS

But I have not found a solution to save it as a valid .png file (just as a base64 encoded representation).
So I opened a tab to show the encoded data as an image the user can download with a right click.
I don't know why it's inconsistent.

Hi luishp

OK, will try out later. As Long as image is shown on new tab, it’s better than nothing. BTW, do I use the suggested script direct or simply execute fabSaveAsPNG command. I didn’t see the subroutine being called anywhere...

Thanks

BTW, do I use the suggested script direct or simply execute fabSaveAsPNG command. I didn’t see the subroutine being called anywhere...

Just use fabSaveAsPNG to show the png into a new tab.
Use the suggested script to save a base64 encoded representation of the png image (you can later save and load it as a file, but it's not a valid png file) The subroutine is never called because it was a test I forgot to delete.
Regards.

Hi luishp

Using the fabSaveAsPNG does not work for all... as mentioned earlier.  could below link provides some ideas? I tested them and it accepts local image upload and save to local too - https://stackoverflow.com/questions/33806624/save-fabricjs-canvas-as-image-on-the-pc

Hi @ronnie, after doing some tests this works for me (except in Internet Explorer):

BeginJS
containername="Container1";
var mycanvas = document.getElementById(containername+"Canvas");
mycanvas.toBlob(function(blob) {
    saveAs(blob, "myimage.png");
});
EndJS

Please confirm.
Thanks!

Hi luishp,

It works...   Here's my quick test and feedback. Need some fine-tuning perhaps as I noticed below observations:

  1. On Safari (Mac), the images is OK except canvas background was not in white as I've set (like it's transparent or default light grey background). Image quality is OK.
  2. On Chrome (Mac), similar to above point (1).
  3. On Chrome (Windows), canvas background was white as it should be.
  4. On iPad, it's OK... image loaded (very fast) in new tab as blob:http://...
  5. On iPhone, same experience as iPad (item 4)
  6. On Android phone, it downloaded the file. But canvas background is transparent.

Ronnie

Hi @ronnie,
Are you using fabSetBgColor command to set the background color?

Yes. I thought changing it to #ffffff would work.

Anyway, I insert a workaround to force bgcolour to white before saving to png, and it works fine...

fabUnselect "Container1"
fabSetBgColor "Container1" "#ffffff"

 

Hola,

Tenéis un ejemplo que se pueda abrir con el programa visualneo donde se pueda visualizar el código. No consigo que funcione la captura en imagen png.

 

Gracias

@rrey aquí tienes un ejemplo.
Recuerda que no funcionará en Internet Explorer.
Saludos.

Uploaded files:
  • You need to login to have access to uploads.

Muchas gracias.

Si quiero añadir una imagen al container he probado con:

setVar [imagen] "Image1.jpg"
fabInitialize "Container1"
fabNewCircle "Container1" "c1" 160 90 100 "red"

fabLoadLocal "Container1" [imagen]

No me funciona algo algo mal.

 

 

 

@rrey, me temo que fabLoadLocal no sirve para eso, sino para cargar una imagen previamente guardada con fabSaveLocal.
Por favor echa un vistazo a estos hilos:
https://visualneo.com/forum/topic/load-image-from-local-system-to-fabricjs-canvas
https://visualneo.com/forum/topic/load-image-and-auto-scale