Make a transparent 448*448 image

This is a simple challenge.

The task is to write code that outputs a 448*448 square image with 100% transparency. The output should follow the standard image rules.

• What's to stop people from submitting a 0-byte answer which "outputs" a transparent (invisible) image to the screen? – 12Me21 Mar 12 '19 at 20:56
• @12Me21 Would that be 448*448? – Anush Mar 13 '19 at 9:21
• Is this a parody of (or at least inspired by) a closed question on stackoverflow? – Foon Mar 13 '19 at 20:38
• What's special about 448 px? – dan04 Mar 13 '19 at 22:12
• @Foon Definitely not a parody but certainly I was interested enough to ask on SO before realising it would be much more fun here. – Anush Mar 13 '19 at 22:18

Imagemagick in some shell, 35

convert -size 448x448 xc:none a.png


Is this allowed?

• Bash, I guess? That's what I used when I tested it. Any POSIX shell should work? – vityavv Mar 13 '19 at 2:20
• Works also in Windows (if ImageMagick is in the PATH before \windows\system32). – CL. Mar 13 '19 at 7:48
• On Windows ImageMagick is not being shipped with convert tool, because the name clashes with system utility. You run magick convert ...  instead. – n0rd Mar 14 '19 at 6:05
• @SztupY the convert is part of ImageMagick, so calling it its own language would not work. – vityavv Mar 14 '19 at 14:35
• it's an own command. You can just say the language you are using is ImageMagick Convert. Might be worth opening a meta about it though – SztupY Mar 14 '19 at 14:52

APL (Dyalog Unicode), 11 bytesSBCS

Full program. Prints 448-by-448-by-4 array representing a 448-by-448 rgba image.

448 448 4⍴0


Try it online!

⍴ is reshape

• I don't know APL at all, but I guess it doesn't have a duplicate to golf the 448 448? – Kevin Cruijssen Mar 13 '19 at 8:24
• 448*448=200704, so cant you replace the space separated 448 448 with 200704, saving 1 byte? – NaCl Mar 13 '19 at 9:35
• @NaCl In that case why not just multiply that by 4 and have 802832p0 as the answer? – John Hamilton Mar 13 '19 at 11:25
• @NaCl Because that's not one of the valid image formats per default rules. – Adám Mar 13 '19 at 12:32
• @JohnHamilton For the same reason as my answer to NaCl. – Adám Mar 13 '19 at 12:32

Go, 70

import i"image";func a()i.Image{return i.NewRGBA(i.Rect(0,0,448,448))}


Never seen a golf in Go before. Defines a function called a that outputs the image

• Call it a Go-lf. – Skyler Mar 14 '19 at 19:24

JavaScript (ES6), 74 69 bytes

f=
(_=document.createElementcanvas)=>_.toDataURL(_.height=_.width=448)
;document.write(f());

Returns a PNG image encoded as a data: URL suitable e.g. for setting as the src of an HTMLImageElement. Edit: Saved 3 bytes thanks to @Shaggy and a further 2 bytes thanks to @Arnauld.

• – Shaggy Mar 12 '19 at 23:30
• document.createElementcanvas  should work, saving 2 more bytes. – Arnauld Mar 12 '19 at 23:31
• If createelement is valid would seeing document.body and using the fact an id becomes a variable be valid? Also stack snippet pls – ASCII-only Mar 12 '19 at 23:37
• Could you add something like d=document at the top and replace document with d? Should save ~5 characters. – Luke Mar 14 '19 at 14:07
• @Luke The document.write is just part of the stack snippet, not part of the function, so it doesn't count anyway. – Neil Mar 14 '19 at 14:21

Java 8, 23 (or 20) bytes

v->new int[448][448][4]


Returns a 3D array of 448x448x4 0s.

Try it online.

Explanation:

v->  // Method with empty unused parameter and 3D integer-array as return-type
new int[448][448][4]
// Create a 3D array of dimensions 448 by 448 by 4 (filled with 0s by default)


v->new int[448][448]


Returns a 448x448 matrix of 0s.

In Java, RGBA values can be represented by an integer. The hexadecimal 0x00000000 would represent 00 for red, green, blue, and alpha respectively. And 0x00000000 is equal to the integer 0.

Try it online.

• Ah ah ah, love it :-) Doesn't it work with simply v->new int[448][448]? Because a color can be represented with an integer (RGBA) in Java. – Olivier Grégoire Mar 13 '19 at 9:27
• @OlivierGrégoire No, I need the four 0s per 448x448 pixel for the RBGA values. EDIT: Hmm.. is an integer 0-255 a valid RBGA value? I know it's a valid RGB value, but also RGBA? I almost never use images in Java, so not too familiar with them. I simply based my 4 inner 0s on other answers. – Kevin Cruijssen Mar 13 '19 at 9:31
• Yes, four 0s as (in hexadecimal) 0x00000000 that fit on an int. The first 2 hex digits are the Alpha, the next 2 are the red, the next 2 are the green, the final 2 are the blue.So you only need an integer. See BufferedImage.TYPE_INT_ARGB. You have 4 values, summarized as one integer. And 0x00000000 is equal to 0. – Olivier Grégoire Mar 13 '19 at 9:40
• I think this is the first time in ~2 years here I've seen Java actually be competitive! – Shaggy Mar 15 '19 at 22:55
• @Shaggy With these golfing languages around it's still not that competitive.. Besides, I had a few other semi-competitive Java answers in the past, like this one, or this one that was winning until the Bash showed up (and R golfed its answer). – Kevin Cruijssen Mar 16 '19 at 10:47

Java 8

Saving the image to a file with path s, 101 bytes

s->javax.imageio.ImageIO.write(new java.awt.image.BufferedImage(448,448,2),"png",new java.io.File(s))


Try it online... somehow

Returning the BufferedImage, 46 bytes

v->new java.awt.image.BufferedImage(448,448,2)


Saving the image to the file f, 83 bytes

f->javax.imageio.ImageIO.write(new java.awt.image.BufferedImage(448,448,2),"png",f)


Dumping PNG to STDOUT, 92 bytes (thanks ASCII-only!)

v->javax.imageio.ImageIO.write(new java.awt.image.BufferedImage(448,448,2),"png",System.out)


Try it online!
Thanks to Kevin for saving a byte for the second and fourth solutions!

• Do you mean empty or transparent? – Anush Mar 12 '19 at 20:43
• Just write to stdout – ASCII-only Mar 12 '19 at 23:39
• @ASCII-only So, write an empty (filled with zeros) 448*448*4 array to stdout? Anyways I like the idea of creating an actual PNG file. – Benjamin Urquhart Mar 13 '19 at 0:45
• You can golf the ()-> in two of your answers to v->, since it's allowed to have an empty unused input (for which I personally use Void). Your last TIO would then be this instead. – Kevin Cruijssen Mar 13 '19 at 10:58
• @NahuelFouilleul because I want to output an actual image and not a pixel by pixel representation of one – Benjamin Urquhart Mar 13 '19 at 14:01

05AB1E, 1210 9 bytes

448LDδ4Å0


Try it online.

or alternatively:

¾4Ž1ÂDиии


Try it online.

-2 bytes thanks to @Emigna.
-1 byte thanks to @Adnan.

Outputs a 448x448x4 3D list of 0s.

Explanation:

448LD      # Push a list in the range [1,448], and duplicate it
δ     # Outer product; apply the following double-vectorized:
4Å0  #  Push a list of 4 0s: [0,0,0,0]
# (and output the result implicitly)

Ž1ÂD     # Push compressed integer 448, and duplicate it
и    # Create a list of 448 times 448
4     и   # Transform it into a list of 448 times 448 times 4
¾       и  # Transform it into a list of 448 times 448 times 4 times 0
# (and output the result implicitly)


See this 05AB1E answer of mine (section How to compress large integers?) to understand why Ž1Â is 448.

Processing, 66 bytes

PGraphics g=createGraphics(448,448);g.beginDraw();g.save("a.png");


Python 2.7, 17 Bytes (22 With Print)

[[[0]*4]*488]*488


With Print:

print[[[0]*4]*488]*488


As variable:

x=[[[0]*4]*488]*488


As an array of RGBA is allowed, that is what I have created above, defaulting to all 0's - meaning black, but totally transparent.

Try it online!

• Again, with this one, just multiply manually and you get [0]*802816 that should also work. – John Hamilton Mar 13 '19 at 11:26
• @JohnHamilton Correct me if I'm wrong, but I do believe that it would have to be a 3D array (An array of rows of pixels) i.e. array[pixel x coord][pixel y coord][r/g/b/a] – Snaddyvitch Dispenser Mar 13 '19 at 12:27
• Not quite as concise but here is an alternative that gets the zeros into a numpy array... np.zeros([4]+[448]*2) – P. Hopkinson Mar 14 '19 at 0:53

Jelly, 8 bytes

448ṁ4¬¥þ


A niladic Link which yields a 448 by 448 RGBA array of transparent black pixels.

Try it online!

How?

448ṁ4¬¥þ - Link: no arguments
448      - 448
þ - outer-product with: -- i.e. [[f(x,y) for y in [1..448]] for x in [1..448]]
¥  -   last two links as a dyad:
ṁ4    -     mould like [1,2,3,4]  -- e.g. x=7 -> [7,7,7,7]
¬   -     logical NOT                       -> [0,0,0,0]


HTML, 25 bytes

Is this valid?

<svg height=448 width=448


Test it (background applied with CSS so you can "see" it)

• I don't believe that this is valid, as writting <svg height=448 width=448 into an html file and opening it produces an empty <body>. However, with the penality of 1 byte, if you write <svg height=448 width=448>, it produces a <body> with an empty SVG image. – Ismael Miguel Mar 15 '19 at 10:43
• @IsmaelMiguel, we define languages by their interpreter rather than their (intended) implementation. That an interpreter exists (in this case CodePen) that allows us to omit the closing > means that this is, indeed, valid, as far as the markup goes. – Shaggy Mar 15 '19 at 11:01
• Codepen adds additional HTML code to make it work. It adds a <!DOCTYPE html>, <html>, <head>, <style>, <script> and everything goes to the <body>. Some of the additional code is required to produce the desired output. You can see that the resulting code is parsed as <svg height="448" width="448" < body></svg>, because it writes <svg height=448 width=448 </body> in the iframe. As such, I still believe it isn't valid. – Ismael Miguel Mar 15 '19 at 11:10

C# (Visual C# Interactive Compiler), 21 bytes

_=>new int[448,448,4]


Try it online!

Rust - 206201 168 bytes

use std::{io::Write,fs::File};fn main(){let mut v=vec![0,0,2,0,0,0,0,0,0,0,0,0,192,1,192,1,32,0];v.extend(vec![0u8;802816]);File::create("o.tga").unwrap().write(&v);}


This writes an actual, readable o.tga file, without any libraries or builtin functions, using the TGA binary format per http://paulbourke.net/dataformats/tga/ , by hard coding the width and height into the binary file header.

-5 bytes shorten filename, fix img size, @ASCII-only

• does it need to be printed to a file though :P – ASCII-only Mar 13 '19 at 1:04
• does it even need to be 2 dimensional? I could just say [0;444*444*4]; and say i created a 444x444 transparent image. im making it interesting. – don bright Mar 13 '19 at 3:24
• well also a would work as file name would it not. btw it's 448*448 not 444*444 so this is invalid – ASCII-only Mar 13 '19 at 3:29
• oops, ha ha thanks – don bright Mar 13 '19 at 3:34
• to make it even more interesting, run length encode it :P (image data should be [255,0,0,0,0] 6272 times ([0,0,0,0] 128 times, repeated 6272 times). image type would then be 10 not 2. even better, colormap for shorter run length encoding (0,0,0,0 -> 0) – ASCII-only Mar 13 '19 at 3:35

C# (Visual C# Interactive Compiler), 48 bytes

_=>(Enumerable.Repeat((0,0,0,0),200704),448,448)


Apparently outputting [1D array of pixels, width, height] is ok, so this outputs a tuple of (IEnumerable of pixels, width, height).

Try it online!

C# (Visual C# Interactive Compiler), 58 bytes

_=>Enumerable.Repeat(Enumerable.Repeat((0,0,0,0),448),448)


The original matrix returning answer.

Since the image IO rules allow output as a matrix of RGB values, this submission outputs a matrix of RGBA values, represented by tuples with four values, all being 0.

Try it online!

PHP, 192 bytes

Sadly, PHP kinda sucks in that aspect because it requires a whole lot of code. But then again, where doesn't PHP suck.

$i=imagecreatetruecolor(448,448);imagesavealpha($i,true);$b=imagecolorallocatealpha($i,0,0,0,127);imagefill($i,0,0,$b);imagepng($i,'i.png');header('Content-type: image/png');readfile('i.png');  Ungolfed: $i=imagecreatetruecolor(448,448);         // Create a new image with a set width
imagesavealpha($i,true); // Tell PHP to save alphachannels on that image$b=imagecolorallocatealpha($i,0,0,0,127); // set the actual transparency values imagefill($i,0,0,$b); // Fill the image with the color saved above imagepng($i,'i.png');                     // Save the file as PNG
header('Content-type: image/png');        // Set the content type for the browser
readfile('i.png');                        // Read the file and output it


Obviously, if you just want to create it without outputting it, you can omit the header() and readfile() commands. Still, it's idiotically long.

• on the positive side, this is one of the most 'readable' answers that indicates exactly what its doing – don bright Mar 15 '19 at 4:37
• @donbright Not really the point of codegolfing tho. ;P However, there is no other way to do this in PHP I guess, unless I just echo some HTML. – Realitätsverlust Mar 15 '19 at 10:05
• @YUNOWORK According to the rules, you can export an array. You can use '<?php return '.var_export(array_fill(0,952576,0),1).';'; to export the array in an executable way. you can do php -f image.php > array.php, and somewhere else you can do $array = include('array.php'); to have an usable array again. But I don't know if it is valid, so, I'm giving it to you to add as an alternative. Or even a <?=json_encode(array_fill(0,952576,0));. – Ismael Miguel Mar 15 '19 at 15:18 • By the way, true can be replaced with 1, to save 3 bytes. Reading the documentation of imagepng(), you can just do header('Content-type: image/png');imagepng($i);. I believe you can also replace $b=imagecolorallocatealpha($i,0,0,0,127);imagefill($i,0,0,$b); with imagefill($i,0,0,imagecolorallocatealpha($i,0,0,0,127)); but dont quote me on that. – Ismael Miguel Mar 15 '19 at 16:29
• I just tested and <? imagecolorallocatealpha($i=imagecreate(448,448),0,0,0,127);header('Content-type: image/png');imagepng($i); produces a transparent image (109 bytes). Automatically sends the image to the browser/standard output and everything. – Ismael Miguel Mar 15 '19 at 17:44

Python 3.7 - PIL Imported, 30 bytes

Image.new("LA",[448]*2).show()


This requires an import but has the benefit of creating and displaying an actual image file rather than an abstract empty array.

Explanation:

from PIL import Image
Image.new(    // create a new image
mode="LA"     // select LA colour mode, this is grey-scale plus an alpha channel
size=[448]*2  // size argument needs to be a 2D tuple, [448*2] is a better golf shot than (448,448)
color=0       // populates the image with the specified colour, helpfully preset to transparent
).show()      // display the image object


Image.show() will open the image in your default image program. In my case this opens a temporary bitmap file in Windows Photo Viewer but results may vary. Arguably this is cheating since the bitmap representation contains no transparency

Variations...

Image.new("LA",[448]*2)                 // 24 bytes but doesn't open image
Image.new("LA",[448]*2).show()          // 30 bytes, shows you a bitmap
Image.new("LA",[448]*2).save("x.png")   // 37 bytes, saves image to disk

• If you do not count your import, you should state your language as Python 3.7 -- PIL imported or something similar. Furthermore, in your explanation you capitalize Import. – Jonathan Frech Mar 14 '19 at 0:53
• Thanks, corrected. Should I give my answer as 24 bytes, 30 or 37? – P. Hopkinson Mar 14 '19 at 0:57
• The byte count depends on the language you use. As of now, your submission takes 30 bytes in the language Python 3 with PIL imported. If you wrote in Python 3, it would most likely be longer. Of course, if you use the language Python 3 with the entire PIL namespace imported, your answer would be new("LA",[448]*2).show(), 26 bytes. – Jonathan Frech Mar 14 '19 at 2:11
• Thanks so much for submitting code I can actually run and which produces output I can test! – Anush Mar 14 '19 at 10:42

MATLAB, 31 bytes

imwrite(nan(448),'.png','tr',1)


Creates a 448 x 448 matrix of NaN values, and then uses imwrite to save them to a PNG file named '.png' and sets the transparency to 1, making it transparent. The 'Transparency' parameter name is able to be abbreviated to 'tr' as MATLAB allows for partial string matching of parameter names as long as the shortened version is unique among available parameters.

• wait, why 443?? – ASCII-only Mar 14 '19 at 12:58
• @ASCII-only Fat fingers :) – Suever Mar 14 '19 at 12:59
• O_o that was an insanely quick reply – ASCII-only Mar 14 '19 at 12:59

dzaima/APL + APLP5, 18 16 bytes

{P5.img⍴∘0,⍨448}


Function that outputs an image object that can be drawn to the screen (for no effect) or converted back to pixel values.

-2 thanks to ngn!

• would this work? {P5.img⍴∘0,⍨448} – ngn Mar 15 '19 at 11:18
• @ngn it indeed would, thanks! – dzaima Mar 15 '19 at 11:22

Jelly, 10 9 bytes

x4Wẋ448Ɗ⁺


Try it online!

Outputs a 448x448x4 array

Thanks to @JonathanAllan for saving a byte.

• 2¡ can be ⁺ – Jonathan Allan Mar 12 '19 at 21:33

Red, 33 bytes

a: make image![448x448 0.0.0.255]


Opacity defaults to fully opaque(0)

This is how to use it /a full program/ :

Red [ ]
a: make image! [ 448x448 0.0.0.255 ]
view [ image a ]


MathGolf, 10 bytes

º4♦7*_ß{.a


Try it online!

Explanation

º            push [0]
4           push 4
♦7*        push 64*7=448
_       duplicate TOS
ß      wrap last three elements in array (stack is now [[0], [4, 448, 448]])
{     foreach in [4, 448, 448]
.    repeat TOS x times
a   wrap TOS in array


This method saves 1 byte compared to the "standard" ♦7*_4º*a*a*

JavaScript (Node.js), 39 bytes

_=>[w=448,w,Array(w*w).fill([0,0,0,0])]


Apparently outputting [height, width, 1d array of RGBA values] is ok.

Try it online!

-3 bytes thanks to @Arnauld

• invalid... it's a list of strings – ASCII-only Mar 13 '19 at 2:20
• Also you can output [1D array of pixels, width, height] – ASCII-only Mar 13 '19 at 2:21
• @ASCII-only Fixed now – Embodiment of Ignorance Mar 13 '19 at 2:24
• 41 bytes or 39 bytes if we can output [width, height, array]. – Arnauld Mar 13 '19 at 8:09

SmileBASIC, 27 bytes

DIM A[448,448]SAVE"DAT:I",A


Saves a 2-dimensional 448x448 array filled with 0s to a file named DAT:I (Which is shorter than defining a function that returns the array, somehow)

The standard formats (used by all graphics functions) for colors in SmileBASIC are 32 bit ARGB and 16 bit 5551 RGBA, and 0 is transparent in both of them.

• What makes this transparent instead of black? – pipe Mar 13 '19 at 13:38
• The colors are in 4 byte ARGB format (commonly used in Smilebasic), so 0x00000000 is Alpha = 0, Red = 0, Green = 0, Blue = 0. Black would be 0xFF000000. – 12Me21 Mar 13 '19 at 15:38
• kudos to SmileBasic for using a RAW image format lol – don bright Mar 14 '19 at 1:57
• I would complain on technicality that this isn't an image format since it isn't GRP but I'll let it go since the actual data being stored is the same. – snail_ Mar 14 '19 at 7:02
• @snail_ It's just outputting a matrix of pixels, not using a specific image format. – 12Me21 Mar 14 '19 at 8:23

ScPL for iOS Shortcuts, 98 bytes

Text"R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"
Base64Encode Decode
ResizeImage 448


Takes a 1x1 transparent gif encoded as base64 and resizes it

• that was ... weird... what is the icloud link i just went to? ? – don bright Mar 15 '19 at 4:37
• @donbright when you share a shortcut from the shortcuts app, it makes that link – pfg Mar 15 '19 at 14:29

Jstx, 24 bytes

♪☺ü@/øP♦£Q)%)£Q◄úæD)%)£Q


Explanation

♪☺ü@ # Push literal 448
/    # Store the first stack value in the a register.
ø    # Push literal 0
P    # Push four copies of the first stack value.
♦    # Push literal 4
£Q   # Push stack values into a list of the size of the first stack value starting with the second stack value.
)    # Push the value contained in the a register.
%    # Push the second stack value the absolute value of the first stack value times.
)    # Push the value contained in the a register.
£Q   # Push stack values into a list of the size of the first stack value starting with the second stack value.
◄úæ  # Push literal \n
D    # Push the sum of the second and first stack values.
)    # Push the value contained in the a register.
%    # Push the second stack value the absolute value of the first stack value times.
)    # Push the value contained in the a register.
£Q   # Push stack values into a list of the size of the first stack value starting with the second stack value.


Try it online!

R, 21 bytes

array(0,c(448,448,4))


Try it online!

Returns a 3D-array of zeroes.

Japt, 9 bytes

448ÆZç4Æ0


Try it online!

C++, SFML, 131 bytes

#include <SFML/Graphics.hpp>


JavaScript + HTML, 56 bytes

location=C.toDataURL()
<canvas id=C width=448 height=448>`

Clicking "Run code snippet" will generate a 448x448 transparent PNG in an IFRAME. You may then right-click "Save image as..." to download it to your computer.