我可以获取Caman.js过滤器列表吗?

时间:2019-01-24 17:17:08

标签: javascript html css filter camanjs

有什么方法可以返回库中所有内置过滤器的列表。

例如:

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

     caman_Default_List= this.getAllFilters();
});

现在我正在使用它,它可以正常工作:

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();
});

但是我想知道是否有一种方法来获取过滤器的值而不必自定义它们。 (例如list = [“ vintage”,“ lomo”,.........])

2 个答案:

答案 0 :(得分:1)

我一直在浏览他们的文档,但是找不到任何对您尝试获取的数据有用的信息。我查看了他们的代码,并为您提供了以下内容。

我不确定我会100%信任代码,因为属性的顺序可能会改变,但至少它会为您提供所需的内容。

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>

答案 1 :(得分:0)

我使用下面的代码来实现我想要的@AndrewLohr所说的:

    //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>