下山羊化动物!


25

我的Downgoat头像有几个独特的功能

但是,这些功能也可以应用于任何其他动物。

规格

给定动物的图像(技术上可以是任何东西),您必须对其应用Downgoat属性。

边框像素是图像的最外面像素。

背景颜色定义为边界像素最常用的颜色。当该颜色被解释为(r,g,b,a)颜色,并且每个通道都来自[0,256)时,背景被定义为给定像素的每个通道在“背景颜色”。

过程:

  • 将背景和所有透明像素设置为#232323RGBA(35, 35, 35, 1.00)
  • 设置不属于后台的所有像素#FC0D1BRGBA(252, 13, 27, 1.00)
  • 垂直反映图像
  • -1在图像的中央添加Arial字体的文本。文字的总高度应为图片最小尺寸(即min(width, height) * 0.25)的25%。

规则

  • 随意假设字体已经安装
  • 您的阈值应该是50,但是您也可以将此数字作为输入。您不会因此而减少任何字节数
  • 有关与I / O格式有关的任何问题,请参考我们的映像I / O默认值
  • 图片尺寸始终至少为3x3
  • 如果没有最常见的“边界像素颜色”,则使用哪种边界像素颜色作为“背景颜色”都没有关系,但是必须保持一致。

例子

输入: 山羊

输出: 下山羊


输入: 乌贼

输出: 下乌贼

输入: 下山羊

输出: 羽绒山羊


输入: 丹尼斯

输出: 唐登尼斯


输入: 木霉

输出: 下tric


更多例子?

可在此处获得在线实施:vihan.org/p/downgoatify/#50


这是因此以字节为单位的最短代码获胜。祝好运!


6
-1第一个测试用例不是动物-_-
Geobits,2016年

10
-1ˢᵗ测试用例也不是动物。
2013年

8
不喜欢恶魔
丹尼斯

1
通过将标题中的“动物”更改为“化身”,您可以消除对它是否是动物的担忧。
Glenn Randers-Pehrson,2016年

4
强制使用字体有什么意义?唯一要做的就是惩罚更改字体需要更多字节的语言
Fatalize

Answers:


9

ImageMagick 7.0.3 + bash + sed,379字节

M=magick K=\#232323 P='-chop x%[fx:u[0].h-2]-0+1'
$M $1 -depth 8 ppm:W;$M W $P T;$M W -rotate 90 -shave 1x $P L
C=`$M T L +append -statistic mode +0 txt:-|sed -e "1d;s/.*#/#/;s/ .*//;q"`
$M W -background $K -flatten -fill $K -fuzz 20% -opaque $C +fuzz -fill \#FC0D1B +opaque $K -flip -pointsize %[fx:.282*min\(u[0].w,u[0].h\)] -fill white -draw 'gravity center text 0,0 "-1"' x:

不打高尔夫球

# Make aliases for things we'll use repeatedly
M=magick K=\#232323 P='-chop x%[fx:u[0].h-2]-0+1'

# Copy the input file to a PPM file
$M $1 -depth 8 ppm:W

# Extract the border pixels into "T" (top and bottom), and "L" (left and right)
# PPM files, removing the ends from the "L" because they were already counted 
$M W $P T;$M W -rotate 90 -shave 1x $P L

# Put the borders into one strip and reduce to a txt image of the "mode"
# color on stdout, then convert the first pixel to hex format string "C"
C=`$M T L +append -statistic mode +0 txt:-|sed -e "1d;s/.*#/#/;s/ .*//;q"`

# Make background "#232323" and compose transparent pixels against it
# Convert any pixels with color within "fuzz" distance of background to #232323
# Convert any remaining pixels to "#FC0D1B"
# Flip the image vertically
# Determine pointsize for text, 1/5 of min(w,h). 1 pixel == 1.44 points
# Draw text "-1" centered on the image
# Display the result to an X window

$M W -background $K -flatten                     \
-fill $K -fuzz 20% -opaque $C                    \
+fuzz -fill \#FC0D1B +opaque $K                  \
-flip                                            \
-pointsize %[fx:.282*min\(u[0].w,u[0].h\)]       \
-fill white -draw 'gravity center text 0,0 "-1"' \
x:

输入和输出

对于丹尼斯图像,我得到了一个完全不同的答案,可能是因为ImageMagick的“ -fuzz”计算了一个在RGB坐标中直径为2N单位的球体,而规则要求计算在RGB坐标中具有101个单位的边的立方体。改变“模糊”有助于一些。此外,原始文件中的JPEG伪像似乎会干扰转换。


我对imageMagick并不熟悉,所以这可能是没有学问的,但是可以将#0000颜色代码替换为简单的#0吗?
tuskiomi

不,#0不起作用。#000也不会,因为那是不透明的黑色,我们这里需要透明的黑色。
Glenn Randers-Pehrson

我提到的错误# ImageMagick 7.0.1 through 7.0.3-7 fails here已报告给IM开发人员,并已在7.0.3-8版中修复。
Glenn Randers-Pehrson '16

10

C,32位Windows,987字节

#include <windows.h>
#define A CreateCompatibleDC(c)
#define F z=GetPixel(d,x,y);r=z;g=z>>8;b=z>>16
#define C(X,Y) (X<0||Y<0||X>=s[2]||Y>=s[3]||!GetPixel(e,X,Y))
#define D ((C(x-1,y)||C(x+1,y)||C(x,y-1)||C(x,y+1))&&!C(x,y))
#define E(X,Y) ((Z+X-Y)*(Z+X-Y)<2501)
main(int a,int*n){HDC c,d,e,f,w;int x,y,s[9],z,*o,m,t,Z;unsigned char r,g,b,R,G,B;c=GetDC(w=GetDesktopWindow());d=A;e=A;SelectObject(d,f=LoadImage(0,n[1],0,0,0,16));SelectObject(e,LoadImage(0,n[2],0,0,0,16));GetObject(f,24,s+1);o=LocalAlloc(64/*Fixed,ZeroInit*/,8*s[2]*s[3]);for(x=t=Z=s[1]=s[0]=0;x<s[2];x++)for(y=0;y<s[3];y++)if D{F;for(m=0;m<t&&o[m]!=z;m+=2);o[m]=z;o[m+1]++;t+=2*(m>=t);}for(x=y=1;x<t;x+=2)if(o[x]>o[y])y=x;z=o[y-1];R=z;G=z>>8;B=z>>16;for(x=0;x<s[2];x++)for(y=0;y<s[3];y++){F;SetPixel(c,x,s[3]-y-1,(C(x,y)||(E(r,R)&&E(g,G)&&E(b,B)))?0x232323:0x1B0DFC);}SelectObject(c,CreateFont(-(s[2]>>2),0,0,0,400,0,0,0,0,0,0,0,0,"Arial"));SetBkMode(c,1);SetTextColor(c,0xFFFFFF);DrawText(c,"-1",2,s,37);ReleaseDC(w,c);}
  • 该文件以LF作为行尾保存,而不是使用CR + LF保存以保存一些字节。
  • 该程序以生成编译器警告以节省更多字节的方式编写。
  • 该文件可能不会编译为64位程序,因为数组“ s[]”用于执行一些隐式转换。
  • 该程序拍摄两个图像(文件名通过命令行给出):
    • 第一个映像(第一个命令行参数)是Windows .BMP格式的R / G / B映像。
    • 第二个图像是Alpha通道(黑色表示:0%,其他颜色表示:非0%);该文件也是.BMP格式,并且必须具有相同大小或大于第一个图像
  • 输出图像显示在屏幕的左上角
  • 我无法复制那个染黄头发的男孩。黄色似乎离白色太远(> 50)!

非高尔夫版本:

#include <windows.h>

/*
 * Although this line costs us 32 bytes
 * Replacing "CreateCompatibleDC(c)" we'll
 * save 42 bytes in the golfed version later
 * so we save 10 bytes using this define!
 */
#define A CreateCompatibleDC(c)

/*
 * Macro: Get a pixel value at (x,y) to z
 * Also get r, g, b
 */
#define F z=GetPixel(d,x,y); \
    r=z; \
    g=z>>8; \
    b=z>>16

/*
 * Macro checking if a pixel is a
 * transparent colour or lies outside the
 * image
 */
#define C(X,Y) (X<0 || Y<0 || X>=s[2] || Y>=s[3] || !GetPixel(e,X,Y))

/*
 * Macro checking if a pixel at (x,y) is a border pixel
 */
#define D ((C(x-1,y) || C(x+1,y) || C(x,y-1) || C(x,y+1)) && !C(x,y))

/*
 * Macro checking if the difference between X and Y is less than 50
 * The variable "Z" must be type "int" and zero. It is used to
 * perform an implicit cast from "BYTE" to "int".
 */
#define E(X,Y) ((Z+X-Y)*(Z+X-Y)<2501)

/*
 * Note that the second argument is "char **",
 * not "int *".
 * We ignore resulting compiler warnings...
 */
main(int a, int * n)
{
    HDC c, d, e, f, w;
    int x, y, s[9], z, *o, m, t, Z;
    unsigned char r, g, b, R, G, B;

    /*
     * Get the HDC handle to the
     * screen (allowing us to create HDCs
     * for accessing bitmap files as well as
     * drawing directly to the screen!)
     */
    c=GetDC(w=GetDesktopWindow());
    /*
     * Create two virtual HDCs for accessing
     * the bitmap files.
     */
    d=A; /* Macro */
    e=A; /* Macro */
    /*
     * Load the two images:
     * The first argument is the image file with
     * the R/G/B channel
     * The second argument is the image file
     * containing the mask defined by the Alpha
     * channel:
     *   Black means = Alpha=0
     *   White means = Alpha>0
     *   (Any other colour means: Alpha>0)
     *
     * Note that "f" is of the type "HBITMAP",
     * not "HDC". We save 4 bytes in the golfed
     * version using HDC instead of HBITMAP and
     * compile the C file with compiler warnings
     * switched off!
     *
     * The second image should have the same size
     * as the first one. However it may be larger
     * than the first one. It must not be smaller!
     */
    SelectObject(d,f=LoadImage(0,n[1],0,0,0,16 /* 16=LR_LOADFROMFILE */));
    SelectObject(e,LoadImage(0,n[2],0,0,0,16));
    /*
     * Get the image information (size)
     */
    GetObject(f,24,s+1);
    /*
     * Search all background colours
     */
    o=LocalAlloc(64 /* Fixed, ZeroInit */,8*s[2]*s[3]);
    for(x=t=Z=s[1]=s[0]=0;x<s[2];x++)
        for(y=0;y<s[3];y++)
            if D
    {
        F; /* Macro */
        for(m=0;m<t && o[m]!=z;m+=2);
        o[m]=z;
        o[m+1]++;
        t+=2*(m>=t);
    }
    /*
     * Search the most common one
     */
    for(x=y=1;x<t;x+=2) if(o[x]>o[y]) y=x;
    z=o[y-1];
    R=z;
    G=z>>8;
    B=z>>16;
    /*
     * Draw the image directly to the screen
     */
    for(x=0;x<s[2];x++)
        for(y=0;y<s[3];y++)
    {
        F; /* Macro */
        /* C and E are macros: */
        SetPixel(c,x,s[3]-y-1,(C(x,y) ||
            (E(r,R) && E(g,G) && E(b,B)))?
            0x232323:0x1B0DFC);
    }
    /*
     * Draw the text over the image
     */
    SelectObject(c,CreateFont(-(s[2]>>2),0,0,0,400,0,0,0,0,0,0,0,0,"Arial"));
    SetBkMode(c,1 /* TRANSPARENT */);
    SetTextColor(c,0xFFFFFF);
    DrawText(c,"-1",2,s,37 /* center, vcenter, singleline */);
    /*
     * Unfortunately DrawText() won't work
     * when not doing this!
     */
    ReleaseDC(w,c);
}
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.