Can I get the list of Caman.js filters?

312 views Asked by At

Is there any way to return the list of all the built-in filters within the library.

For example:

var caman_Default_List = [];
Caman('myCanvas', function(){

     caman_Default_List= this.getAllFilters();
});

For now I'm using this and it works okay:

var filters =  
[   
   "vintage", "lomo", "clarity", "sinCity", "sunrise", 
   "crossProcess", "orangePeel", "love", "grungy", "jarques", "pinhole", 
   "oldBoot", "glowingSun", "hazyDays", "herMajesty", "nostalgia", 
   "hemingway", "concentrate"
];

myList.push(filters[   some filters   ]);

Caman("#myCanvas", function(){

     this[myList[index]]().render();
});

But I was wondering if there is a way to get the values of the filters without delcaring them customly. (eg. list = [ "vintage", "lomo", ......... ])

2

There are 2 answers

1
Andrew Lohr On

I was looking through their docs, but could not find anything helpful for the data you are trying to get. I took a look at their code and came up with the below for you.

I am not sure I would 100% trust the code, because the order of properties might change, but at least it gives you what you wanted.

console.log(Object.keys(Caman.prototype).slice(75, 93))
<script src="https://cdnjs.cloudflare.com/ajax/libs/camanjs/4.1.2/caman.full.min.js"></script>

0
Loizos Vasileiou On

I used the code below to achieve what I wanted as @AndrewLohr stated:

    //Declare lists to store filter names
    var list4,list5,list6,list7 = [];

    //Get Caman Filters (Samples : "vintage", "clarity", ... )
    list4 = (Object.keys(Caman.prototype).slice(75, 93));
    list5 = list4.toString().toUpperCase(); //To upper Case as string value (use as Label Button Name)

    //Get Caman Filters (Customs : "brightness", "saturation")
    list6 = Object.keys(Caman.prototype).slice(45, 55);
    //Add some more elements in the list
    list6.push("clip", "stuckBlur", "exposure", "noise", "sharpen");

    list7 = list6.toString().toUpperCase(); //To upper Case as string value (use as Slider Name)


    //Print lists 
    console.log(list4);console.log(list5);console.log(list6);console.log(list7);
<script src="https://cdnjs.cloudflare.com/ajax/libs/camanjs/4.1.2/caman.full.min.js"></script>