Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I save a manipulated image?

I use a javascript image processing library to manipulate an image, and when I'm done I want to have the possibility to save the image (a new file) to the server and keep track of it in a database. The database part is no problem, but how do I save the image without losing the manipulation done?

Are there any libraries for that or is it easiest to just do it myself?

like image 854
Gustav Avatar asked Dec 02 '25 16:12

Gustav


1 Answers

It doesn't seem like Pixastic provides an interface for this, specifically, but there is a property in the options giving you the resulting canvas:

var options = {};
Pixastic.process(image, "action", options);
options.resultCanvas; // <- holds new canvas

This canvas object you can use to obtain a "data URL":

options.resultCanvas.toDataURL('image/jpeg')

Uploading 'canvas' image data to the server

The "data URL" is a tiny header (see the so-post linked) and the file content in a string. You can post this to the server for storage.

like image 62
geon Avatar answered Dec 04 '25 05:12

geon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!