001/**
002 *
003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved.
004 *
005 * This library is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public
007 * License as published by the Free Software Foundation; either 
008 * version 2.1 of the License, or (at your option) any later version.
009 * 
010 * This library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013 * Lesser General Public License for more details.
014 * 
015 * You should have received a copy of the GNU Lesser General Public 
016 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
017 * 
018 **/
019package lucee.runtime.functions.image;
020
021
022import lucee.runtime.PageContext;
023import lucee.runtime.exp.FunctionException;
024import lucee.runtime.exp.PageException;
025import lucee.runtime.ext.function.Function;
026import lucee.runtime.img.Image;
027
028public class ImageResize implements Function {
029
030        public static String call(PageContext pc, Object name,String width, String height) throws PageException {
031                return call(pc, name, width, height, "highestQuality", 1.0);
032        }
033
034        public static String call(PageContext pc, Object name,String width, String height,String interpolation) throws PageException {
035                return call(pc, name, width, height, interpolation, 1.0);
036        }
037        
038        
039        public static String call(PageContext pc, Object name,String width, String height,String interpolation, double blurFactor) throws PageException {
040                // image
041                //if(name instanceof String)name=pc.getVariable(Caster.toString(name));
042                Image image=Image.toImage(pc,name);
043                
044                interpolation = interpolation.toLowerCase().trim();
045                
046                
047                if (blurFactor <= 0.0 || blurFactor > 10.0) 
048                        throw new FunctionException(pc,"ImageResize",5,"blurFactor","argument blurFactor must be between 0 and 10");
049                        
050                
051                // MUST interpolation/blur
052                //if(!"highestquality".equals(interpolation) || blurFactor!=1.0)throw new ExpressionException("argument interpolation and blurFactor are not supported for function ImageResize");
053                
054                image.resize(width,height,interpolation,blurFactor);
055                return null;
056        }
057        
058        /*private static int toDimension(String label, String dimension) throws PageException {
059                if(StringUtil.isEmpty(dimension)) return -1;
060                dimension=dimension.trim();
061                // int value
062                int i=Caster.toIntValue(dimension,-1);
063                if(i>-1) return i;
064                throw new ExpressionException("attribute ["+label+"] value has an invalid value ["+dimension+"]"); 
065        }*/
066}