001 package railo.runtime.functions.image; 002 003 import java.awt.RenderingHints; 004 005 import railo.runtime.PageContext; 006 import railo.runtime.exp.FunctionException; 007 import railo.runtime.exp.PageException; 008 import railo.runtime.img.Image; 009 import railo.runtime.op.Caster; 010 011 public class ImageTranslate { 012 013 public static String call(PageContext pc, Object name, double xTrans, double yTrans) throws PageException { 014 return call(pc, name, xTrans, yTrans,"nearest"); 015 } 016 017 public static String call(PageContext pc, Object name, double xTrans, double yTrans, String strInterpolation) throws PageException { 018 if(name instanceof String) name=pc.getVariable(Caster.toString(name)); 019 Image img = Image.toImage(name); 020 021 strInterpolation=strInterpolation.toLowerCase().trim(); 022 Object interpolation = RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR; 023 024 if("nearest".equals(strInterpolation)) interpolation = RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR; 025 else if("bilinear".equals(strInterpolation)) interpolation = RenderingHints.VALUE_INTERPOLATION_BILINEAR; 026 else if("bicubic".equals(strInterpolation)) interpolation = RenderingHints.VALUE_INTERPOLATION_BICUBIC; 027 028 else throw new FunctionException(pc,"ImageTranslate",4,"interpolation","invalid interpolation definition ["+strInterpolation+"], " + 029 "valid interpolation values are [nearest,bilinear,bicubic]"); 030 031 img.translate((int)xTrans, (int)yTrans,interpolation); 032 return null; 033 } 034 }