小编Vic*_*Xue的帖子

转义字符在 Dockerfile 中如何工作?

我正在阅读Dockerfile Reference 的 escape 部分。在文档中,有一个示例演示了默认转义字符“\”如何在 Windows 系统中引起问题。

FROM microsoft/nanoserver  
COPY testfile.txt c:\\  
RUN dir c:\  
Run Code Online (Sandbox Code Playgroud)

结果是:

PS C:\John> docker build -t cmd 。
将构建上下文发送到 Docker 守护进程 3.072 kB
步骤 1/2:FROM microsoft/nanoserver ---> 22738ff49c6d
步骤 2/2:复制 testfile.txt c:\RUN dir c:
GetFileAttributesEx c:RUN:系统找不到指定的文件。
PS C:\约翰>

根据我的理解, in 中的第一个反斜杠COPY testfile.txt c:\\将转义第二个反斜杠,命令变为COPY testfile.txt c:\。反斜杠在RUN dir c:\命令中消失,因为它充当转义字符,这是有道理的。但是,我不确定为什么换行符也会被转义,因为 COPY 和 RUN 命令被合并为单个命令。我不是转义字符方面的专家,我可能会误解一些非常基本的东西。您能告诉我转义字符在这种情况下是如何工作的吗?提前致谢。

escaping docker dockerfile

11
推荐指数
1
解决办法
2万
查看次数

PIL 的 Image.convert() 函数如何在“P”模式下工作

我有一组 24 位 png 文件,我想将它们转换为 8 位 png 文件。我使用了 PIL 的 Image.convert() 方法来解决这个问题。但是,在使用 mode 'P' 作为参数后,我发现具有相同 RGB 值的像素可以进行不同的转换。

我将一个示例图像传输到一个 numpy 数组中,原始 24 位 png 文件具有如下值:

RGB阵列

   ..., 
   [204, 102, 119],
   [204, 102, 119],
   [204, 102, 119],
   [204, 102, 119],
   [204, 102, 119],
   [204, 102, 119],
   [204, 102, 119],
   [204, 102, 119],
   [204, 102, 119],
   [204, 102, 119],
   [204, 102, 119], 
   ...
Run Code Online (Sandbox Code Playgroud)

使用模式'P'的转换函数后,图像值变成这样:

8 位数组

   ..., 98, 98, 134, 98, 98, 98, 134, 98, 98, 98, 134, ...
Run Code Online (Sandbox Code Playgroud)

代码示例:

from PIL …
Run Code Online (Sandbox Code Playgroud)

python image image-processing python-imaging-library

6
推荐指数
1
解决办法
3039
查看次数