imageio库据我所知,我可以更改两种类型的设置。在imageio.imread()阅读.pngs设置和imageio.mimwrite()写GIF格式设置。根据imageio.help(),
imageio.imread()有一个只读参数 for PNG-PIL,ignoregamma它需要一个布尔值。这不会改变我的输出 gif 的任何内容。imageio.mimwrite()可以参考两种格式。第一个是GIF-PIL。这种格式的输出只显示一帧,因此是不可取的。输出在这里。imageio.mimwrite()有第二种格式GIF-FI。这可以通过以下选项产生更有希望的输出:
这是迄今为止我可以获得的最佳质量的相关代码(GIF-FI与nq)
def gen_gif(self, datetime_list):
kwargs_write = {'fps':5.0, 'quantizer':'nq'}
frames = []
for datetime in datetime_list:
frames.append(imageio.imread(datetime+'.png'))
exportname = '{} …Run Code Online (Sandbox Code Playgroud) 编辑:这个问题已被标记为重复?我的问题显然是关于优化这个过程,而不是如何做到这一点.我甚至提供了代码来证明我已经找到了后者.互联网大厅监视器甚至在标记之前读过这些问题吗?
我有以下代码块来使用PIL压缩图像,直到所述图像具有一定的大小.
from PIL import Image
import os
def compress(image_file, max_size, scale):
while os.path.getsize(image_file) > max_size:
pic = Image.open(image_file)
original_size = pic.size
pic = pic.resize((int(original_size[0] * scale),
int(original_size[1] * scale)),
Image.ANTIALIAS)
pic.save(image_file, optimize=True, quality=95)
Run Code Online (Sandbox Code Playgroud)
在这段代码中,我os.path.getsize(image_file)用来获取图像的大小.但是,这意味着每次循环运行时都必须保存文件pic.save(image_file, optimize=True, quality=95.
这个过程需要很长时间.
有没有办法通过某种方式获得PIL Image对象中图像的大小来优化它pic?
我知道如何使用-vin 中的选项将本地目录安装为卷docker run,即
docker run -v /local/some_folder:/container/some_folder image_name
Run Code Online (Sandbox Code Playgroud)
不过,我希望能够指定上述指令(安装在本地/local/some_folder作为/container/some_folder容器的Dockerfile内。
我试过VOLUME /local/some_folder /container/some_folder在 中使用Dockerfile,但这似乎没有用:然后我可以/container/some_folder从容器内使用进行访问docker exec -t container sh,但是容器的写入更改/container/some_folder 不会/local/some_folder在容器运行时和之后反映docker stop container。
我对编程很陌生。我最近使用 python 和 pygame 制作了一个简单的贪吃蛇游戏。当然,我可以通过运行 .py 脚本轻松玩我的游戏,但为了与我不太懂计算机的朋友分享它,我继续尝试找出如何将我的代码编译成单个 .exe 来制作它对他们来说很容易。
我尝试过 py2exe 和 cx_Freeze,两者都为我提供了一个包含 .exe 和其他几个文件(依赖项)的 dist 或 build 目录。这确实有效,因为我可以压缩整个文件夹并通过 .zip 分发,但这并不理想。我希望能够将所有内容打包在一个文件中。
所以我开始谷歌搜索“如何将 python 编译成单个 exe”。然而,与我之前尝试过谷歌搜索的许多编程问题不同,我只是无法得到直接、可靠的答案。到目前为止,我尝试过的最新可靠答案给了我这个 setup.py 脚本:
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
options = {'py2exe': {'bundle_files': 1, 'compressed': True}},
windows = ['snek.py'],
zipfile = None
)
# Python 3.4.4, py2exe 0.9.2.2; modules used: pygame, random
Run Code Online (Sandbox Code Playgroud)
尽管如此,它还是给了我一个完整的文件夹,而不是一个 .exe,没有它程序就无法运行。
所以,我带着两个问题来找你,这位无所不知、伟大的 stackoverflow。
以防万一我错过了什么:你建议我如何实现我的单一 .exe 梦想?
还有:这到底为什么这么难?
为了使用SSH从GitHub推/拉,我必须......
$ eval $(ssh-agent -s)
$ ssh-add ~/.ssh/git_id_rsa
$ git push origin master
Run Code Online (Sandbox Code Playgroud)
但是,当我推送/拉到远程git存储库时,我在我自己的私有服务器上托管,我可以跳过所有ssh-agent内容并简单地
$ git push origin master
Run Code Online (Sandbox Code Playgroud)
我如何使用GitHub(没有ssh-agent设置的推/拉ssh-add)?
我在根crontab中设置了一个脚本,该脚本应该使用reboot命令重新启动计算机。
但是,reboot: command not found尽管事实reboot并非如此,但是我已经成为root用户的了。
$ sudo su
$ which reboot
/sbin/reboot
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin
Run Code Online (Sandbox Code Playgroud)
我的剧本:
#!/bin/bash
ping 8.8.8.8 -c 1 > /dev/null 2>&1; exit_code=$?
time_stamp=$(date +"%Y%m%d-%H%M")
if [ $exit_code -ne 0 ]; then
(1>&2 echo "$time_stamp: failed with exit code $exit_code; restarting now")
reboot
else
echo "$time_stamp: ok"
fi
Run Code Online (Sandbox Code Playgroud)
超级用户crontab:
$ sudo crontab -l
58 * * * * /home/pi/github/ping-restart/ping-restart.sh >> /home/pi/github/ping-restart/cron.log 2>&1
$ sudo su
58 * * * * /home/pi/github/ping-restart/ping-restart.sh …Run Code Online (Sandbox Code Playgroud)