Search in sources :

Example 16 with Image

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

the class ImageSharpen method call.

public static String call(PageContext pc, Object name, double gain) throws PageException {
    // if(name instanceof String) name=pc.getVariable(Caster.toString(name));
    Image img = Image.toImage(pc, name);
    if (gain < -1.0 || gain > 2.0)
        throw new FunctionException(pc, "ImageSharpen", 2, "gain", "value must be between 1 and 2");
    img.sharpen((float) gain);
    return null;
}
Also used : FunctionException(lucee.runtime.exp.FunctionException) Image(lucee.runtime.img.Image)

Example 17 with Image

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

the class ImageShearDrawingAxis method call.

public static String call(PageContext pc, Object name, double shx, double shy) throws PageException {
    // if(name instanceof String) name=pc.getVariable(Caster.toString(name));
    Image img = Image.toImage(pc, name);
    img.shearAxis(shx, shy);
    return null;
}
Also used : Image(lucee.runtime.img.Image)

Example 18 with Image

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

the class ImageWrite method call.

public static String call(PageContext pc, Object name, String destination, double quality, boolean overwrite) throws PageException {
    // if(name instanceof String)name=pc.getVariable(Caster.toString(name));
    Image image = Image.toImage(pc, name);
    if (quality < 0 || quality > 1)
        throw new FunctionException(pc, "ImageWrite", 3, "quality", "value have to be between 0 and 1");
    Resource res = StringUtil.isEmpty(destination) ? image.getSource() : ResourceUtil.toResourceNotExisting(pc, destination);
    // MUST beide boolschen argumente checken
    if (res == null)
        return null;
    try {
        image.writeOut(res, overwrite, (float) quality);
    } catch (IOException e) {
        throw Caster.toPageException(e);
    }
    return null;
}
Also used : FunctionException(lucee.runtime.exp.FunctionException) Resource(lucee.commons.io.res.Resource) IOException(java.io.IOException) Image(lucee.runtime.img.Image)

Example 19 with Image

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

the class ImageXORDrawingMode method call.

public static String call(PageContext pc, Object name, String color) throws PageException {
    // if(name instanceof String) name=pc.getVariable(Caster.toString(name));
    Image img = Image.toImage(pc, name);
    img.setXorMode(ColorCaster.toColor(color));
    return null;
}
Also used : Image(lucee.runtime.img.Image)

Example 20 with Image

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

the class Sprite method _doStartTag.

public int _doStartTag() throws Throwable {
    // write out div for single item
    pageContext.write("<div id=\"" + _id + "\"></div>");
    // handle all items
    if (!StringUtil.isEmpty(_ids)) {
        String[] ids = ListUtil.listToStringArray(_ids, ',');
        String[] strSrcs = ListUtil.listToStringArray(_srcs, ',');
        Resource[] srcs = new Resource[strSrcs.length];
        Image[] images = new Image[strSrcs.length];
        for (int i = 0; i < srcs.length; i++) {
            srcs[i] = ResourceUtil.toResourceExisting(pageContext, strSrcs[i]);
            images[i] = new Image(srcs[i]);
        }
        // TODO use the same resource as for cfimage
        PageSource ps = pageContext.getCurrentTemplatePageSource();
        Resource dir;
        if (ps != null) {
            Resource curr = ps.getResource();
            dir = curr.getParentResource();
        } else
            dir = SystemUtil.getTempDirectory();
        Resource cssDir = dir.getRealResource("css");
        Resource pathdir = cssDir;
        cssDir.mkdirs();
        // the base name for the files we are going to create as a css and image
        String baseRenderedFileName = MD5.getDigestAsString(_ids);
        Resource cssFileName = cssDir.getRealResource(baseRenderedFileName + ".css");
        Resource imgFileName = pathdir.getRealResource(baseRenderedFileName + "." + ResourceUtil.getExtension(src, ""));
        // if the files don't exist, then we create them, otherwise
        boolean bCreate = !cssFileName.isFile() || !imgFileName.isFile();
        // Are we going to create it, let's say no
        String css = "";
        if (bCreate) {
            int imgMaxHeight = 0;
            int imgMaxWidth = 0;
            Image img;
            int actualWidth, actualHeight;
            // Setup the max height and width of the new image.
            for (int i = 0; i < srcs.length; i++) {
                img = images[i];
                // set the image original height and width
                actualWidth = img.getWidth();
                ;
                actualHeight = img.getHeight();
                // Check if there is a height,
                imgMaxHeight += actualHeight;
                if (actualWidth > imgMaxWidth)
                    imgMaxWidth = actualWidth;
            }
            // Create the new image (hence we needed to do two of these items)
            Image spriteImage = (Image) ImageNew.call(pageContext, "", "" + imgMaxWidth, "" + imgMaxHeight, "argb");
            int placedHeight = 0;
            // Loop again but this time, lets do the copy and paste
            for (int i = 0; i < srcs.length; i++) {
                img = images[i];
                spriteImage.paste(img, 1, placedHeight);
                css += "#" + ids[i] + " {\n\tbackground: url(" + baseRenderedFileName + "." + ResourceUtil.getExtension(strSrcs[i], "") + ") 0px -" + placedHeight + "px no-repeat; width:" + img.getWidth() + "px; height:" + img.getHeight() + "px;\n} \n";
                placedHeight += img.getHeight();
            }
            // Now Write the CSS and the Sprite Image
            ImageWrite.call(pageContext, spriteImage, imgFileName.getAbsolutePath());
            IOUtil.write(cssFileName, css, "UTF-8", false);
        }
        try {
            ((PageContextImpl) pageContext).getRootOut().appendHTMLHead("<link rel=\"stylesheet\" href=\"css/" + baseRenderedFileName + ".css\" type=\"text/css\" media=\"screen\" title=\"no title\" charset=\"utf-8\">");
        } catch (IOException e) {
            Caster.toPageException(e);
        }
    }
    return SKIP_BODY;
}
Also used : Resource(lucee.commons.io.res.Resource) IOException(java.io.IOException) Image(lucee.runtime.img.Image) PageSource(lucee.runtime.PageSource)

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