Chart.js-to-image in Laravel - laravel

does someone use Chart.js-to-image in his laravel application?
i render a chart.js chart in my application and i will save it as a img in my public folder to use it later to render a pdf with dompdf. but im not able to implement the chartjs-to-image in my project. i have a error with
const fs = require('fs')
i also try it with base64 image but there is the problem that my chart is not the same bevor and after base64img ( peak bevore goes up to 30 after only to 20).

Related

uploading images with filepond in an express ejs project

I'm working on a project that uses express.js for backend and the ejs rendering template for frontend. I've uploaded some images using filepond and the images were converted to base64. However, while viewing the output on the browser, the images look as though they're broken (with a small square at the top-left corner).
I need help with getting this fixed. Here's the code for the function to save the images and convert to base64:
function saveCover(book, coverEncoded) {
if (coverEncoded == null) return;
const cover = coverEncoded;
if (cover != null && imageMimeTypes.includes(cover.type)) {
book.coverImage = new Buffer.from(cover.data, "base64");
book.coverImageType = cover.type;
}
}
The problem I believe will be coming from how you are retrieving the image. If the code you've shown above saves the image (i.e you are seeing some data in the database), then you should focus your attention on the code that retrieves the image to display on the webpage.

`filter.applyTo is not a function` error when try to change image src using setSrc() in fabric js

Currently, I am Working on image editor that allows me to crop an image and apply a filter.
I am using fabric js version 1.7.22.
I want to implement crop functionality.
so my cropping flow is like Below :
crop image using a plugin and ger base64 of the cropped image.
generate blobUrl from base64 which help to display image in fabric js canvas.
After Cropping the image, I Just replace old image src with new One.
It works fine when an image has no filter.
but when I try to set a filter in the image first then try to replace src using setSrc() function.
It throws an error like Below
filter.applyTo is not a function
I have created one fiddle for demonstrating to replace src after the apply filter.
https://jsfiddle.net/Mark_1998/98gLhcb4/1/
And I Can't upgrade my fabric js version. If any patch Available then
Please Help Me.
The problem lies in this piece of code:
canvas.getActiveObject().setSrc('http://fabricjs.com/assets/pug_small.jpg', function(){
canvas.renderAll();
}, canvas.getActiveObject().toObject());
You're passing canvas.getActiveObject().toObject() as an options object, which is assigned to your image in setSrc() -> setElement() -> _initConfig().
toObject() serializes your fabric.Image, and filters array no longer contains the actual fabric.Filter, but rather a serialized version of it. So, it does not have a prototype with applyTo() method on it, hence the error filter.applyTo is not a function when fabric tries to reapply filters to your image after setSrc().
Instead of passing the whole serialized object as options, you'll need to pick the properties you actually want to be passed. As I'm not sure about what your requirements are, I tried replacing the above code with the following and it worked for me:
var options = canvas.getActiveObject().toObject();
delete options.filters;
options.crossOrigin = true;
canvas.getActiveObject().setSrc('http://fabricjs.com/assets/pug_small.jpg', function(){
canvas.renderAll();
}, options);
Note the options.crossOrigin = true - you won't be able to apply filters without it.

Convert leaflet map snippet to image

I need to export a page that contain leaflet map to pdf. I tried to convert the map container to image but thats not working perfectly.
The code I used is here
http://jsfiddle.net/Sq7hg/2/
html2canvas([document.getElementById('mydiv')], {
onrendered: function (canvas) {
document.getElementById('canvas').appendChild(canvas);
var data = canvas.toDataURL('image/png');
console.log(data)
// AJAX call to send `data` to a PHP file that creates an image from the dataURI string and saves it to a directory on the server
var image = new Image();
image.src = data;
document.getElementById('image').appendChild(image);
}
});
This code not working perfectly for leaflet map.How can I implement this ?
I think you'd better off using leaflet-image plugin, which does exactly that. There is a demo linked from the header. The main catch is forcing Leaflet to use canvas for rendering.
I had a problem to export the leaflet map with special markers, I tried to use the plugin leaflet-image but it works only with standard markers.
At the end I created the map in the server (Node).
I wrote a post, How to export the leaflet map to pdf, see link below
Export leaflet map to pdf report

how to save kendo ui chart to image using PHP or java script

i would to convert chart to image, iwish that can saving to png or jpeg
how to save kendo ui chart to image using PHP or java script
Have a look at these:
http://docs.kendoui.com/api/dataviz/chart#methods-svg
http://docs.kendoui.com/api/dataviz/chart#methods-imageDataURL
I've had mixed success with the svg export, but to be fair mine wasn't an "out-of-the-box" scenario.
With HTML 5 you can use this JavaScript:
var image = chart.imageDataURL(); //Kendo UI
var a = $("<a>").attr("href", image).attr("download", "img.png").appendTo("body");
a[0].click();
a.remove();

Dynamically serving images from Google App engine

having problems serving an image stored as a blob from google app engine - I'm trying to view a stored image with the following code
my datastore model is:
class QuestionTemp(db.Model):
picture = db.BlobProperty()
my post call from the initial form is:
class QuestionAsker3(webapp.RequestHandler):
def post(self):
upload_files = self.request.get('file') # 'file' is file upload
tempQuestion = QuestionTemp(picture= db.Blob(upload_files))
tempQuestion.put()
self.response.headers['Content-Type'] = "image/jpeg"
self.response.out.write(tempQuestion.picture)
The image is stored in the blobstore as I can view it in the GAE admin console
"blob viewer".
In chrome the return screen in blank - firefox I get a url and what looks to be a hashcode.
many thanks in advance.
managed to solve the problem - was reading the data into the Blobstore, rather than as a Blob
so the Blob was just storing a references hence had no image data. The .value thing didn't work for me.
Thanks for helping me figure it out #abdul and #adam

Resources