fponticelli / ufront

MVC 2 framework for Haxe

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ImageResult is not functioning as we don't have uimage

andyli opened this issue · comments

As title, or is uimage up in anywhere?
It is better to have a simple ImageResult, something like:

package ufront.web.mvc;

import haxe.io.Bytes;
import thx.error.NullArgument;

class ImageResult extends ActionResult
{
    public var format:String;
    public var image:Bytes;

    public function new(image:Bytes, format:String)
    {
        NullArgument.throwIfNull(format);
        this.format = format;
        NullArgument.throwIfNull(image);
        this.image = image;
    }

    override function executeResult(controllerContext : ControllerContext)
    {
        NullArgument.throwIfNull(controllerContext);
        var response = controllerContext.response;
        response.contentType = switch(format.toLowerCase()) {
            case "jpeg", "jpg": "image/jpeg";
            case "png": "image/png";
            case "gif": "image/gif";
            default: throw "unknow image format: " + format;
        }

        response.setHeader("Content-Length", "" + image.length);
//      response.setHeader("Last-Modified", DateTools.format(Date.now(), '%a, %d %b %Y %H:%M:%S') + ' GMT');
        response.writeBytes(image, 0, image.length);
    }
}

I've never published UImage because it was too incomplete. I agree that generalizing the class is the best path to follow so feel free to provide a patch if you have the time.
Ideally I'd like to integrate a GD/ImageMagick lib but so far I have not found one that has the right ndlls for Neko (cross platform).

What about http://lib.haxe.org/p/ImageMagick?
I'm using it for php target. And it supports neko target too although I've never tested.

Sounds good ... it seems to miss the Mac ndll but I can probably contact the author and ask for instruction to build it myself.
Ideally the ImageMagickResult will extend the ImageResult transformed as you suggested.