001    package railo.runtime.functions.image;
002    
003    
004    import railo.runtime.PageContext;
005    import railo.runtime.exp.FunctionException;
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 ImageResize implements Function {
012    
013            public static String call(PageContext pc, Object name,String width, String height) throws PageException {
014                    return call(pc, name, width, height, "highestQuality", 1.0);
015            }
016    
017            public static String call(PageContext pc, Object name,String width, String height,String interpolation) throws PageException {
018                    return call(pc, name, width, height, interpolation, 1.0);
019            }
020            
021            
022            public static String call(PageContext pc, Object name,String width, String height,String interpolation, double blurFactor) throws PageException {
023                    // image
024                    if(name instanceof String)
025                            name=pc.getVariable(Caster.toString(name));
026                    Image image=Image.toImage(name);
027                    
028                    interpolation = interpolation.toLowerCase().trim();
029                    
030                    
031                    if (blurFactor <= 0.0 || blurFactor > 10.0) 
032                            throw new FunctionException(pc,"ImageResize",5,"blurFactor","argument blurFactor must be between 0 and 10");
033                            
034                    
035                    // MUST interpolation/blur
036                    //if(!"highestquality".equals(interpolation) || blurFactor!=1.0)throw new ExpressionException("argument interpolation and blurFactor are not supported for function ImageResize");
037                    
038                    image.resize(width,height,interpolation,blurFactor);
039                    return null;
040            }
041            
042            /*private static int toDimension(String label, String dimension) throws PageException {
043                    if(StringUtil.isEmpty(dimension)) return -1;
044                    dimension=dimension.trim();
045                    // int value
046                    int i=Caster.toIntValue(dimension,-1);
047                    if(i>-1) return i;
048                    throw new ExpressionException("attribute ["+label+"] value has an invalid value ["+dimension+"]"); 
049            }*/
050    }