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 021import javax.media.jai.operator.TransposeDescriptor; 022import javax.media.jai.operator.TransposeType; 023 024import lucee.runtime.PageContext; 025import lucee.runtime.exp.FunctionException; 026import lucee.runtime.exp.PageException; 027import lucee.runtime.img.Image; 028 029public class ImageFlip { 030 public static String call(PageContext pc, Object name) throws PageException { 031 return call(pc,name,"vertical"); 032 } 033 public static String call(PageContext pc, Object name, String strTranspose) throws PageException { 034 //if(name instanceof String) name=pc.getVariable(Caster.toString(name)); 035 Image img = Image.toImage(pc,name); 036 037 strTranspose=strTranspose.toLowerCase().trim(); 038 TransposeType transpose = TransposeDescriptor.FLIP_VERTICAL; 039 if("vertical".equals(strTranspose)) transpose=TransposeDescriptor.FLIP_VERTICAL; 040 else if("horizontal".equals(strTranspose)) transpose=TransposeDescriptor.FLIP_HORIZONTAL; 041 else if("diagonal".equals(strTranspose)) transpose=TransposeDescriptor.FLIP_DIAGONAL; 042 else if("antidiagonal".equals(strTranspose)) transpose=TransposeDescriptor.FLIP_ANTIDIAGONAL; 043 else if("anti diagonal".equals(strTranspose)) transpose=TransposeDescriptor.FLIP_ANTIDIAGONAL; 044 else if("anti-diagonal".equals(strTranspose)) transpose=TransposeDescriptor.FLIP_ANTIDIAGONAL; 045 else if("anti_diagonal".equals(strTranspose)) transpose=TransposeDescriptor.FLIP_ANTIDIAGONAL; 046 else if("90".equals(strTranspose)) transpose=TransposeDescriptor.ROTATE_90; 047 else if("180".equals(strTranspose)) transpose=TransposeDescriptor.ROTATE_180; 048 else if("270".equals(strTranspose)) transpose=TransposeDescriptor.ROTATE_270; 049 else throw new FunctionException(pc,"ImageFlip",2,"transpose","invalid transpose definition ["+strTranspose+"], " + 050 "valid transpose values are [vertical,horizontal,diagonal,90,180,270]"); 051 052 img.flip(transpose); 053 return null; 054 } 055 056}