相关疑难解决方法(0)

如何找出文件的MIME类型(Content-Type)?

有没有办法找出Linux bash脚本中的文件的MIME类型(或称为"Content-Type"?)?

我需要它的原因是因为ImageShack似乎需要它来上传文件,因为它将某个.png文件检测为application/octet-stream文件.

我检查了文件,它确实是一个PNG图像:

$ cat /1.png 
?PNG
(with a heap load of random characters)
Run Code Online (Sandbox Code Playgroud)

这给了我错误:

$ curl -F "fileupload=@/1.png" http://www.imageshack.us/upload_api.php
<links>
<error id="wrong_file_type">Wrong file type detected for file 1.png:application/octet-stream</error>
</links>
Run Code Online (Sandbox Code Playgroud)

这有效,但我需要指定MIME-TYPE.

$ curl -F "fileupload=@/1.png;type=image/png" http://www.imageshack.us/upload_api.php
Run Code Online (Sandbox Code Playgroud)

linux bash mime content-type mime-types

91
推荐指数
4
解决办法
9万
查看次数

如何将Python/Pillow中的PNG图像调色板减少到真正使用的颜色?

在处理了具有透明度的先前优化的索引颜色PNG图像之后(参见此处针对某些背景,因为该问题涉及相同的图像文件),使用以下代码,PLTE块似乎扩展为具有比有效使用的颜色更多的颜色.

Mu当前代码:

#!/usr/bin/env/python3
import os

from PIL import Image


source_file = os.path.expanduser("~/Desktop/prob.png")
dest_file = os.path.expanduser("~/Desktop/processed_img.png")

img = Image.open(source_file)

# Convert all colors in the palette to grayscale and save the new palette
pal = img.getpalette()
for i in range(len(pal) // 3):
    # Using ITU-R 601-2 luma transform
    g = (pal[3*i] * 299 + pal[3*i+1] * 587 + pal[3*i+2] * 114) // 1000
    pal[3*i: 3*i+3] = [g, g, g]

img.putpalette(pal)

try:
    img.save(dest_file, optimize=True, format="PNG")
except IOError:
    ImageFile.MAXBLOCK = img.size[0] …
Run Code Online (Sandbox Code Playgroud)

png image-compression python-3.x pypng pillow

8
推荐指数
1
解决办法
645
查看次数