001    package railo.runtime.functions.image;
002    
003    
004    import javax.media.jai.BorderExtender;
005    
006    import railo.commons.color.ColorCaster;
007    import railo.runtime.PageContext;
008    import railo.runtime.exp.PageException;
009    import railo.runtime.ext.function.Function;
010    import railo.runtime.img.Image;
011    import railo.runtime.op.Caster;
012    
013    public class ImageAddBorder implements Function {
014            public static String call(PageContext pc, Object name) throws PageException {
015                    return call(pc,name,1D,"black","constant");
016            }
017            
018            public static String call(PageContext pc, Object name, double thickness) throws PageException {
019                    return call(pc,name,thickness,"black","constant");
020            }
021            
022            public static String call(PageContext pc, Object name, double thickness, String color) throws PageException {
023                    return call(pc,name,thickness,color,"constant");
024            }
025    
026            public static String call(PageContext pc, Object name, double thickness, String color, String strBorderType) throws PageException {
027                    if(name instanceof String)
028                            name=pc.getVariable(Caster.toString(name));
029                    strBorderType=strBorderType.trim().toLowerCase();
030                    int borderType=Image.BORDER_TYPE_CONSTANT;
031                    if("zero".equals(strBorderType))                        borderType=BorderExtender.BORDER_ZERO;
032                    else if("constant".equals(strBorderType))       borderType=Image.BORDER_TYPE_CONSTANT;
033                    else if("copy".equals(strBorderType))           borderType=BorderExtender.BORDER_COPY;
034                    else if("reflect".equals(strBorderType))        borderType=BorderExtender.BORDER_REFLECT;
035                    else if("wrap".equals(strBorderType))           borderType=BorderExtender.BORDER_WRAP;
036            
037                    Image image=Image.toImage(name);
038                    image.addBorder((int)thickness,ColorCaster.toColor(color),borderType);
039                    
040                    
041                    return null;
042            }
043    }