public static String call(PageContext pc, Object name, String filterName) throws PageException {
return call(pc, name, filterName, EMPTY_STRUCT);
}
public static String call(PageContext pc, Object name, String filterName, Struct parameters) throws PageException {
if(name instanceof String) name=pc.getVariable(Caster.toString(name));
Image img = Image.toImage(name);
String lcFilterName = filterName.trim().toLowerCase();
// get filter class
Class clazz = filters.get(lcFilterName);
if(clazz==null) {
String[] keys = filters.keySet().toArray(new String[filters.size()]);
Arrays.sort(keys);
String list=ListUtil.arrayToList(keys, ", ");
String soundex = StringUtil.soundex(filterName);
java.util.List<String> similar=new ArrayList<String>();
for(int i=0;i<keys.length;i++){
if(StringUtil.soundex(keys[i]).equals(soundex))
similar.add(keys[i]);
}
if(similar.size()>0) {
list=ListUtil.arrayToList(similar.toArray(new String[similar.size()]), ", ");
throw new FunctionException(pc, "ImageFilter", 2, "filtername", "invalid filter name ["+filterName+"], did you mean ["+list+"]");
}
throw new FunctionException(pc, "ImageFilter", 2, "filtername", "invalid filter name ["+filterName+"], valid filter names are ["+list+"]");
}
// load filter
DynFiltering filter=null;
try {
filter=(DynFiltering) clazz.newInstance();
} catch (Throwable t) {
throw Caster.toPageException(t);
}
// execute filter
BufferedImage bi = img.getBufferedImage();
//BufferedImage empty = bi;//ImageUtil.createBufferedImage(bi);
img.image(filter.filter(bi, parameters));
return null;
}