Code Golf:1x1 黑色像素

发布于 2024-09-03 18:26:11 字数 493 浏览 14 评论 0原文

最近,我使用我最喜欢的图像编辑器制作了一个 1x1 黑色像素(当您想以便宜的方式在 HTML 中绘制实心框时,它可以派上用场)。尽管我将其设为单色 PNG,但结果却是 120 字节!我的意思是,这有点陡峭。 120 字节。 一个像素。然后我将其转换为 GIF,大小降至 43 字节。好多了,但仍然...

挑战

生成 1x1 黑色像素的最短图像文件或程序。提交内容可以是:

  • 代表 1x1 黑色像素的图像文件。所选格式必须能够表示大于 1x1 的图像,并且不能是临时的(也就是说,它不能是您刚刚为代码高尔夫编写的图像格式)。图像文件将按字节数排名。
  • 生成此类图像文件的程序。程序将按照字符数进行排名,就像代码高尔夫中常见的那样。

只要答案属于这两个类别之一,任何事情都是公平的。

另外,对于图像文件,请以十六进制或转义符指定它们,而不是使用外部图像主机:-)

Recently, I used my favorite image editor to make a 1x1 black pixel (which can come in handy when you want to draw solid boxes in HTML cheaply). Even though I made it a monochrome PNG, it came out to be 120 bytes! I mean, that's kind of steep. 120 bytes. For one pixel. I then converted it to a GIF, which dropped the size down to 43 bytes. Much better, but still...

Challenge

The shortest image file or program that is or generates a 1x1 black pixel. A submission may be:

  • An image file that represents a 1x1 black pixel. The format chosen must be able to represent larger images than 1x1, and cannot be ad-hoc (that is, it can't be an image format you just made up for code golf). Image files will be ranked by byte count.
  • A program that generates such an image file. Programs will be ranked by character count, as usual in code golf.

As long as an answer falls into one of these two categories, anything is fair game.

Also, for image files, please specify them in hexadecimal or escapes rather than using an external image host :-)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(17

蓦然回首 2024-09-10 18:26:17

DrRacket:23 个字符

#lang slideshow
(disk 1)

DrRacket: 23 chars

#lang slideshow
(disk 1)
幸福还没到 2024-09-10 18:26:17

我参加这个聚会已经很晚了,但是 http://www.perlmonks.org/?node_id= 7974 有一个比迄今为止任何人发布的更通用的答案:

## tinygif
## World's Smallest Gif
## 35 bytes, 43 if transparent

use strict;
my($RED,$GREEN,$BLUE,$GHOST,$CGI);

## Adjust the colors here, from 0-255
$RED   = 255;
$GREEN = 0;
$BLUE  = 0;

## Set $GHOST to 1 for a transparent gif, 0 for normal
$GHOST = 0;

## Set $CGI to 1 if writing to a web browser, 0 if not
$CGI = 0;

$CGI && printf "Content-Length: %d\nContent-Type: image/gif\n\n", 
  $GHOST?43:35;
printf "GIF89a\1\0\1\0%c\0\0%c%c%c\0\0\0%s,\0\0\0\0\1\0\1\0\0%c%c%c\1\0;",
  144,$RED,$GREEN,$BLUE,$GHOST?pack("c8",33,249,4,5,16,0,0,0):"",2,2,4;

I'm pretty late to this party, but http://www.perlmonks.org/?node_id=7974 has a more general answer than anyone's posted so far:

## tinygif
## World's Smallest Gif
## 35 bytes, 43 if transparent

use strict;
my($RED,$GREEN,$BLUE,$GHOST,$CGI);

## Adjust the colors here, from 0-255
$RED   = 255;
$GREEN = 0;
$BLUE  = 0;

## Set $GHOST to 1 for a transparent gif, 0 for normal
$GHOST = 0;

## Set $CGI to 1 if writing to a web browser, 0 if not
$CGI = 0;

$CGI && printf "Content-Length: %d\nContent-Type: image/gif\n\n", 
  $GHOST?43:35;
printf "GIF89a\1\0\1\0%c\0\0%c%c%c\0\0\0%s,\0\0\0\0\1\0\1\0\0%c%c%c\1\0;",
  144,$RED,$GREEN,$BLUE,$GHOST?pack("c8",33,249,4,5,16,0,0,0):"",2,2,4;
打小就很酷 2024-09-10 18:26:17

XPM,57字节

/* XPM */
static char *_x_[] = {"1 1 1 1",".c #000","."}

查找要链接的维基百科文章时我找到了XPM2,26字节,但我无法用这里的任何程序打开它。

! XPM2
1 1 1 1
. c #000
.

XPM, 57 bytes:

/* XPM */
static char *_x_[] = {"1 1 1 1",".c #000","."}

When looking for the wikipedia article to link it I found XPM2, 26 bytes, but I could not open that with any program here.

! XPM2
1 1 1 1
. c #000
.
痴情换悲伤 2024-09-10 18:26:17

Rebmu:16个字符

en'PNGmkIM![1x1]

如果您希望它根据您传入的参数保存到文件中,则添加程序中还有三个字符:

rebmu/args [wrAen'PNGmkIM![1x1]] %my-black-pixel.png

该程序是以下 Rebol 的简写,为了清楚起见添加了括号:

write a (encode 'png (make image! [1x1]))

Rebmu: 16 chars

en'PNGmkIM![1x1]

If you want it to save to a file based on an argument you pass in, that adds three more chars to the program:

rebmu/args [wrAen'PNGmkIM![1x1]] %my-black-pixel.png

The program is shorthand for the following Rebol, parentheses added for clarity:

write a (encode 'png (make image! [1x1]))
怪我太投入 2024-09-10 18:26:17
<div style="height: 0; width: 1px; border-top: 1px solid #000">

但定位需要更多。

<div style="height: 0; width: 1px; border-top: 1px solid #000">

But positioning it will take more.

风筝在阴天搁浅。 2024-09-10 18:26:16

数据 URI,83 个字符

data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAAAAAAALAAAAAABAAEAAAICTAEAOw==

Data URI, 83 characters

data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAAAAAAALAAAAAABAAEAAAICTAEAOw==
我乃一代侩神 2024-09-10 18:26:16

图像文件:10 字节,采用 PGM 格式

P5 1 1 1\n\0

:用 Python 创建:40 个字符

 open('b.pgm', 'w').write('P5 1 1 1\n\0')

Image file: 10 bytes, in PGM format:

P5 1 1 1\n\0

To create it, in Python: 40 characters

 open('b.pgm', 'w').write('P5 1 1 1\n\0')
毁虫ゝ 2024-09-10 18:26:16

Unicode 艺术 格式:

·

Unicode art format:

·

奶气 2024-09-10 18:26:16

WBMP,5 字节:

00 00 01 01 00

无法想象更小的尺寸

WBMP, 5 bytes:

00 00 01 01 00

Can't imagine anything smaller

dawn曙光 2024-09-10 18:26:16

PBM 格式是一种黑白图形格式。

单个黑色像素的二进制表示需要 8 个字节,用 C# 将其写入文件将如下所示:

File.WriteAllText("p.pbm", "P4 1 1 ÿ");

The PBM format is a black and white graphics format.

A binary representation of a single black pixel would take 8 bytes, and writing it to a file with C# would look like:

File.WriteAllText("p.pbm", "P4 1 1 ÿ");
套路撩心 2024-09-10 18:26:16

Logo / Turtle basic,12 字节

PENDOWN FD 1

我不记得 pendown 是否可以缩短为 pd,如果可以的话,那将其减少到 7 个字节。

Logo / Turtle basic, 12 bytes

PENDOWN FD 1

I can't remember if pendown can be shortened to pd or not, if so, that drops it to 7 bytes.

故人的歌 2024-09-10 18:26:16

bash: 31 个字符

从互联网下载单个像素 gif 的脚本比单个像素本身的字节数少......

wget http://tinyurl.com/2w97dyo

bash: 31 chars

The script to download a single pixel gif from the interwebs is fewer bytes than the single pixel itself...

wget http://tinyurl.com/2w97dyo
甜中书 2024-09-10 18:26:16

Python+PIL 68 个字符

from PIL import Image
Image.fromstring("P",(1,1),"\0").save("B.gif")

Python+PIL 68 chars

from PIL import Image
Image.fromstring("P",(1,1),"\0").save("B.gif")
日暮斜阳 2024-09-10 18:26:16

后记,29 字节。并不是真正的“单个像素”,但它是我的预览屏幕上的单个像素。

0 0 moveto .5 0 lineto stroke

Postscript, 29 bytes. not really a "single pixel", but it was a single pixel on my preview screen.

0 0 moveto .5 0 lineto stroke
念三年u 2024-09-10 18:26:16

Python(带 PIL)(85 个字符):

from PIL import Image
i=Image.new("P",(1,1))
i.putpixel((0,0),(0))
i.save("i.gif","GIF")

Python (w/ PIL) (85 chars):

from PIL import Image
i=Image.new("P",(1,1))
i.putpixel((0,0),(0))
i.save("i.gif","GIF")
慕巷 2024-09-10 18:26:16

我曾经使用的旧图像格式: 4 字节

 01 00 00 0C

该格式由 16 位整数数组(小端)组成:

位映射:

0-10:  number of pixels to shade
10-11: control bits
12-15: VGA16 pidel color

控制位值:

0: normal
1: end of line
3: end of file

An old image format I used to use: 4 bytes

 01 00 00 0C

The format consists of an array of 16 bit integers (little endian):

Bit mapping:

0-10:  number of pixels to shade
10-11: control bits
12-15: VGA16 pidel color

Control bits values:

0: normal
1: end of line
3: end of file
窝囊感情。 2024-09-10 18:26:16

SVG,59 个字符:

<svg><rect width="1" height="1" style="fill:#000;"/></svg>

不幸的是,包括 Doctype 它增长到 157 个...:

<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg><rect width="1" height="1" style="fill:#000;"/></svg>

SVG, 59 characters:

<svg><rect width="1" height="1" style="fill:#000;"/></svg>

Unfortuntally, including Doctype it grows to 157...:

<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg><rect width="1" height="1" style="fill:#000;"/></svg>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文