001    package railo.runtime.functions.image;
002    
003    
004    import railo.runtime.PageContext;
005    import railo.runtime.exp.ExpressionException;
006    import railo.runtime.exp.PageException;
007    import railo.runtime.ext.function.Function;
008    import railo.runtime.img.Image;
009    import railo.runtime.op.Caster;
010    
011    public class ImageRotate implements Function {
012            
013            public static String call(PageContext pc, Object name, String angle) throws PageException {
014                    return _call(pc, name,-1F,-1F,Caster.toFloatValue(angle),"nearest");
015            }
016            
017            public static String call(PageContext pc, Object name, String angle, String strInterpolation) throws PageException {
018                    return _call(pc, name,-1F,-1F,Caster.toFloatValue(angle),strInterpolation);
019            }
020            
021            public static String call(PageContext pc, Object name, String x, String y, String angle) throws PageException {
022                    return _call(pc, name,Caster.toFloatValue(x),Caster.toFloatValue(y),Caster.toFloatValue(angle),"nearest");
023            }
024    
025            public static String call(PageContext pc, Object name, String x, String y, String angle, String strInterpolation) throws PageException {
026                    return _call(pc, name,Caster.toFloatValue(x),Caster.toFloatValue(y),Caster.toFloatValue(angle),strInterpolation);
027            }
028    
029            private static String _call(PageContext pc, Object name, float x, float y, float angle, String strInterpolation) throws PageException {
030                    if(name instanceof String) name=pc.getVariable(Caster.toString(name));
031                    Image img = Image.toImage(name);
032                    strInterpolation=strInterpolation.trim().toLowerCase();
033                    int interpolation;
034                    if("nearest".equals(strInterpolation)) interpolation=railo.runtime.img.Image.INTERPOLATION_NEAREST;
035                    else if("bilinear".equals(strInterpolation)) interpolation=railo.runtime.img.Image.INTERPOLATION_BILINEAR;
036                    else if("bicubic".equals(strInterpolation)) interpolation=railo.runtime.img.Image.INTERPOLATION_BICUBIC;
037                    else if("none".equals(strInterpolation)) interpolation=railo.runtime.img.Image.INTERPOLATION_NONE;
038                    else throw new ExpressionException("invalid interpolation definition ["+strInterpolation+"]," +
039                                    " valid values are [nearest,bilinear,bicubic]");
040                    
041                    img.rotate(x,y,angle,interpolation);
042                    return null;
043                    
044            }
045    }