The Slim Framework support forum has moved to http://discourse.slimframework.com. This Tender forum is no longer maintained or monitored.

How get image for a specific route

slouge's Avatar

slouge

05 Mar, 2012 12:41 PM

I'm trying to get an image for a route like :
/maps/trafficlayer

I think that i need to change headers but how for a specific route ?

$app->response()->header('Content-type', 'image/png'); echo imagepng($source_gd_image);

  1. 1 Posted by slouge on 05 Mar, 2012 12:52 PM

    slouge's Avatar

    ps i'm writing that :
    $app->get('/maps/trafficlayer', function () use ($app) { $app->contentType('image/png'); echo GetTrafficLayer();});

    function GetTrafficLayer()
    { //...

    imagepng($source_gd_image);
        imagedestroy( $source_gd_image );
    

    }

    There is a way to simplify this call ?

  2. 2 Posted by slouge on 05 Mar, 2012 02:22 PM

    slouge's Avatar

    i didn't notice the static method :
    $app = Slim::getInstance();

    So i can use:
    $app->get('/maps/trafficlayer', 'GetTrafficLayer');

    and

    function GetTrafficLayer()
    {

    //...
    $app = Slim::getInstance();
    $app->contentType('image/png');
    echo imagepng($source_gd_image);
    
    imagedestroy( $source_gd_image );
    

    }

  3. 3 Posted by hexa2k9 on 05 Mar, 2012 06:36 PM

    hexa2k9's Avatar

    Hi,

    in case that image is being generated dynamically - what I think it is - you should care about client-side caching by either setting an ETag or a Last-Modified Header (both ways are provided by Slim. See http://www.slimframework.com/documentation/stable#caching) before you echo your png.

    Regards,
    Chris

  4. 4 Posted by slouge on 13 Mar, 2012 06:56 PM

    slouge's Avatar

    Works fine thanks

  5. slouge closed this discussion on 13 Mar, 2012 06:58 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac