Skip to content

Instantly share code, notes, and snippets.

@n3omaster
Created June 19, 2022 16:24
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 n3omaster/3c4df21b26a403c8b9a8af0e81f22cc3 to your computer and use it in GitHub Desktop.
Save n3omaster/3c4df21b26a403c8b9a8af0e81f22cc3 to your computer and use it in GitHub Desktop.
Cover generator for the QvaPay P2P offers
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use Intervention\Image\ImageManagerStatic as Image;
class CoverController extends Controller
{
/**
* Test Cover P2P generation
*/
public static function make_cover($avatar1 = 'android-chrome-512x512.png', $avatar2 = 'android-chrome-512x512.png', $text = "QvaPay")
{
// Create the image 1 cover
$avatar1 = self::avatar($avatar1);
// Create the image 2 cover
$avatar2 = self::avatar($avatar2);
// bind into image
$background = Image::make('qvapay-cover-social.png');
// Left circle
$background->circle(400, 250, 250, function ($draw) {
$draw->background('#fff');
});
// Right circle
$background->circle(400, 950, 250, function ($draw) {
$draw->background('#fff');
});
// Insert Image (resize first to 300x300 and apply a mask with a circle shape)
$background->insert(
// Avatar 1
$avatar1,
'top-left',
55,
55
);
// Insert Image (resize first to 300x300 and apply a mask with a circle shape)
$background->insert(
// Avatar 2
$avatar2,
'top-left',
755,
55
);
// Add text
$background->text($text, 600, 500, function ($font) {
$font->file('fonts/nunito.ttf');
$font->size(48);
$font->color('#fff');
$font->align('center');
$font->valign('center');
});
// Response
// return $background->response('jpg');
return $background;
}
/**
* Avatar creation
*/
private static function avatar($img_path = 'android-chrome-512x512.png')
{
$avatar = Image::make($img_path);
$avatar->fit(400);
$canvas = Image::canvas(400, 400);
$canvas->circle(390, 195, 195, function ($draw) {
$draw->background('#000000');
});
$avatar->mask($canvas, true);
// Response with the image or you can as well do whatever you like with it.
return $avatar;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment