Skip to content

Instantly share code, notes, and snippets.

@lukespragg
Created October 4, 2014 06:00
Show Gist options
  • Save lukespragg/f41c91236abf3f978cd9 to your computer and use it in GitHub Desktop.
Save lukespragg/f41c91236abf3f978cd9 to your computer and use it in GitHub Desktop.
Unfinished meme generator that was actually meant for something else, but is just scrap now...
<?php
// Set the content-type
header ("Content-type: image/jpeg");
// Get text from URL
$text = $_GET['text'];
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
// Select the text font
$font = 'Oswald-Bold.ttf';
// Get font dimensions
$width = imagefontwidth($font) * strlen($string) ;
$height = imagefontheight($font) ;
// Grab original image
$im = imagecreatefromjpeg('grumpycat.jpg');
// Set new image dimensions
$x = imagesx($im) - $width;
$y = imagesy($im) - $height;
// Add text to new image
//imagefttext($im, 22, 0, $x, $y, $black, $font, $text);
//imagefttext($im, 20, 0, $x, $y, $white, $font, $text);
imagettftext($im, 20, 0, $x, $y, $black, $font, $text);
// Create new image
imagejpeg($im);
imagedestroy($im);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment