Skip to content

Instantly share code, notes, and snippets.

@nickshek
Created June 5, 2016 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickshek/8b068619c9ba9bda2ce941a70a0c11e2 to your computer and use it in GitHub Desktop.
Save nickshek/8b068619c9ba9bda2ce941a70a0c11e2 to your computer and use it in GitHub Desktop.
Simple PlaceHolder API using Laravel and Intervention
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use Intervention\Image\ImageManager;
class PlaceHolderController extends Controller
{
public function serve($width,$height,$background_color = "#000",$text=NULL){
if($width <= 0){
return redirect()->action("ImageController@not_found");
}
if($height <= 0){
return redirect()->action("ImageController@not_found");
}
$manager = new ImageManager();
$img = $manager->canvas($width, $height, $background_color);
if($text === NULL){
$text = sprintf("%sx%s",$width,$height);
}
$font_size = 32;
if($width <= 150 && $height <= 100){
$font_size = 16;
}
if($width >= 60 && $height >= 30){
$img->text($text, $width/2, $height/2, function($font) use($font_size) {
$font->size($font_size);
$font->color(array(255, 255, 255));
$font->file(base_path('resources/assets/fonts/wt014.ttf'));
$font->align('center');
$font->valign('middle');
});
}
return $img->response('jpg');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment