Open Naberdz opened 6 years ago
Just wanted to ask if there is an update on this? Did somebody find a workaround? (It still does not work for me)
Thanks.
I have solved it by using php code. so i don't use html to canvas anymore. don't know where i got this part of the code but here it is :
jQuery("#save").click(function(){
var raw = jQuery(".drawArea").html();
var encoded = raw.replace(/\s+/g, " ");
encoded = replaceAll(encoded, "%", "%25");
encoded = replaceAll(encoded, "> <", "><"); // normalise spaces elements
encoded = replaceAll(encoded, "; }", ";}"); // normalise spaces css
encoded = replaceAll(encoded, "<", "%3c");
encoded = replaceAll(encoded, ">", "%3e");
encoded = replaceAll(encoded, "\"", "'");
encoded = replaceAll(encoded, "#", "%23"); // needed for ie and firefox
encoded = replaceAll(encoded, "{", "%7b");
encoded = replaceAll(encoded, "}", "%7d");
encoded = replaceAll(encoded, "|", "%7c");
encoded = replaceAll(encoded, "^", "%5e");
encoded = replaceAll(encoded, "`", "%60");
encoded = replaceAll(encoded, "@", "%40");
// charset reported as not needed
var svg = 'data:image/svg+xml;charset=UTF-8,' + encoded;
var form_data = new FormData();
form_data.append('svg', raw);
jQuery.ajax({
url: 'toimage.php', // point to server-side PHP script
cache: false,
contentType: false,
processData: false,
data: form_data,
type: 'post',
success: function(data){
//what you do with file is up to you right now my php script returns image
}
});
});
function escapeRegExp(str) {
return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
}
function replaceAll(str, find, replace) {
return str.replace(new RegExp(escapeRegExp(find), 'g'), replace);
}
toimage.php :
$svg_data_as_string = $_POST['svg'];
header("Content-Type: image/png");
$image = new IMagick();
$image->setBackgroundColor(new ImagickPixel('transparent'));
$image->readImageBlob($svg_data_as_string);
$image->setImageFormat("png32");
Having issue with saving svg which have background image in them.
it can save ordinary svg with filled colors, but when i add background image to it then it becomes empty. any ideas how to solve this issue ?
svg looks like this:
Specifications: