001    package railo.runtime.functions.image;
002    
003    import javax.media.jai.operator.TransposeDescriptor;
004    import javax.media.jai.operator.TransposeType;
005    
006    import railo.runtime.PageContext;
007    import railo.runtime.exp.FunctionException;
008    import railo.runtime.exp.PageException;
009    import railo.runtime.img.Image;
010    import railo.runtime.op.Caster;
011    
012    public class ImageFlip {
013            public static String call(PageContext pc, Object name) throws PageException {
014                    return call(pc,name,"vertical");
015            }
016            public static String call(PageContext pc, Object name, String strTranspose) throws PageException {
017                    if(name instanceof String) name=pc.getVariable(Caster.toString(name));
018                    Image img = Image.toImage(name);
019                    
020                    strTranspose=strTranspose.toLowerCase().trim();
021                    TransposeType transpose = TransposeDescriptor.FLIP_VERTICAL;
022                    if("vertical".equals(strTranspose)) transpose=TransposeDescriptor.FLIP_VERTICAL;
023                    else if("horizontal".equals(strTranspose)) transpose=TransposeDescriptor.FLIP_HORIZONTAL;
024                    else if("diagonal".equals(strTranspose)) transpose=TransposeDescriptor.FLIP_DIAGONAL;
025                    else if("antidiagonal".equals(strTranspose)) transpose=TransposeDescriptor.FLIP_ANTIDIAGONAL;
026                    else if("anti diagonal".equals(strTranspose)) transpose=TransposeDescriptor.FLIP_ANTIDIAGONAL;
027                    else if("anti-diagonal".equals(strTranspose)) transpose=TransposeDescriptor.FLIP_ANTIDIAGONAL;
028                    else if("anti_diagonal".equals(strTranspose)) transpose=TransposeDescriptor.FLIP_ANTIDIAGONAL;
029                    else if("90".equals(strTranspose)) transpose=TransposeDescriptor.ROTATE_90;
030                    else if("180".equals(strTranspose)) transpose=TransposeDescriptor.ROTATE_180;
031                    else if("270".equals(strTranspose)) transpose=TransposeDescriptor.ROTATE_270;
032                    else throw new FunctionException(pc,"ImageFlip",2,"transpose","invalid transpose definition ["+strTranspose+"], " +
033                                    "valid transpose values are [vertical,horizontal,diagonal,90,180,270]");
034                    
035                    img.flip(transpose);
036                    return null;
037            }
038            
039    }