Search in sources :

Example 81 with FunctionException

use of lucee.runtime.exp.FunctionException in project Lucee by lucee.

the class ImageCrop method call.

public static String call(PageContext pc, Object name, double x, double y, double width, double height) throws PageException {
    // if(name instanceof String) name=pc.getVariable(Caster.toString(name));
    Image img = Image.toImage(pc, name);
    if (width < 0)
        throw new FunctionException(pc, "ImageCrop", 3, "width", "width must contain a none negative value");
    if (height < 0)
        throw new FunctionException(pc, "ImageCrop", 4, "height", "width must contain a none negative value");
    img.crop((float) x, (float) y, (float) width, (float) height);
    return null;
}
Also used : FunctionException(lucee.runtime.exp.FunctionException) Image(lucee.runtime.img.Image)

Example 82 with FunctionException

use of lucee.runtime.exp.FunctionException in project Lucee by lucee.

the class ImageDrawBeveledRect method call.

public static String call(PageContext pc, Object name, double x, double y, double width, double height, boolean raised, boolean filled) throws PageException {
    // if(name instanceof String) name=pc.getVariable(Caster.toString(name));
    Image img = Image.toImage(pc, name);
    if (width < 0)
        throw new FunctionException(pc, "ImageDrawBeveledRect", 3, "width", "width must contain a none negative value");
    if (height < 0)
        throw new FunctionException(pc, "ImageDrawBeveledRect", 4, "height", "width must contain a none negative value");
    img.draw3DRect((int) x, (int) y, (int) width, (int) height, raised, filled);
    return null;
}
Also used : FunctionException(lucee.runtime.exp.FunctionException) Image(lucee.runtime.img.Image)

Example 83 with FunctionException

use of lucee.runtime.exp.FunctionException in project Lucee by lucee.

the class ImageDrawRect method call.

public static String call(PageContext pc, Object name, double x, double y, double width, double height, boolean filled) throws PageException {
    // if(name instanceof String) name=pc.getVariable(Caster.toString(name));
    Image img = Image.toImage(pc, name);
    if (width < 0)
        throw new FunctionException(pc, "ImageDrawRect", 3, "width", "width must contain a none negative value");
    if (height < 0)
        throw new FunctionException(pc, "ImageDrawRect", 4, "height", "width must contain a none negative value");
    img.drawRect((int) x, (int) y, (int) width, (int) height, filled);
    return null;
}
Also used : FunctionException(lucee.runtime.exp.FunctionException) Image(lucee.runtime.img.Image)

Example 84 with FunctionException

use of lucee.runtime.exp.FunctionException in project Lucee by lucee.

the class ImageDrawRoundRect method call.

public static String call(PageContext pc, Object name, double x, double y, double width, double height, double arcWidth, double arcHeight, boolean filled) throws PageException {
    // if(name instanceof String) name=pc.getVariable(Caster.toString(name));
    Image img = Image.toImage(pc, name);
    if (width < 0)
        throw new FunctionException(pc, "ImageDrawRoundRect", 3, "width", "width must contain a none negative value");
    if (height < 0)
        throw new FunctionException(pc, "ImageDrawRoundRect", 4, "height", "width must contain a none negative value");
    if (arcWidth < 0)
        throw new FunctionException(pc, "ImageDrawRoundRect", 5, "arcWidth", "arcWidth must contain a none negative value");
    if (arcHeight < 0)
        throw new FunctionException(pc, "ImageDrawRoundRect", 6, "arcHeight", "arcHeight must contain a none negative value");
    img.drawRoundRect((int) x, (int) y, (int) width, (int) height, (int) arcWidth, (int) arcHeight, filled);
    return null;
}
Also used : FunctionException(lucee.runtime.exp.FunctionException) Image(lucee.runtime.img.Image)

Example 85 with FunctionException

use of lucee.runtime.exp.FunctionException in project Lucee by lucee.

the class ImageFilter method call.

public static String call(PageContext pc, Object name, String filterName, Struct parameters) throws PageException {
    // if(name instanceof String) name=pc.getVariable(Caster.toString(name));
    Image img = Image.toImage(pc, name);
    String lcFilterName = filterName.trim().toLowerCase();
    // get filter class
    Class clazz = filters.get(lcFilterName);
    if (clazz == null) {
        String[] keys = filters.keySet().toArray(new String[filters.size()]);
        Arrays.sort(keys);
        String list = ListUtil.arrayToList(keys, ", ");
        String soundex = StringUtil.soundex(filterName);
        java.util.List<String> similar = new ArrayList<String>();
        for (int i = 0; i < keys.length; i++) {
            if (StringUtil.soundex(keys[i]).equals(soundex))
                similar.add(keys[i]);
        }
        if (similar.size() > 0) {
            list = ListUtil.arrayToList(similar.toArray(new String[similar.size()]), ", ");
            throw new FunctionException(pc, "ImageFilter", 2, "filtername", "invalid filter name [" + filterName + "], did you mean [" + list + "]");
        }
        throw new FunctionException(pc, "ImageFilter", 2, "filtername", "invalid filter name [" + filterName + "], valid filter names are [" + list + "]");
    }
    // load filter
    DynFiltering filter = null;
    try {
        filter = (DynFiltering) clazz.newInstance();
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        throw Caster.toPageException(t);
    }
    // execute filter
    BufferedImage bi = img.getBufferedImage();
    // BufferedImage empty = bi;//ImageUtil.createBufferedImage(bi);
    img.image(filter.filter(bi, parameters));
    return null;
}
Also used : ArrayList(java.util.ArrayList) FunctionException(lucee.runtime.exp.FunctionException) Image(lucee.runtime.img.Image) BufferedImage(java.awt.image.BufferedImage) Point(java.awt.Point) Paint(java.awt.Paint) BufferedImage(java.awt.image.BufferedImage)

Aggregations

FunctionException (lucee.runtime.exp.FunctionException)189 BufferedImage (java.awt.image.BufferedImage)123 Image (lucee.runtime.img.Image)17 Struct (lucee.runtime.type.Struct)13 Array (lucee.runtime.type.Array)12 Resource (lucee.commons.io.res.Resource)10 ArrayList (java.util.ArrayList)7 IOException (java.io.IOException)6 Iterator (java.util.Iterator)6 Query (lucee.runtime.type.Query)6 ForEachQueryIterator (lucee.runtime.type.it.ForEachQueryIterator)6 Enumeration (java.util.Enumeration)5 List (java.util.List)5 ListIterator (java.util.ListIterator)5 ExecutorService (java.util.concurrent.ExecutorService)5 Future (java.util.concurrent.Future)5 Iteratorable (lucee.runtime.type.Iteratorable)5 StringListData (lucee.runtime.type.util.StringListData)5 ArrayImpl (lucee.runtime.type.ArrayImpl)4 StructImpl (lucee.runtime.type.StructImpl)4