Search in sources :

Example 6 with Image

use of lucee.runtime.img.Image 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 7 with Image

use of lucee.runtime.img.Image in project Lucee by lucee.

the class ImageDrawText method call.

public static String call(PageContext pc, Object name, String str, double x, double y, Struct ac) throws PageException {
    // if(name instanceof String) name=pc.getVariable(Caster.toString(name));
    Image img = Image.toImage(pc, name);
    img.drawString(str, (int) x, (int) y, ac);
    return null;
}
Also used : Image(lucee.runtime.img.Image)

Example 8 with Image

use of lucee.runtime.img.Image 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)

Example 9 with Image

use of lucee.runtime.img.Image in project Lucee by lucee.

the class ImageGetEXIFTag method call.

public static Object call(PageContext pc, Object name, String tagName) throws PageException {
    // if(name instanceof String) name=pc.getVariable(Caster.toString(name));
    Image img = Image.toImage(pc, name);
    // ImageGetEXIFMetadata.getData(img);
    Struct data = img.info();
    Object value = data.get(tagName, null);
    if (value == null) {
        throw new FunctionException(pc, "ImageGetEXIFTag", 2, "tagName", ExceptionUtil.similarKeyMessage(data, tagName, "tag", "tags", null, true));
    }
    return value;
}
Also used : FunctionException(lucee.runtime.exp.FunctionException) Image(lucee.runtime.img.Image) Struct(lucee.runtime.type.Struct)

Example 10 with Image

use of lucee.runtime.img.Image in project Lucee by lucee.

the class ImageResize method call.

public static String call(PageContext pc, Object name, String width, String height, String interpolation, double blurFactor) throws PageException {
    // image
    // if(name instanceof String)name=pc.getVariable(Caster.toString(name));
    Image image = Image.toImage(pc, name);
    interpolation = interpolation.toLowerCase().trim();
    if (blurFactor <= 0.0 || blurFactor > 10.0)
        throw new FunctionException(pc, "ImageResize", 5, "blurFactor", "argument blurFactor must be between 0 and 10");
    // MUST interpolation/blur
    // if(!"highestquality".equals(interpolation) || blurFactor!=1.0)throw new ExpressionException("argument interpolation and blurFactor are not supported for function ImageResize");
    image.resize(width, height, interpolation, blurFactor);
    return null;
}
Also used : FunctionException(lucee.runtime.exp.FunctionException) Image(lucee.runtime.img.Image)

Aggregations

Image (lucee.runtime.img.Image)38 FunctionException (lucee.runtime.exp.FunctionException)17 IOException (java.io.IOException)4 Color (java.awt.Color)3 Resource (lucee.commons.io.res.Resource)3 BufferedImage (java.awt.image.BufferedImage)2 ExpressionException (lucee.runtime.exp.ExpressionException)2 Paint (java.awt.Paint)1 Point (java.awt.Point)1 ArrayList (java.util.ArrayList)1 ShearDir (javax.media.jai.operator.ShearDir)1 TransposeType (javax.media.jai.operator.TransposeType)1 PageSource (lucee.runtime.PageSource)1 ConverterException (lucee.runtime.converter.ConverterException)1 Struct (lucee.runtime.type.Struct)1