dongyan6910
dongyan6910
2017-03-25 07:01

Laravel使浏览器呈现动态图像

  • laravel
  • nginx
  • php

I'm using dynamic image generator simple-qrcode. It works fine as img src. However, when I try to directly access, for example site.dev/qr/some-text/60, 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. site.dev/qr/some-text/60/qr.png, 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;
        }


    }
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐