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 java.io.IOException; 023 024import lucee.commons.io.res.util.ResourceUtil; 025import lucee.runtime.PageContext; 026import lucee.runtime.exp.FunctionException; 027import lucee.runtime.exp.PageException; 028import lucee.runtime.ext.function.Function; 029import lucee.runtime.img.Image; 030import lucee.runtime.op.Caster; 031 032public class ImageWrite implements Function { 033 034 public static String call(PageContext pc, Object name) throws PageException { 035 return call(pc, name, null, 0.75,true); 036 } 037 038 public static String call(PageContext pc, Object name, String destination) throws PageException { 039 return call(pc, name, destination, 0.75,true); 040 } 041 042 public static String call(PageContext pc, Object name, String destination, double quality) throws PageException { 043 return call(pc, name,destination,quality,true); 044 } 045 046 public static String call(PageContext pc, Object name, String destination, double quality, boolean overwrite) throws PageException { 047 //if(name instanceof String)name=pc.getVariable(Caster.toString(name)); 048 Image image=Image.toImage(pc,name); 049 050 if(quality<0 || quality>1) 051 throw new FunctionException(pc,"ImageWrite",3,"quality","value have to be between 0 and 1"); 052 053 // MUST beide boolschen argumente checken 054 if(destination==null) return null; 055 try { 056 image.writeOut(ResourceUtil.toResourceNotExisting(pc, destination), overwrite , (float)quality); 057 } catch (IOException e) { 058 throw Caster.toPageException(e); 059 } 060 return null; 061 } 062}