Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
54
rated 0 times [  55] [ 1]  / answers: 1 / hits: 20154  / 8 Years ago, mon, august 1, 2016, 12:00:00

I'm using angularJS and need to apply a watermark programatelly in images by calling an JS function. What I have is:



<figure><img class=watermark ng-src={{applyWatermark(img.url)}}></figure>  


So, I need to call that function applyWatermark (not implemented yet) and return a img with the watermark, but I'm not sure how can I build this function. Should it return the image? Can someone provide me some example how can I do this?



EDIT:



I did this, but it's not working:



 $(function applyWatermark(image) {                                                                                                                                                                                                      
watermark([image, 'watermark.png'])
.image(watermark.image.lowerRight())
.then(function (img) {
return img
});
})


Any idea?


More From » javascript

 Answers
13

Using watermark.js:



watermark(['/img/forest.jpg', '/img/logo.png'])
.image(watermark.image.lowerRight(0.5)) // Or lowerRight() for no opacity
.then(function (img) {
document.getElementById('alpha-image').appendChild(img);
});


If this doesn't work for you, maybe try this:



$.ajax({
url: 'http://www.example.com/your-image.jpg',
type: 'HEAD',
error: function() {
// File isn't found
},
success: function() {
// File is found! Do the watermarkage.
}
});


to test if the image exists before processing.


[#61189] Thursday, July 28, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tyreese

Total Points: 739
Total Questions: 95
Total Answers: 98

Location: Belize
Member since Mon, Jun 20, 2022
2 Years ago
;