Dank Meme Generator

29

6

I like making dank memes out of my own images. But all those so called "quick meme" sites just have too much code. I realized that the only way to make the dankest meme generator is to ask you guys at PPCG to golf one for me. So let me give you the low down on what you have to do.

Specs

  • Take an image as input as a file name, image object, etc. to make a meme out of.
  • Then take two strings for top text and bottom text (with no line breaks).
  • Render the text on the image in size 22pt Impact white font with 5px black outline (You can assume Impact is installed.
  • The text should be centered horizontally.
  • You can assume the text fits horizontally.
  • The respective texts should be 10px from the top and 8px from the bottom.
  • Then output the image by saving in a file, displaying, etc.
  • This is , so shortest code in bytes wins!

Happy Memeing!

Maltysen

Posted 2016-02-07T17:49:48.340

Reputation: 25 023

1Can we assume the Impact font is installed? – Downgoat – 2016-02-07T20:10:14.877

@Downgoat yeah. – Maltysen – 2016-02-07T21:50:08.957

9...advice animals? Is this what you call a dank meme? – nine – 2016-02-08T06:38:36.313

5These memes aren't dank at all. This is like, entry-level memeology. – Pyritie – 2016-02-08T11:09:35.730

2@Pyritie Not everyone should be allowed to wield meme magic just yet. – hownowbrowncow – 2016-02-08T14:26:58.013

Can we assume we have impact font including the black border installed? – Eumel – 2016-02-08T15:43:26.957

Answers

13

HTML/JS/CSS, 341 329 300 bytes

<input onblur=i.src=this.value><table><td><img id=i><p style=top:10px contenteditable><p style=bottom:8px contenteditable></p><style>td{position:relative}p{position:absolute;margin:0;width:100%;text-align:center;font:22px Impact;color:#fff;text-shadow:0 0 5px #000,0 0 5px #000,0 0 5px #000,0 0 5px #000}

To use: First paste the desired image URL into the provided input box, then tab to the top text and type in the desired text, then tab to the bottom text and type in the desired text.

Edit: Saved 12 bytes thanks to @Downgoat. Saved a further 29 bytes thanks to @dev-null.

td {
  position: relative;
}
div {
  position: absolute;
  left: 0;
  right: 0;
  text-align: center;
  font: 22px "Impact";
  color: #fff;
  text-shadow: 0 0 5px #000, 0 0 5px #000, 0 0 5px #000, 0 0 5px #000;
}
<input onchange="i.src=this.value">
<table>
  <td>
    <img id=i>
    <div style="top: 10px;" contenteditable></div>
    <div style="bottom: 8px;" contenteditable></div>

Neil

Posted 2016-02-07T17:49:48.340

Reputation: 95 035

You can probably remove a lot of the quotes in the html. You can also remove the ></div> at the end – Downgoat – 2016-02-07T19:03:50.147

You can change your div's to p tags and add margin:0; should save a few bytes – andlrc – 2016-02-07T19:54:19.510

@dev-null After Downgoat's suggestion it now costs me a byte rather than saving me a byte. – Neil – 2016-02-07T19:58:07.603

@Neil This is correct, but if you also move the style tag to the end you will be able to remove the </style> – andlrc – 2016-02-07T19:58:48.933

@dev-null Well, I can get rid of the first </p> at least (the second is needed to prevent you from pressing Ctrl+A, Del to delete the style element). – Neil – 2016-02-07T20:11:46.103

@Neil I guess you can change left:0;right:0 to width:100% and onchange to onblur – andlrc – 2016-02-07T20:24:44.063

When I tested it you can swap the 0 0 5px #000, 0 0 5px #000, 0 0 5px #000, 0 0 5px #000 for "0 0 5px #000,"*5 – Rɪᴋᴇʀ – 2016-02-07T21:28:21.257

@Neil If you only targer webkit browsers then you can use: -webkit-text-stroke:5px#000 expect it seems to be inline and not outline. – andlrc – 2016-02-07T22:50:58.403

@dev-null Fortunately I don't use webkit/blink browsers. – Neil – 2016-02-07T23:30:42.363

@Neil Now that I think about it, cant you use window.MY_ID.src=... and <img id=MY_ID>, eg: I.src, <img id=I> – andlrc – 2016-02-08T22:37:38.760

12

Jelly, 141 bytes

⁴;@€“¢ÇẎȧsẊỊ>ɼẈAẋ®ŀȮĠq⁼ṫṁḢĠZỴċƊ£²ÆṗÑḊ°>oÆl{(¢ɗpḅ]µṖÑb¹ƁịṾ¦Ç\ṭO4»“1kịXḥɗ"Ụɦḷ©Ƈ&Ṭ19“£ŀ³³.Ṗ<ṂqṬỵ.ṣȦƇƈ2ƭḂXƊ»ż³;“ßƑ_!]²Rȧ⁵⁴°ṁD⁽a{⁼!z¿ıṾƇDẇḤḶṡÇẈg»;

Try it online!

Takes command line arguments as in the example, and returns a HTML file. The result looks like this in Chrome:

enter image description here

Lynn

Posted 2016-02-07T17:49:48.340

Reputation: 55 648

2Nice answer, but I'm not counting this as an image. Its not really graphical output. – Maltysen – 2016-02-07T21:37:41.290

Upgoated, nice golf. – Ave – 2016-02-07T22:07:38.643

Guess @Downgoat needs a sibling named Upgoat now. – Paul Picard – 2016-02-08T10:40:18.477

5

bash+imagemagick+gs 690 575 456 440 bytes

See earlier revisions for "ungolfed" code.

#!/bin/bash
d=`identify $1|cut -d' ' -f3`
x=`echo $d|cut -d'x' -f1`
y=`echo $d|cut -d'x' -f2`
convert $1 $1.eps
gs -g"$d" -o $1.png -sDEVICE=png48 -c "
/s/showpage load def/showpage{}def($1.eps)run
matrix defaultmatrix setmatrix/Helvetica-Bold 22
selectfont/c{dup stringwidth pop neg 2 div 0 rmoveto dup 
gsave 1 setgray show grestore 0 setgray false charpath stroke}def
$x 2 div $y 42 sub moveto($2)c $x 2 div 8 moveto($3)c s"
echo :$1.png

eg.

./meme.sh Superman1.jpg "I AM CORNHOLIO" "Are you threatening me??!"
GPL Ghostscript 9.15 (2014-09-22)
Copyright (C) 2014 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Loading NimbusRomNo9L-Regu font from /usr/share/ghostscript/9.15/Resource/Font/NimbusRomNo9L-Regu... 4186304 2700982 3995248 2685490 2 done.
Loading NimbusSanL-Bold font from /usr/share/ghostscript/9.15/Resource/Font/NimbusSanL-Bold... 4203248 2760390 3833712 2536130 1 done.
:Superman1.jpg.png

Superman likes Beavis

luser droog

Posted 2016-02-07T17:49:48.340

Reputation: 4 535

4That's not impact font! – Pyritie – 2016-02-08T11:10:36.680

True. It appears I don't have it installed. fc-list can't find it. – luser droog – 2016-02-10T02:29:48.497

I could specify Impact anyway, but then it'd render with Courier. – luser droog – 2016-03-07T18:49:19.403