LunaticThinker.me

Thoughts on code and poetry.

Welcome to LunaticThinker.me - thoughts on code and poetry.

Railo / ColdFusion – Writing Image to Outpout Stream

Hello guys,

Needed to do this for a project my team is maintaining, but I could only find the solution for ColdFusion, which looks like this:

JavaImport = structNew();

JavaImport.io = structNew();
JavaImport.io.File = CreateObject('java', 'java.io.File');

JavaxImport = StructNew();

JavaxImport.imageio = StructNew();
JavaxImport.imageio.ImageIO = CreateObject('java', 'javax.imageio.ImageIO');

imageBuffer = JavaxImport.imageio.ImageIO.read(JavaImport.io.File.Init(imagePath));

response = getPageContext().getFusionContext().getResponse();
response.setHeader('Content-Type', 'image/png');
response.setHeader('Cache-Control', 'max-age=604800, public');
JavaxImport.imageio.ImageIO.write(imageBuffer, "png", response.getResponse().getOutputStream() );

After consulting Railo documentation on GetPageContext method, we’ve come to the following result:

CFML Generating Random String

While working on one of my client’s projects, I’ve encountered the need of generating RANDOM strings. Since, as almost, any other language, Cold Fusion does not have any type of support for this functionality, I had to create a function of my own.

Hope you find it useful.


    function RandomString(length, chars="ABCDEFGHIJKLMNOPQRST0123456789-") {
        var i = 0;
        var theString = "";
        for (i = 0; i < length; i++) {
            theString &= Mid(chars, RandRange(1, len(chars), "SHA1PRNG"), 1);
        }
        return theString;
    }

Zend Framework 2 Generating Route Url With Domain Name

Nothing more than this little line of code:

$homeUrl = $this->url(
    'youRouteName',
    array(/* your route params */),
    array('force_canonical' => true)
);

Of course, you need to call it within a code zone where you can invoke the URL helper. What you see above, assumes that you are in a .phtml file invoked by a controller’s action.