이것은 간단한 도전입니다.
이 작업은 100 % 투명도로 448 * 448 정사각형 이미지를 출력하는 코드를 작성하는 것입니다. 출력은 표준 이미지 규칙을 따라야합니다 .
이것은 간단한 도전입니다.
이 작업은 100 % 투명도로 448 * 448 정사각형 이미지를 출력하는 코드를 작성하는 것입니다. 출력은 표준 이미지 규칙을 따라야합니다 .
답변:
convert -size 448x448 xc:none a.png
이것이 허용됩니까?
\windows\system32).
convert도구 와 함께 제공되지 않습니다 . 이름이 시스템 유틸리티와 충돌하기 때문입니다. 당신은 magick convert ... 대신 실행 합니다.
convertImageMagick의 일부이므로 자체 언어로 호출하면 작동하지 않습니다.
ImageMagick Convert. 그래도 메타를
전체 프로그램. 448x448 rgba 이미지를 나타내는 448x448x4 배열을 인쇄합니다.
448 448 4⍴0
⍴이다 r에 eshape은
448 448?
802832p0답을 얻지 않겠 습니까?
f=
(_=document.createElement`canvas`)=>_.toDataURL(_.height=_.width=448)
;document.write(f());
반환 데이터로 인코딩 된 PNG 이미지 다음으로 설정하기위한 URL에 적합한 예를 들어 src의 HTMLImageElement. 편집 : @Shaggy 덕분에 3 바이트를 절약하고 @Arnauld 덕분에 2 바이트를 더 절약했습니다.
document.createElement`canvas` 작동하여 2 바이트를 더 절약합니다.
d=document상단에 같은 것을 추가 하고 대체 document할 수 d있습니까? ~ 5자를 저장해야합니다.
document.write함수의 일부가 아닌 스택 스 니펫의 일부이므로 계산에 포함되지 않습니다.
v->new int[448][448][4]
448x448x4 0의 3D 배열을 반환합니다.
설명:
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]
0의 448x448 행렬을 반환합니다.
Java에서 RGBA 값은 integer 로 나타낼 수 있습니다 . 16 진 0x00000000은 00각각 빨강, 녹색, 파랑 및 알파를 나타냅니다. 그리고 0x00000000integer 와 같습니다 0.
v->new int[448][448]않습니까? Java에서 색상은 정수 (RGBA)로 표시 될 수 있기 때문입니다.
0-255는 유효한 RBGA 값입니까? 유효한 RGB 값이지만 RGBA입니까? 나는 거의 자바에서 이미지를 사용하지 않으므로 너무 익숙하지 않습니다. 나는 단순히 4 개의 내부 0을 다른 답변에 기초했습니다.
0x00000000정수에 맞는 (16 진수로) 4 개의 0 입니다. 처음 2 개의 16 진수는 알파이고 다음 2는 빨간색, 다음 2는 녹색, 마지막 2는 파란색이므로 정수만 있으면됩니다. BufferedImage.TYPE_INT_ARGB를 참조하십시오 . 하나의 정수로 요약 된 4 개의 값이 있습니다. 그리고 0x00000000같습니다 0.
경로 s가 101 바이트 인 파일에 이미지 저장
s->javax.imageio.ImageIO.write(new java.awt.image.BufferedImage(448,448,2),"png",new java.io.File(s))
온라인으로 시도해보십시오 ... 어떻게 든
BufferedImage 반환, 46 바이트
v->new java.awt.image.BufferedImage(448,448,2)
이미지를 파일에 저장 f, 83 바이트
f->javax.imageio.ImageIO.write(new java.awt.image.BufferedImage(448,448,2),"png",f)
PNG를 STDOUT으로 덤프, 92 바이트 (ASCII 전용)
v->javax.imageio.ImageIO.write(new java.awt.image.BufferedImage(448,448,2),"png",System.out)
온라인으로 사용해보십시오!
두 번째 및 네 번째 솔루션의 바이트를 절약 한 Kevin에게 감사합니다!
()->대한 두 가지 답변에서 골프를 칠 수 있습니다. 비공개 입력이 비어v-> 있을 수 있기 때문입니다 (개인적으로 사용합니다 ). 그러면 마지막 TIO가 대신 사용됩니다 . Void
448LDδ4Å0
또는 대안 적으로 :
¾4Ž1ÂDиии
@Emigna 덕분에 -2 바이트 . @Adnan
덕분에 -1 바이트 .
0의 448x448x4 3D 목록을 출력합니다.
설명:
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)
내이 05AB1E 대답을 참조하십시오 (섹션 얼마나 큰 정수를 압축하는 방법을? ) 이유를 이해하는 Ž1Â것입니다 448.
[[[0]*4]*488]*488
인쇄시 :
print[[[0]*4]*488]*488
변수로 :
x=[[[0]*4]*488]*488
RGBA 배열이 허용되면 위에서 만든 것입니다. 기본값은 모두 0으로 설정됩니다. 검은 색이지만 완전히 투명합니다.
[0]*802816효과가 있습니다.
448ṁ4¬¥þ
투명한 검정 픽셀의 448 x 448 RGBA 배열을 생성하는 niladic Link.
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]
<svg height=448 width=448html 파일로 작성하고 열면 empty가 생성되므로 이것이 유효하지 않다고 생각합니다 <body>. 그러나 1 바이트의 Penality로 작성 하면 빈 SVG 이미지로를 <svg height=448 width=448>생성합니다 <body>.
>한다는 것은 마크 업이 진행되는 한 실제로 유효하다는 의미입니다.
<!DOCTYPE html>, <html>, <head>, <style>, <script>그리고 모든 것이 간다 <body>. 원하는 출력을 생성하려면 일부 추가 코드가 필요합니다. 결과 코드는 iframe으로 <svg height="448" width="448" < body></svg>작성되기 때문에 로 구문 분석되는 것을 볼 수 있습니다 <svg height=448 width=448 </body>. 따라서 여전히 유효하지 않다고 생각합니다.
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);}
이것은 바이너리 파일 헤더에 너비와 높이를 하드 코딩하여 http://paulbourke.net/dataformats/tga/에 따라 TGA 바이너리 형식을 사용하여 라이브러리 나 내장 함수없이 실제 읽을 수있는 o.tga 파일을 씁니다 .
-5 바이트는 파일 이름을 줄이고 img 크기를 수정합니다. @ASCII 전용
a파일 이름으로 작동이되지 것 것입니다. btw 444 * 444가 아닌 448 * 448이므로 유효하지 않습니다.
[255,0,0,0,0]6272 회 ( [0,0,0,0]128 회) 6272 회 반복 이미지 유형은 다음이 될 것입니다. 10아니 2더 나은, 더 짧은 실행 길이 인코딩 (대한 컬러 맵. 0,0,0,0-> 0)
_=>(Enumerable.Repeat((0,0,0,0),200704),448,448)
분명히 출력 [1D array of pixels, width, height]은 괜찮으므로`(IE, 픽셀 수, 너비, 높이)의 튜플을 출력합니다.
_=>Enumerable.Repeat(Enumerable.Repeat((0,0,0,0),448),448)
원래 행렬이 답을 반환합니다.
이미지 IO 규칙은 RGB 값의 행렬로 출력 할 수 있기 때문에이 제출은 RGBA 값의 행렬을 출력합니다.
안타깝게도 PHP는 코드가 많이 필요하기 때문에 이러한 측면에서 짜증납니다. 그러나 다시, PHP는 빠르지 않습니다.
$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');
언 골프 드 :
$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
출력하지 않고 작성하려는 경우 header()및 readfile()명령을 생략 할 수 있습니다 . 아직도, 그것은 관용적으로 길다.
'<?php return '.var_export(array_fill(0,952576,0),1).';';실행 가능한 방식으로 배열을 내보내는 데 사용할 수 있습니다 . 당신은 할 수 php -f image.php > array.php있고, 다른 곳 $array = include('array.php');에서 사용 가능한 배열을 다시 갖기 위해 할 수 있습니다 . 그러나 그것이 유효한지 모르겠으므로 대안으로 추가 할 수 있습니다. 또는 <?=json_encode(array_fill(0,952576,0));.
true로 대체 될 수 있습니다 1. 의 문서를 읽고 imagepng(), 당신은 할 수 있습니다 header('Content-type: image/png');imagepng($i);. 당신도 대체 할 수있는 생각 $b=imagecolorallocatealpha($i,0,0,0,127);imagefill($i,0,0,$b);으로 imagefill($i,0,0,imagecolorallocatealpha($i,0,0,0,127));하지만 날을 인용니까.
<? imagecolorallocatealpha($i=imagecreate(448,448),0,0,0,127);header('Content-type: image/png');imagepng($i);하여 투명한 이미지 (109 바이트)를 생성했습니다. 이미지를 브라우저 / 표준 출력 및 모든 것에 자동으로 보냅니다.
Python 3.7-PIL 가져 오기, 30 바이트
Image.new("LA",[448]*2).show()
가져 오기가 필요하지만 추상 빈 배열이 아닌 실제 이미지 파일을 만들어 표시 할 수있는 이점이 있습니다.
설명:
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 ()는 기본 이미지 프로그램에서 이미지를 엽니 다. 필자의 경우 Windows 사진 뷰어에서 임시 비트 맵 파일이 열리지 만 결과가 다를 수 있습니다. 비트 맵 표현이 투명도를 포함하지 않기 때문에 이것은 부정 행위입니다
변형 ...
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
Import합니다.
new("LA",[448]*2).show()26 바이트입니다.
2¡될 수 있습니다⁺
º4♦7*_ß{.a
º 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
이 방법은 "표준"에 비해 1 바이트를 절약합니다 ♦7*_4º*a*a*
_=>[w=448,w,Array(w*w).fill([0,0,0,0])]
분명히 출력 [height, width, 1d array of RGBA values]은 괜찮습니다.
@Arnauld 덕분에 -3 바이트
[1D array of pixels, width, height]
DIM A[448,448]SAVE"DAT:I",A
0으로 채워진 2 차원 448x448 배열을 이름이 지정된 파일에 저장합니다 DAT:I(어쨌든 배열을 반환하는 함수를 정의하는 것보다 짧음)
SmileBASIC의 색상에 대한 표준 형식 (모든 그래픽 기능에서 사용)은 32 비트 ARGB 및 16 비트 5551 RGBA이며 0두 가지 모두에서 투명합니다.
ARGB형식 (일반적으로 Smilebasic에서 사용됨)이므로 0x00000000Alpha = 0, Red = 0, Green = 0, Blue = 0입니다 0xFF000000. 검은 색은입니다 .
GRP것이지만 실제 저장되는 데이터가 동일하기 때문에 보내 드리겠습니다.
Text"R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"
Base64Encode Decode
ResizeImage 448
base64로 인코딩 된 1x1 투명 gif를 가져 와서 크기를 조정합니다
♪☺ü@/øP♦£Q)%)£Q◄úæD)%)£Q
설명
♪☺ü@ # 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.