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.
Bash + ImageMagick:
|
|
Great!! :-) I wanted to write something like that. Unbeatable! All the esoteric languages will finally get their ass kicked today! :-)
–
Tomas
Feb 1 at 20:57
|
||
|
You can shave off one char by using single-quotes:
convert 'label:Hello world!' a.png
–
DigitalTrauma
Feb 1 at 22:05
|
||
|
|||
|
Also, if you make it
sh , you don't have to worry about ! and you make it even less esoteric.
–
sch
Feb 1 at 22:17
|
||
|
Frankly I don't think bash qualifies as a programming language here or that convert qualifies as an API. But in this case I'd throw
GNU hello in and bring this contraption down to 29 with: convert label:"`hello`" h.png
–
Arnaud Meuret
17 hours ago
|
Mathematica
|
|
C# - 168 charsC# is better! ;)
Saves as .png in the current directory. Rule abuse:
To mirror the Java answer, here is the indented code:
.net's API is a lot cleaner. |
|||||||||||||||||||||
|
HTML, 1494I know this won't win, but I didn't see this here before. Anchor link data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEIAAAANEAYAAABNymQSAAAABmJLR0T///////8JWPfcAAAACXBIWXMAAABIAAAASABGyWs+AAAACXZwQWcAAABCAAAADQDi7GgjAAADvElEQVRYw+1YPa9pTRReRIJKEPHdiEJBoVVIRCenpCJBfCQEDeI3qAh/QCIRUchp0KCUaISgROO7QMRHSGS9xX73u+85592Xe47uepqJZ9bMrFnzrJm1MfBfwAsvAADzM8HhcDgczv2Bj9r9KRgMBoPBeJz/2/DdODwaV+bjU77wN+AliBc+4OmCmE6n0+kUwGKxWCwWAKFQKBQKAfR6vV6vBygWi8Vi8efr7Ha73W4H4HK5XC4XgFQqlUqlADKZTCaTAbjdbrfbTdndg8FgMBgMANVqtVqtUnwikUgkEgBisVgsFgOQFRfZkny/3+/3+z/3i7zC8/l8Pp8HkEgkEomE3u/tdrvdbgEcDofD4aDirVar1Wo1QCaTyWQyj8f1iyAul8vlcqEco2tJu88IBoPBYBDA7/f7/X6A5XK5XC4ByuVyuVwGSCaTyWQSYDAYDAaD7wsiHo/H43EAFovFYrEAxuPxeDwGGI1Go9GI4skDvYe3t7e3tzeAer1er9cpvtlsNptNAC6Xy+VyAYbD4XA4pPwnea1Wq9Vqn+dXu91ut9sAjUaj0WjQ28VisVgsRgl0MplMJhOAXq/X6/UAOp1Op9OhH8/j8Xg83i8EfgKbzWaz2XgXdHYCgUAgEJBfLfQtkQFfx/+/V195uVwul8sRV6vVarX6ak8IEVGpVCqVyvv7IQKISBwsIpHBiBqNRqPRIBIHiJhOp9PpNGIqlUqlUoihUCgUCj3PL3Kf6/V6vV7fjwNxAyEuFovFYvHVnuTp4moymUwmE/Wb9f0c/b3iut1ut9sFIDZO9c9ms9lsBsDn8/l8/s/Xu1c932632+12fx6dTqfT6QD2+/1+vwcolUqlUgnAaDQajUYAs9lsNpsBstlsNpulMjISiUQikef7JRKJRCLRfb+ZTCaT+ZuH/95XCflU/odHM/9Ru3A4HA6HEaPRaDQaRbxer9frFbHVarVaLURCMFSm3MsAOt7j8Xg8HkSfz+fz+RDP5/P5fEY8nU6n0wnR6/V6vV6qfRSBQCAQCFAZXCgUCoUC4vF4PB6PiMRBISoUCoVCgUg8nc/zi27/dP3kPHa73W63IxKCRjwcDofDAZGoWejnrdVqtVrtl/mfLQiiyEG02Ww2m416QogiB/H9/f39/f3xDdPx5DpOp9PpdCISxRfVkjxp9ygqlUqlUqHWm8/n8/mc6ievWKvVarVa6ff/Xb/+VBCbzWaz2VCCIOOtUqlUKhViLpfL5XKPx5XxseOFvx2v/yFe+ICXIF74gH8A5ia8gOmPT18AAAASdEVYdGxhYmVsAEhlbGxvIHdvcmxkIbl+3UEAAAAASUVORK5CYII= Well apparently StackExchange will not allow data links so you must copy & paste it into your browser's address bar. @squeamish ossifrage got it down to 176: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC0AAAAHAQAAAAC0VvlnAAAAOklEQVR4nGLIv/57/+9rDGDqAkPOterN0YIM3KG712pdZcgI3bW26gZD9lUwlRNWW1wtAAAAAP//AwCcyhjs3+7tWQAAAABJRU5ErkJggg |
|||||||||||||||||||||
|
Linux shell + various utilities: 48 bytesMy first thought was to print
(28 bytes). Unfortunately, this fails the "and nothing else" requirement: it will generally show other things like window decorations. So instead, do it inside a full-screen Because The option to make it full-screen is The final code (48 bytes) is:
(where It works on my system: |
|||||||||
|
TI-BASIC, 22
White background. Use TI-Connect if you wish to retrieve it from the calculator. Resulting PNG: |
|||||||||||||||||||||
|
Java -
|
|
@user-12506 Yes, you can add
throws Exception to other methods, but the compiler enforce this rule: if you call a method that might throw a Throwable that is not a RuntimeException or an Error , then the compiler will require that you either catch or rethrow it, and this includes Exception . Further, although it is allowed, declaring throws Exception is a bad programming practice, because Exception is way too generic to be effectively handled in practice and rethrowing it just spread the bad practice to elsewhere.
–
Victor
yesterday
|
||
|
|||
|
@user-12506 Not everything is lower case in Java – classes are CamelCase just like in C#. Methods and fields are lowerCamelCase, and packages are alllowercase. Makes it somewhat easier to determine what a name refers to, in my opinion.
–
ntoskrnl
yesterday
|
||
|
@ntoskrnl Yeah, things can and do get a bit confusing when classes, methods and other things are camel case. But in the case of methods, it either begins with an Identifier that allows you to immediately recognize it as such, and if you're calling a method, you'll know right away that it's a method because it ends in (); or (somethinginHere);. In C#, most things are CamelCase (when I'm typing anyway), except for variables. and (most)
types . Either way, I'm going to have to get used to Java eventually. I've just started my first serious Android project.
–
user-12506
yesterday
|
||
|
@Timtech, at least for me ỻ was rendered as a square in the resulting image. Here in the browser (using firefox), it renders as a box containing 1EFB. I strongly suspect that this is not portable.
–
Victor
21 hours ago
|
Fortran 90, 104 bytes:Aight, game on. Fortran 90, using the g2 graphics library and implict typing, so "d" is a real:
Needs to have the g2 library installed, then just compile with
I'm pretty satisfied that I beat C#, C + Cairo, Java, Javascript, Python and Ruby! Example output:
|
|||||
|
Processing,
|
R,
|
|
|||
|
@SvenHohenstein sorry you are correct. I made a mistake while attempting shorter versions (they didn't work).
–
Tomas
2 days ago
|
||
|
dev.off() is unnecessary when you run this as a script instead of interactively.
–
Michael Hoffman
yesterday
|
||
|
C + Cairo:
|
|
You can save some chars by removing the type declaraction, i.e. the
void for main and the int for x , and possibly the char for **a (I'm not sure about the last one though). In C the type is default to be int if no type is specified, and you don't necessarily need to return a value for int main . This may produce compilation warning messages, but not errors and the program will still work.
–
ace
2 days ago
|
||
|
Shaved 17 bytes by removing the pointless
#define C(n,...) … . Also, main returns int , not void (and as of C99 it's not required to explicitly "return 0 " at the end of main ; the implementation implicitly adds it for you).
–
Quuxplusone
2 days ago
|
||
|
@ace Thank you! I had forgotten that types defaults to int i C. But it looks like it's all-or-nothing; you can't have some variables in the call signature use default types while others don't. So I just changed it to
main() and hardcode the filename to o instead of passing it to main. Now it's smaller than the Java version :)
–
Torkel Bjørnson
2 days ago
|
||
|
@Quuxplusone Thanks! Did not know that C99 add an implicit
return 0 to main if not already there. That was why I choose to (incorrectly) return void instead of int . Since you got rid of the vararg macro, C99 is not required to compile the code anymore. <rant>Which makes it more portable to compilers who's vendors has chosen to not implement C99 [read: Microsoft] :)</rant>
–
Torkel Bjørnson
2 days ago
|
You'll hopefully excuse my very loose interpretation of the above requirement. :) OSX bash:
|
|||||||||||||||||||||
|
BASH + RST + ImageMagick = 43 charsJust for fun, here's another (quite ugly) one:
Output: |
||||
|
PHP + gd2 - 86 bytes
The
Setting black to be transparent, and drawing with PHP + No Library - 790+ bytes
Ahh, that's better. No bloat; exactly as much as required, and not a chunk more. Or, URI encoded (which seems to be trending...) at 168 bytes:
Supposing we wanted to cut that down a bit more, let's say we replace the data string with this:
(and update the header to the new dimensions, 40x5), the output would be this 96 byte png: Which URI encodes to 150 bytes:
I think that's about as small as you're going to be able to get, and still be considered "human readable". |
|||||||||
|
Octave, 46Is this legal? Does not conform to the "nothing else" requirement... it has a coordinate system too.
|
|||
|
Javascript! 105
Outputs this size-optimized and pretty image: |
|||
|
Ruby, 138I'm golfing this hole with just my putter. (I chose a PNG library without fonts or a string draw method.)
Actual output is 34x4 pixels. (Enlarged below.) This plots very, very small and nearly transparent hand-drawn chars onto a very small transparent background. Image is saved to a PNG file named |
|||||||||
|
Data URI: 446Following Chloe's idea, applied some basic optimisation to the image. data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEEAAAALCAAAAAAFX7+TAAABBUlEQVQoz2P4Tylg+M8IohiRRUCIkC6E0sFlwhFBJo5kmPAdWSYmuTsgGa6y/3pMf/8yLYEJMcQwARXckmZi8YCawAAG//8L537ZxbEMaoKCwuvXCkogE2y0/nMyL1vC/BcmxKC6AqhAXurBc1kGkNUINzCBDIqFmsB84f//c8wgmcVs91j13d3U4EIMl0AKmM78/38GqJQXyQSWQ///H3sJMwGo7ALYhL/MQUq1wkK1cCEGsE+ZgSacAzKNkUxQ1/kygfEczBeKb18rKICDS4U58SUT8ye4EMQEBelHz+WAzEokE+6IM7HkI4ekLDgk/5cxnPrPK/4fLgQxARSSUdCQpBQAAFZKE8rQG60FAAAAAElFTkSuQmCC Might be able to hack it further, but then would not be a perfectly conformant PNG and some viewers may not display it correctly. |
|||||||||||||||||||||
|
Python with PIL 122 Chars
It could probably be much smaller but I haven't worked with PIL extensively and made this in 5 minutes. Output:
|
|||||||||||||
|
Ghostscript command line incantation, 84 (i.e. Postscript) :
Missing font message is intentional ;-). And proper (i.e. not hidden) name for our PNG file, too :-) |
|||
|
Python and Matplotlib -
|
|
|||
|
|||
|
Gnuplot Not really a true competitor, just for fun. (homepage)
|
|||||
|
Perl, 95:The whole command incantation:
Because of (reasonable) module defaults, it's 95 characters (or 92 if single letter file name allowed). On Windows we need to
i.e. 105 |
||||
|
Python, with
|
|
|||
|
|||
|
The question state that it should have a white or transparent background. I myself think that the rules should be relaxed to allow black too, but for now, it fails the spec at this point.
–
Victor
2 days ago
|
||
|
dot, 35Golfed Hans Zauber's solution:
|
|||||
|
Bash + DOT,
|
|
|||
|
I am not sure whether you should add the bash chars as well for compiling this dot script. This adds
dot -Tpng -op d , which is 15 chars.
–
Hans Zauber
2 days ago
|
||
|
You should count the command line options/argument if they are needed to make your program solve the task. Normally the dashes are not counted, so I think you only should add
Tnpg , op and d to the character count (+7), and specify how to run it in the answer itself.
–
daniero
2 days ago
|
||
|
It can be better if you don't
echo but instead write it in a file and run dot -Tpng on the file; it makes it 38, but I don't know if it counts...
–
Hans Zauber
2 days ago
|
||
|
PureBasic - 128 chars
Not the shortest here, but I have to support my favorite Basic language :) edit: just in case there is a complain about the black background, at 133 chars:
|
||||
|
Sage notebook, 22
|
|||||||||
|
EPL, 28
|
|||||
|
Matlab: 47 charactersI'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 |
|||
|
protected by Community♦ 4 hours ago
This question is protected to prevent "thanks!", "me too!", or spam answers by new users. To answer it, you must have earned at least 10 reputation on this site.
Hello World
orHello World!
? – Ryan Carlson 2 days ago