3
I have a canvas, in which I manipulate images drawn on it with the plugin Camanjs and works perfectly. However, if I manipulate the canvas manually (without the help of the plugin) the image loses the effect. For example, I add a filter (Vintage, for example) to the image and it works perfectly, but if I invert the canvas using translate
and scale
the canvas is reversed but the image loses the effect. It seems that with each change in the image through the plugin, it saves its current state, and therefore the effect is lost after some change without using it. How to do this while preserving the effects of the image?
To add the effect, I use the same examples of the plugin site, already the code to invert the canvas is (js scripts.):
$(document).ready(function() {
$("html, body").on("click", "#vintage", function() {
Caman("#filtrar", function() {
this.vintage().render();
});
});
$("html, body").on("click", "#inverter_foto", function() {
var c = $("#filtrar")[0];
var ctx = c.getContext("2d");
ctx.translate(filtro_width, 0);
ctx.scale(-1, 1);
ctx.drawImage(filtro, 0, 0);
});
});
The variables filtro_width
and filtro
match the picture drawn in the canvas.
html:
<canvas id="filtrar" width="640" height="255"></canvas>
<button id="vintage">Vintage Effect</button>
<button id="inverter_foto">Reverse</button>
<script type="text/javascript" src="/js/jquery-2.1.3.min.js"></script>
</script>
<script type="text/javascript" src="/js/caman.full.min.js"></script>
<script type="text/javascript" src="/js/scripts.js"></script>
You could save somewhere the last added effect on the image, and whenever you do something on the canvas like Translate, add that effect again. There’s a way to put in your code so we can take a look?
– PauloHDSousa
@Wouldn’t Paulohdsousa have a simpler way of doing that? Because the user has the option to add several effects and maybe it would be a little difficult to save them. I’m taking a look at the code of the plugin to see if I can find something related to this "save" function for each added effect. I added excerpt of my code to the question.
– Igor
Can you post more code and HTML? If you are creating a context or something similar and not using the existing one, it may be that you are recreating the image and so it loses the effect. You use Caman on canvas and not in the image?
– PauloHDSousa
The code that really matters (where I manipulate the canvas) is what’s already in the question, @Paulohdsousa . I believe that’s right, I’m creating another context... How can I use the existing?
– Igor
Try extending ->Extend the http://www.sitepoint.com/manipulating-images-web-pages-camanjs plugin/
– PauloHDSousa
I created an Extended using Register only to invert the image. After adding the effect, by clicking reverse it reverses but I continue with the same problem, by reversing the effect is lost...
– Igor
Managed to Resolve?
– durtto