├── Anton.ttf ├── functions.php ├── index.php ├── readme.md ├── toystory-example.jpg └── toystory.jpg /Anton.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trepmal/meme-gen/0ff19339623f08ecf59aff8a973ca02700c28ed8/Anton.ttf -------------------------------------------------------------------------------- /functions.php: -------------------------------------------------------------------------------- 1 | $imwidth && $fit ) { 97 | 98 | // $sub = round( ( $box_width - $imwidth) * .08, 0, PHP_ROUND_HALF_DOWN ); 99 | // if ( $sub < 1 ) $sub = 1; 100 | $sub = 1; 101 | $fontsize = $fontsize - $sub; 102 | 103 | return memegen_font_size_guess( $fontsize, $imwidth, $font, $text, $fit ); 104 | 105 | } 106 | 107 | return compact( 'fontsize', 'box_width', 'box_height' ); 108 | 109 | } 110 | 111 | /** 112 | * Writes the given text with a border into the image using TrueType fonts. 113 | * http://www.johnciacia.com/2010/01/04/using-php-and-gd-to-add-border-to-text/ 114 | * @author John Ciacia 115 | * @param image An image resource 116 | * @param size The font size 117 | * @param angle The angle in degrees to rotate the text 118 | * @param x Upper left corner of the text 119 | * @param y Lower left corner of the text 120 | * @param textcolor This is the color of the main text 121 | * @param strokecolor This is the color of the text border 122 | * @param fontfile The path to the TrueType font you wish to use 123 | * @param text The text string in UTF-8 encoding 124 | * @param px Number of pixels the text border will be 125 | * @see http://us.php.net/manual/en/function.imagettftext.php 126 | */ 127 | function memegen_imagettfstroketext(&$image, $size, $angle, $x, $y, &$textcolor, &$strokecolor, $fontfile, $text, $px) { 128 | 129 | for($c1 = ($x-abs($px)); $c1 <= ($x+abs($px)); $c1++) 130 | for($c2 = ($y-abs($px)); $c2 <= ($y+abs($px)); $c2++) 131 | $bg = imagettftext($image, $size, $angle, $c1, $c2, $strokecolor, $fontfile, $text); 132 | 133 | return imagettftext($image, $size, $angle, $x, $y, $textcolor, $fontfile, $text); 134 | } 135 | 136 | /** 137 | * Sanitize 138 | * 139 | * Replace non-alphanumeric characters with hyphens 140 | * Reduce any multihyphens down to one 141 | * 142 | * @param string $input 143 | * @return string $input 144 | */ 145 | function memegen_sanitize( $input ) { 146 | $input = preg_replace( '/[^a-zA-Z0-9-_]/', '-', $input ); 147 | $input = preg_replace( '/--*/', '-', $input ); 148 | return $input; 149 | } 150 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 11 |
12 |

Top text:

13 |

Bottom text:

14 |

15 |
16 | 17 | $top_text, 29 | 'bottom_text' => $bottom_text, 30 | 'filename' => $filename, 31 | 'font' => dirname(__FILE__) .'/Anton.ttf', 32 | 'memebase' => dirname(__FILE__) .'/toystory.jpg', 33 | 'textsize' => 40, 34 | 'textfit' => true, 35 | 'padding' => 10, 36 | ); 37 | 38 | // create and output image 39 | memegen_build_image( $args ); 40 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | Meme Gen 2 | ======== 3 | 4 | ![bones](toystory-example.jpg) 5 | 6 | Font credit: http://www.google.com/fonts/specimen/Anton -------------------------------------------------------------------------------- /toystory-example.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trepmal/meme-gen/0ff19339623f08ecf59aff8a973ca02700c28ed8/toystory-example.jpg -------------------------------------------------------------------------------- /toystory.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trepmal/meme-gen/0ff19339623f08ecf59aff8a973ca02700c28ed8/toystory.jpg --------------------------------------------------------------------------------