# Make a PNG image with “Hello World!” with programming APIs, in the shortest code possible [closed]

So, I want you to make a PNG image that says "Hello world!" and nothing else on a distinguishable background using only an image making API (eg ImageMagick) and return the image. Fewest characters win, as usual. Oh, and you can use any color text.

• Does it have to output Hello World or Hello World!? – The Guy with The Hat Feb 2 '14 at 12:55
• @ryan Hello World! is the right one. – figgycity50 Feb 2 '14 at 14:52
• A lot of answers could save one character by replacing the double 'l' in 'hello' with the medieval Welsh ligatures 'Ỻ' or 'ỻ': once the chars have been transformed to pixels it shouldn't matter what their origin was as long as people still perceive 'heỻo world!' as 'hello world!'. – timxyz Feb 3 '14 at 11:27
• @poldie Your browser changes PNG based on how the pixels got in there? – Christopher Creutzig Feb 4 '14 at 2:22
• @timxyz For me, ỻ is rendered as a box containing 1EFB. I tried to use it in my program anyway, and the result was a square. So, this is probably not very portable. – Victor Stafusa Feb 4 '14 at 5:24

## Matlab: 47 characters

I'm not sure what exactly an Image making API is. This uses a figure/graph making API, which is arguably an image.

text(1,1,'Hello World!');axis off;print -dpng f

Chloe used a Base64 encoded approach with 1494 characters, however you can easily reduce the size:

# Anchor link - 166 chars

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAD8AAAAFAQAAAADaxQm5AAAAM0lEQVQIW2Mo0a+w3iKQz8NQ+r56r+71/BIGlnwg40J+GUhkz9lr78sYShQ57O6IKfIAAJypEkNzAX3zAAAAAElFTkSuQmCC

Paste this into your browser

## Bash, using Google's chart API: 92 characters

curl http://chart.googleapis.com/chart?chst=d_text_outline&chld=|9|h|||Hello+world! > h.png


## Further optimization: 33 characters

curl http://goo.gl/a8ntA4 > h.png


• Don't know if the "further optimization" counts, as it caches data in the cloud in the form of a shortened URL service, which allows one to make a script of arbitrary size and complexity to solve this problem that never requires more than 33 characters to represent. – Adam Davis Feb 3 '14 at 18:07
• Yeah, I wouldn't think using a URL shortener is very kosher for this. :-) – Chris Jester-Young Feb 3 '14 at 18:21
• I have a shorter solution: cat image.png > h.png where image.png is the result of curl http://goo.gl/a8ntA4 > image.png!!! – Farid Nouri Neshat Feb 4 '14 at 12:32

## EPL, 28

0,0,0,1,1,1,N,"Hello World!"

• Can you show the output? – The Guy with The Hat Feb 4 '14 at 13:22

# MATLAB, 41 chars

@gerrit posted a MATLAB solution as well, but since I don't have enough rep to comment, I'll post mine too. (The output is the same as his, so I don't want to take up more space with the resulting PNG).

axis off,title 'Hello world!',print -dpng


# Groovy, 133

Not going to win any points for size here as it's just an abbreviated Java.

No color setting:

i=new java.awt.image.BufferedImage(75,30,2);i.graphics.drawString('Hello World',5,20);javax.imageio.ImageIO.write(i,'PNG',System.out)


With setting color (164):

i=new java.awt.image.BufferedImage(75,30,2);g=i.graphics;g.color=java.awt.Color.RED;g.drawString('Hello World',5,20);javax.imageio.ImageIO.write(i,'PNG',System.out)


### Formatted:

i = new java.awt.image.BufferedImage(75,30,2)
g = i.graphics
g.color = java.awt.Color.RED
g.drawString('Hello World',5,20)
javax.imageio.ImageIO.write(i,'PNG',System.out)


Here is a cool trick, only 37 chars: placehold.it/png/99&text=Hello+world! (+7 chars for the protocol).

This generates a 239 bytes long png image with 99px of width and height.

I know it's not programming, but this is a website that generates placeholder images.

You should visit http://placehold.it.

• similar to codegolf.stackexchange.com/a/20019 – gnibbler Feb 5 '14 at 13:23
• Similar, but WAAAAAAAAAAAAY shorter and a totally different website. dummyimage.com is bigger than placehold.it – Ismael Miguel Feb 5 '14 at 17:29
• cambelt.co/300/Hello+world! and fakeimg.pl/99/?text=Hello+world! are even shorter. Should I post two more answers with them? No. Multiple answers using the same language and principles are boring. If you have improvement for existing answer, please post it as comment. – manatwork Feb 6 '14 at 8:17
• If you didn't downvoted, perhaps I could get enough reputation to make comments on other posts! – Ismael Miguel Feb 6 '14 at 9:34
• Ah, that is indeed a good reason for not posting comment. Revoked the vote. (I had to make and edit to your post to be able to change my vote.) – manatwork Feb 6 '14 at 10:23

Groovy, 151 (or 202 with a black text)

a rewrite of the proposed Java version. Resulting image is with white text on a transparent background. Add 50 chars to have black text !

import java.awt.image.BufferedImage as B
B b=new B(80,9,2)
b.graphics.drawString("Hello world!",5,9)
javax.imageio.ImageIO.write(b,"png",new File("p"))


The version with black text:

import java.awt.*
import java.awt.image.BufferedImage as B
B b=new B(80,9,2)
b.graphics.with {setColor(new Color(0)); drawString("Hello world!",5,9); }
javax.imageio.ImageIO.write(b,"png",new File("p"))


• Could you please post the resulted image? By the way, are all those spaces necessary in the code? – manatwork Feb 4 '14 at 10:44
• image posted and useless spaces removed – Guillaume Feb 4 '14 at 12:53

# Ruby 192 chars:

I use RMagick RVG (Ruby Vector Graphics).

require 'rvg/rvg';include Magick;RVG::dpi = 72;RVG.new(1.5.in, 1.5.in){|canvas|canvas.background_fill = '#C0C0C0';canvas.text(10, 100){|title|;title.tspan("Hello World!")}}.draw.write('hw.png')


output:

# Shell + Graphviz (55)

echo 'graph{a[label="Hello World!"]}'|dot -Tpng>h.png

• @Timtech I don't know what shell you're using, but the ! works fine for me in bash and doesn't need to be escaped. – grim Feb 7 '14 at 22:21
• That's really weird - all I did was add four spaces in front of your answer to format is correctly. I see what you mean, though O_o I don't remember doing that at all :S – Timtech Feb 8 '14 at 0:19
• alright, well I'm going to remove it then :) Thanks for getting the code formatting, not sure how I missed it.. – grim Feb 9 '14 at 6:42
• It's fine - I usually do that kind of stuff whenever I see it :) – Timtech Feb 9 '14 at 16:37
• You can get away with echo 'graph{"Hello World!"}'|dot -Tpng>a.png, which is 44 characters... – Martin Broadhurst Jul 11 '15 at 15:23

# Mouse: 0 chars

"right click" > "save image as"

Result:

• Where is the “with programming APIs” part here? – manatwork Feb 4 '14 at 10:41