<?php

/* @type $Params string[] */

// Definition : $Params = array ( MediaCase, ArticleObjectId, ArticleLanguage, Alias, Variation )

try
{
    $imageArticleTool = new ImageArticleTool ($Params);
    $imageArticleTool->initImage();
    $content = $imageArticleTool->getImageContent();

    if ( strlen($content) == 0 )
        throw new Exception( 'Content is empty' );

    header( 'Content-Type: ' . $imageArticleTool->getImageMimeType() );
    header( 'Content-Length: ' . $imageArticleTool->getImageSize() );

    echo $content;
}
catch ( Exception $e )
{
    $context = ContextTool::instance();
    if ( !($context->environment() & ContextTool::ENVIRONMENT_PROD) )
    {
        eZLog::write( $e->getMessage(), 'article_image.log' );
    }

    $statusReason = HttpTool::$statusReason[404];
    header( "{$_SERVER['SERVER_PROTOCOL']} 404 {$statusReason}" );
}