001    package railo.runtime.functions.image;
002    
003    
004    import java.io.IOException;
005    
006    import railo.commons.io.res.util.ResourceUtil;
007    import railo.runtime.PageContext;
008    import railo.runtime.exp.FunctionException;
009    import railo.runtime.exp.PageException;
010    import railo.runtime.ext.function.Function;
011    import railo.runtime.img.Image;
012    import railo.runtime.op.Caster;
013    
014    public class ImageWrite implements Function {
015    
016            public static String call(PageContext pc, Object name) throws PageException {
017                    return call(pc, name, null, 0.75,true);
018            }
019    
020            public static String call(PageContext pc, Object name, String destination) throws PageException {
021                    return call(pc, name, destination, 0.75,true);
022            }
023            
024            public static String call(PageContext pc, Object name, String destination, double quality) throws PageException {
025                    return call(pc, name,destination,quality,true);
026            }
027            
028            public static String call(PageContext pc, Object name, String destination, double quality, boolean overwrite) throws PageException {
029                    if(name instanceof String)
030                            name=pc.getVariable(Caster.toString(name));
031                    Image image=Image.toImage(name);
032                    
033                    if(quality<0 || quality>1)
034                            throw new FunctionException(pc,"ImageWrite",3,"quality","value have to be between 0 and 1");
035                    
036                    // MUST beide boolschen argumente checken
037                    if(destination==null) return null;
038                    try {
039                            image.writeOut(ResourceUtil.toResourceNotExisting(pc, destination), overwrite , (float)quality);
040                    } catch (IOException e) {
041                            throw Caster.toPageException(e);
042                    }
043                    return null;
044            }
045    }