好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

Laravel4创建一个占位图片服务例子 - php高级应用

Laravel4创建一个占位图片服务例子

下面我来给大家转一个关于Laravel4创建一个占位图片服务例子,使用Composer安装intervention/image库,代码如下:

composer require intervention/image:dev-master

编码,代码如下:

// vim app/routes.php   <?php  Route::pattern( 'width' ,  '\d+' );  Route::pattern( 'height' ,  '\d+' );  Route::get( '{width}x{height}' ,  'ImageHolderController@getIndex' );  // vim app/controllers/ImageHolderController.php   <?php    class  ImageHolderController  extends  BaseController {       public   function  getIndex( $width ,  $height )      {           $width  =  intval ( $width );           $height  =  intval ( $height );           if  ( $width  > 1900 ||  $height  > 900)              App::abort(404);           $fontSize  = min(max( intval ( $width  / 5), 12), 38)(HdhCmsTest111cn.net);           $image  = Image::canvas( $width ,  $height ,  '#CCCCCC' )                  ->line( '#B5B5B5' , 0, 0,  $width ,  $height )                  ->line( '#B5B5B5' ,  $width , 0, 0,  $height )                  ->text( $width  .  'x'  .  $height ,  $width  / 2,  $height  / 2,  function  ( $font )  use  ( $fontSize ) {                       $font ->file(public_path( 'font/Georgia.ttf' ));                       $font ->align( 'center' );                       $font ->valign( 'middle' );                       $font ->size( $fontSize );                       $font ->color( '#666666' );                  });           return  Response::make( $image , 200,  array ( 'Content-Type'  =>  'image/png' ));      }  } 

查看更多关于Laravel4创建一个占位图片服务例子 - php高级应用的详细内容...

  阅读:48次