samedi 25 mars 2017

Laravel make the browser render a dynamic image

I'm using dynamic image generator simple-qrcode. It works fine as img src. However, when I try to directly access, for example http://ift.tt/2og0uCF, the image from the client's address bar it returns encoded text not an image.

The following is the action method:

public function qr($txt='None',$size=32)
    {
        return QrCode::format('png')->size($size)->generate(urldecode($txt));
    }

The following is the route in web.php:

Route::get('/generator/qr/{txt?}/{size?}', 'GeneratorController@qr')->where(['txt', '(.*)/']);

I have tried to add .png hoping the browser consider it as an image i.e. http://ift.tt/2nygF0Y, to the route, but it does not work too, as the following:

Route::get('/generator/qr/{txt?}/{size?}/qr.png', 'GeneratorController@qr')->where(['txt', '(.*)/']);

The application is running using PHP7.1.3 as fastcgi on Nginx 1.10.3 / Windows10 64 bit. The following is the virtual host settings of Nginx:

server {
        listen       80;
        server_name  site.dev;
        location /{
            root   C:/Users/Said/Desktop/Project/laravel/site/public;
            index  index.php index.html index.htm;
            try_files $uri $uri/ /index.php?$query_string;
        }
        error_page  404              /404.html;        
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }        
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  C:/Users/Said/Desktop/Project/laravel/site/public/$fastcgi_script_name;

            fastcgi_buffer_size 128k;
            fastcgi_buffers 256 16k;
            fastcgi_busy_buffers_size 256k;
            fastcgi_temp_file_write_size 256k;

            include        fastcgi_params;
        }        
        location ~ /\.ht {
            deny  all;
        }


    }



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2ofUrhD
via IFTTT

Aucun commentaire:

Enregistrer un commentaire