Merge remote-tracking branch 'LCTT/master'

This commit is contained in:
Xingyu Wang 2020-01-18 12:08:10 +08:00
commit 090739a7a5
9 changed files with 625 additions and 315 deletions

View File

@ -1,34 +1,33 @@
[#]: collector: (lujun9972)
[#]: translator: (cycoe)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: reviewer: (wxy)
[#]: publisher: (wxy)
[#]: url: (https://linux.cn/article-11790-1.html)
[#]: subject: (Add jumping to your Python platformer game)
[#]: via: (https://opensource.com/article/19/12/jumping-python-platformer-game)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
为你的 Python 平台类游戏添加跳跃功能
======
在本期使用 Python Pygame 模块编写视频游戏中,学会如何使用跳跃来对抗重力。
![游戏厅中的游戏][1]
> 在本期使用 Python Pygame 模块编写视频游戏中,学会如何使用跳跃来对抗重力。
![](https://img.linux.net.cn/data/attachment/album/202001/16/214917c8mxn82fot82fx88.jpg)
在本系列的 [前一篇文章][2] 中,你已经模拟了重力。但现在,你需要赋予你的角色跳跃的能力来对抗重力。
跳跃是对重力作用的暂时延缓。在这一小段时间里,你是向_上_跳,而不是被重力拉着向下落。但你一旦到达了跳跃的最高点,重力就会重新发挥作用,将你拉回地面。
跳跃是对重力作用的暂时延缓。在这一小段时间里,你是向*上*跳,而不是被重力拉着向下落。但你一旦到达了跳跃的最高点,重力就会重新发挥作用,将你拉回地面。
在代码中,跳跃被表示为变量。首先,你需要为玩家对象建立一个变量,使得 Python 能够跟踪对象是否正在跳跃中。一旦玩家对象开始跳跃,他就会再次受到重力的作用,并被拉回最近的物体。
在代码中,这种变化被表示为变量。首先,你需要为玩家精灵建立一个变量,使得 Python 能够跟踪该精灵是否正在跳跃中。一旦玩家精灵开始跳跃,他就会再次受到重力的作用,并被拉回最近的物体。
### 设置跳跃状态变量
你需要为你的 Player 类添加两个新变量:
你需要为你的 `Player` 类添加两个新变量:
* 一个是为了跟踪你的角色是否正在跳跃中,可通过你的玩家对象是否站在坚实的地面来确定
* 一个是为了跟踪你的角色是否正在跳跃中,可通过你的玩家精灵是否站在坚实的地面来确定
* 一个是为了将玩家带回地面
将如下两个变量添加到你的 **Player** 类中。在下方的代码中,注释前的部分用于提示上下文,因此只需要添加最后两行:
将如下两个变量添加到你的 `Player` 类中。在下方的代码中,注释前的部分用于提示上下文,因此只需要添加最后两行:
```
                self.movex = 0
@ -40,16 +39,15 @@
                self.jump_delta = 6
```
第一个变量 **collide_delta** 被设为 0 是因为在正常状态下,玩家对象没有处在跳跃中的状态。另一个变量 **jump_delta** 被设为 6是为了防止对象在第一次进入游戏世界时就发生反弹(实际上就是跳跃)。当你完成了本篇文章的示例,尝试把该变量设为 0 看看会发生什么。
第一个变量 `collide_delta` 被设为 0 是因为在正常状态下,玩家精灵没有处在跳跃中的状态。另一个变量 `jump_delta` 被设为 6是为了防止精灵在第一次进入游戏世界时就发生反弹(实际上就是跳跃)。当你完成了本篇文章的示例,尝试把该变量设为 0 看看会发生什么。
### 跳跃中的碰撞
如果你是跳到一个蹦床上,那你的跳跃一定非常优美。但是如果你是跳向一面墙会发生什么呢?(千万不要去尝试!)不管你的起跳多么令人印象深刻,当你撞到比你更大更硬的物体时,你都会立马停下。(译注:原理参考动量守恒定律)
如果你是跳到一个蹦床上,那你的跳跃一定非常优美。但是如果你是跳向一面墙会发生什么呢?(千万不要去尝试!)不管你的起跳多么令人印象深刻,当你撞到比你更大更硬的物体时,你都会立马停下。(LCTT 译注:原理参考动量守恒定律)
为了在你的视频游戏中模拟这一点,你需要在你的玩家对象与地面等东西发生碰撞时,将 **self.collide_delta** 变量设为 0。如果你的 **self.collide_delta** 不是 0 而是其它的什么值,那么你的玩家就会发生跳跃,并且当你的玩家与墙或者地面发生碰撞时无法跳跃。
在你的 **Player** 类的 **update** 方法中,将地面碰撞相关代码块修改为如下所示:
为了在你的视频游戏中模拟这一点,你需要在你的玩家精灵与地面等东西发生碰撞时,将 `self.collide_delta` 变量设为 0。如果你的 `self.collide_delta` 不是 0 而是其它的什么值,那么你的玩家就会发生跳跃,并且当你的玩家与墙或者地面发生碰撞时无法跳跃。
在你的 `Player` 类的 `update` 方法中,将地面碰撞相关代码块修改为如下所示:
```
        ground_hit_list = pygame.sprite.spritecollide(self, ground_list, False)
@ -57,42 +55,40 @@
            self.movey = 0
            self.rect.y = worldy-ty-ty
            self.collide_delta = 0 # 停止跳跃
            if self.rect.y > g.rect.y:
                self.health -=1
                print(self.health)
if self.rect.y > g.rect.y:
self.health -=1
print(self.health)
```
这段代码块检查了地面对象和玩家对象之间发生的碰撞。当发生碰撞时,它会将玩家 Y 方向的坐标值设置为游戏窗口的高度减去一个瓷贴的高度再减去另一个瓷贴的高度。以此保证了玩家对象是站在地面**上**,而不是嵌在地面里。同时它也将 **self.collide_delta** 设为 0使得程序能够知道玩家未处在跳跃中。除此之外它将 **self.movey** 设为 0使得程序能够知道玩家当前未受到重力的牵引作用这是游戏物理引擎的奇怪之处一旦玩家落地也就没有必要继续将玩家拉向地面
这段代码块检查了地面精灵和玩家精灵之间发生的碰撞。当发生碰撞时,它会将玩家 Y 方向的坐标值设置为游戏窗口的高度减去一个瓷砖的高度再减去另一个瓷砖的高度。以此保证了玩家精灵是站在地面*上*,而不是嵌在地面里。同时它也将 `self.collide_delta` 设为 0使得程序能够知道玩家未处在跳跃中。除此之外它将 `self.movey` 设为 0使得程序能够知道玩家当前未受到重力的牵引作用这是游戏物理引擎的奇怪之处一旦玩家落地也就没有必要继续将玩家拉向地面
此处 **if** 语句用来检测玩家是否已经落到地面之_下_,如果是,那就扣除一点生命值作为惩罚。此处假定了你希望当你的玩家落到地图之外时失去生命值。这个设定不是必需的,它只是平台类游戏的一种惯例。更有可能的是,你希望这个事件能够触发另一些事件,或者说是一种能够让你的现实世界玩家沉迷于让对象掉到屏幕之外的东西。一种简单的恢复方式是在玩家对象掉落到地图之外时,将 **self.rect.y** 重新设置为 0这样它就会在地图上方重新生成并落到坚实的地面上。
此处 `if` 语句用来检测玩家是否已经落到地面之*下*,如果是,那就扣除一点生命值作为惩罚。此处假定了你希望当你的玩家落到地图之外时失去生命值。这个设定不是必需的,它只是平台类游戏的一种惯例。更有可能的是,你希望这个事件能够触发另一些事件,或者说是一种能够让你的现实世界玩家沉迷于让精灵掉到屏幕之外的东西。一种简单的恢复方式是在玩家精灵掉落到地图之外时,将 `self.rect.y` 重新设置为 0这样它就会在地图上方重新生成并落到坚实的地面上。
### 撞向地面
模拟的重力使你玩家的 Y 坐标不断增大(译注:此处原文中为 0但在 Pygame 中越靠下方 Y 坐标应越大)。要实现跳跃,完成如下代码使你的玩家对象离开地面,飞向空中。
在你的 **Player** 类的 **update** 方法中,添加如下代码来暂时延缓重力的作用:
模拟的重力使你玩家的 Y 坐标不断增大LCTT 译注:此处原文中为 0但在 Pygame 中越靠下方 Y 坐标应越大)。要实现跳跃,完成如下代码使你的玩家精灵离开地面,飞向空中。
在你的 `Player` 类的 `update` 方法中,添加如下代码来暂时延缓重力的作用:
```
        if self.collide_delta < 6 and self.jump_delta < 6:
        if self.collide_delta < 6 and self.jump_delta < 6:
            self.jump_delta = 6*2
            self.movey -= 33  # 跳跃的高度
            self.collide_delta += 6
            self.jump_delta    += 6
```
根据此代码所示,跳跃使玩家对象向空中移动了 33 个像素。此处是_负_ 33 是因为在 Pygame 中,越小的数代表距离屏幕顶端越近。
根据此代码所示,跳跃使玩家精灵向空中移动了 33 个像素。此处是*负* 33 是因为在 Pygame 中,越小的数代表距离屏幕顶端越近。
不过此事件视条件而定,只有当 **self.collide_delta** 小于 6缺省值定义在你 **Player** 类的 **init** 方法中)并且 **self.jump_delta** 也于 6 的时候才会发生。此条件能够保证直到玩家碰到一个平台,才能触发另一次跳跃。换言之,它能够阻止空中二段跳。
不过此事件视条件而定,只有当 `self.collide_delta` 小于 6缺省值定义在你 `Player` 类的 `init` 方法中)并且 `self.jump_delta` 也于 6 的时候才会发生。此条件能够保证直到玩家碰到一个平台,才能触发另一次跳跃。换言之,它能够阻止空中二段跳。
在某些特殊条件下,你可能不想阻止空中二段跳,或者说你允许玩家进行空中二段跳。举个栗子,如果玩家获得了某个战利品,那么在他被敌人攻击到之前,都能够拥有空中二段跳的能力。
当你完成本篇文章中的示例,尝试将 **self.collide_delta****self.jump_delta** 设置为 0从而获得百分之百的几率触发空中二段跳。
当你完成本篇文章中的示例,尝试将 `self.collide_delta``self.jump_delta` 设置为 0从而获得百分之百的几率触发空中二段跳。
### 在平台上着陆
目前你已经定义了再玩家对象摔落地面时的抵抗重力条件,但此时你的游戏代码仍保持平台与地面置于不同的列表中(就像本文中做的很多其他选择一样,这个设定并不是必需的,你可以尝试将地面作为另一种平台)。为了允许玩家对象站在平台之上,你必须像检测地面碰撞一样,检测玩家对象与平台对象之间的碰撞。将如下代码放于你的 **update** 方法中:
目前你已经定义了在玩家精灵摔落地面时的抵抗重力条件,但此时你的游戏代码仍保持平台与地面置于不同的列表中(就像本文中做的很多其他选择一样,这个设定并不是必需的,你可以尝试将地面作为另一种平台)。为了允许玩家精灵站在平台之上,你必须像检测地面碰撞一样,检测玩家精灵与平台精灵之间的碰撞。将如下代码放于你的 `update` 方法中:
```
        plat_hit_list = pygame.sprite.spritecollide(self, plat_list, False)
@ -103,27 +99,26 @@
但此处还有一点需要考虑:平台悬在空中,也就意味着玩家可以通过从上面或者从下面接触平台来与之互动。
确定平台如何与玩家互动取决于你,阻止玩家从下方到达平台也并不稀奇。将如下代码加到上方的代码块中,使得平台表现得像天花板或者说是藤架。只有在玩家对象跳得比平台上沿更高时才能跳到平台上,但会阻止玩家从平台下方跳上来:
确定平台如何与玩家互动取决于你,阻止玩家从下方到达平台也并不稀奇。将如下代码加到上方的代码块中,使得平台表现得像天花板或者说是藤架。只有在玩家精灵跳得比平台上沿更高时才能跳到平台上,但会阻止玩家从平台下方跳上来:
```
            if self.rect.y &gt; p.rect.y:
            if self.rect.y > p.rect.y:
                self.rect.y = p.rect.y+ty
            else:
                self.rect.y = p.rect.y-ty
```
此处 **if** 语句代码块的第一个子句阻止玩家对象从平台正下方跳到平台上。如果它检测到玩家对象的坐标比平台更大(在 Pygame 中,坐标更大意味着在屏幕的更下方),那么将玩家对象新的 Y 坐标设置为当前平台的 Y 坐标加上一个瓷贴的高度。实际效果就是保证玩家对象距离平台一个瓷贴的高度,防止其从下方穿过平台。
此处 `if` 语句代码块的第一个子句阻止玩家精灵从平台正下方跳到平台上。如果它检测到玩家精灵的坐标比平台更大(在 Pygame 中,坐标更大意味着在屏幕的更下方),那么将玩家精灵新的 Y 坐标设置为当前平台的 Y 坐标加上一个瓷砖的高度。实际效果就是保证玩家精灵距离平台一个瓷砖的高度,防止其从下方穿过平台。
**else** 子句做了相反的事情。当程序运行到此处时,如果玩家对象的 Y 坐标_不_比平台的更大意味着玩家对象是从空中落下(不论是由于玩家刚刚从此处生成,或者是玩家执行了跳跃)。在这种情况下,玩家对象的 Y 坐标被设为平台的 Y 坐标减去一个瓷贴的高度(切记,在 Pygame 中更小的 Y 坐标代表在屏幕上的更高处)。这样就能保证玩家在平台_上_,除非他从平台上跳下来或者走下来。
`else` 子句做了相反的事情。当程序运行到此处时,如果玩家精灵的 Y 坐标*不*比平台的更大,意味着玩家精灵是从空中落下(不论是由于玩家刚刚从此处生成,或者是玩家执行了跳跃)。在这种情况下,玩家精灵的 Y 坐标被设为平台的 Y 坐标减去一个瓷砖的高度(切记,在 Pygame 中更小的 Y 坐标代表在屏幕上的更高处)。这样就能保证玩家在平台*上*,除非他从平台上跳下来或者走下来。
你也可以尝试其他的方式来处理玩家与平台之间的互动。举个栗子,也许玩家对象被设定为处在平台的“前面”,他能够无障碍地跳跃穿过平台并站在上面。或者你可以设计一种平台会减缓而又不完全阻止玩家的跳跃过程。甚至你可以通过将不同平台分到不同列表中来混合搭配使用。
你也可以尝试其他的方式来处理玩家与平台之间的互动。举个栗子,也许玩家精灵被设定为处在平台的“前面”,他能够无障碍地跳跃穿过平台并站在上面。或者你可以设计一种平台会减缓而又不完全阻止玩家的跳跃过程。甚至你可以通过将不同平台分到不同列表中来混合搭配使用。
### 触发一次跳跃
目前为此,你的代码已经模拟了所有必需的跳跃条件,但仍缺少一个跳跃触发器。你的玩家对象的 **self.jump_delta** 初始值被设置为 6只有当它比 6 小时才会触发更新跳跃的代码。
目前为此,你的代码已经模拟了所有必需的跳跃条件,但仍缺少一个跳跃触发器。你的玩家精灵的 `self.jump_delta` 初始值被设置为 6只有当它比 6 小才会触发更新跳跃的代码。
为跳跃变量设置一个新的设置方法,在你的 **Player** 类中创建一个 **jump** 方法,并将 **self.jump_delta** 设为小于 6 的值。通过使玩家对象向空中移动 33 个像素,来暂时减缓重力的作用。
为跳跃变量设置一个新的设置方法,在你的 `Player` 类中创建一个 `jump` 方法,并将 `self.jump_delta` 设为小于 6 的值。通过使玩家精灵向空中移动 33 个像素,来暂时减缓重力的作用。
```
@ -131,25 +126,24 @@
        self.jump_delta = 0
```
不管你相信与否,这就是 **jump** 方法的全部。剩余的部分在 **update** 方法中,你已经在前面实现了相关代码。
不管你相信与否,这就是 `jump` 方法的全部。剩余的部分在 `update` 方法中,你已经在前面实现了相关代码。
要使你游戏中的跳跃功能生效,还有最后一件事情要做。如果你想不起来是什么,运行游戏并观察跳跃是如何生效的。
问题就在于你的主循环中没有调用 **jump** 方法。先前你已经为该方法创建了一个按键占位符,现在,跳跃键所做的就是将 **jump** 打印到终端。
问题就在于你的主循环中没有调用 `jump` 方法。先前你已经为该方法创建了一个按键占位符,现在,跳跃键所做的就是将 `jump` 打印到终端。
### 调用 jump 方法
在你的主循环中将_上_方向键的效果从打印一条调试语句改为调用 **jump** 方法。
注意此处,与 **update** 方法类似,**jump** 方法也需要检测碰撞,因此你需要告诉它使用哪个 **plat_list**
在你的主循环中,将*上*方向键的效果从打印一条调试语句,改为调用 `jump` 方法。
注意此处,与 `update` 方法类似,`jump` 方法也需要检测碰撞,因此你需要告诉它使用哪个 `plat_list`
```
            if event.key == pygame.K_UP or event.key == ord('w'):
                player.jump(plat_list)
```
如果你倾向于使用空格键作为跳跃键,使用 **pygame.K_SPACE** 替代 **pygame.K_UP** 作为按键。另一种选择,你可以同时使用两种方式(使用单独的 **if** 语句),给玩家多一种选择。
如果你倾向于使用空格键作为跳跃键,使用 `pygame.K_SPACE` 替代 `pygame.K_UP` 作为按键。另一种选择,你可以同时使用两种方式(使用单独的 `if` 语句),给玩家多一种选择。
现在来尝试你的游戏吧!在下一篇文章中,你将让你的游戏卷动起来。
@ -157,7 +151,6 @@
以下是目前为止的所有代码:
```
#!/usr/bin/env python3
# draw a world
@ -220,7 +213,7 @@ class Player(pygame.sprite.Sprite):
    def gravity(self):
        self.movey += 3.2 # how fast player falls
       
        if self.rect.y &gt; worldy and self.movey &gt;= 0:
        if self.rect.y > worldy and self.movey >= 0:
            self.movey = 0
            self.rect.y = worldy-ty
       
@ -233,23 +226,23 @@ class Player(pygame.sprite.Sprite):
       
    def update(self):
        '''
        更新对象位置
        更新精灵位置
        '''
       
        self.rect.x = self.rect.x + self.movex
        self.rect.y = self.rect.y + self.movey
        # 向左移动
        if self.movex &lt; 0:
        if self.movex < 0:
            self.frame += 1
            if self.frame &gt; ani*3:
            if self.frame > ani*3:
                self.frame = 0
            self.image = self.images[self.frame//ani]
        # 向右移动
        if self.movex &gt; 0:
        if self.movex > 0:
            self.frame += 1
            if self.frame &gt; ani*3:
            if self.frame > ani*3:
                self.frame = 0
            self.image = self.images[(self.frame//ani)+4]
@ -263,7 +256,7 @@ class Player(pygame.sprite.Sprite):
        for p in plat_hit_list:
            self.collide_delta = 0 # stop jumping
            self.movey = 0
            if self.rect.y &gt; p.rect.y:
            if self.rect.y > p.rect.y:
                self.rect.y = p.rect.y+ty
            else:
                self.rect.y = p.rect.y-ty
@ -273,11 +266,11 @@ class Player(pygame.sprite.Sprite):
            self.movey = 0
            self.rect.y = worldy-ty-ty
            self.collide_delta = 0 # stop jumping
            if self.rect.y &gt; g.rect.y:
            if self.rect.y > g.rect.y:
                self.health -=1
                print(self.health)
               
        if self.collide_delta &lt; 6 and self.jump_delta &lt; 6:
        if self.collide_delta < 6 and self.jump_delta < 6:
            self.jump_delta = 6*2
            self.movey -= 33  # how high to jump
            self.collide_delta += 6
@ -308,22 +301,22 @@ class Enemy(pygame.sprite.Sprite):
        self.movey += 3.2
       
        if self.counter &gt;= 0 and self.counter &lt;= distance:
        if self.counter >= 0 and self.counter <= distance:
            self.rect.x += speed
        elif self.counter &gt;= distance and self.counter &lt;= distance*2:
        elif self.counter >= distance and self.counter <= distance*2:
            self.rect.x -= speed
        else:
            self.counter = 0
       
        self.counter += 1
        if not self.rect.y &gt;= worldy-ty-ty:
        if not self.rect.y >= worldy-ty-ty:
            self.rect.y += self.movey
        plat_hit_list = pygame.sprite.spritecollide(self, plat_list, False)
        for p in plat_hit_list:
            self.movey = 0
            if self.rect.y &gt; p.rect.y:
            if self.rect.y > p.rect.y:
                self.rect.y = p.rect.y+ty
            else:
                self.rect.y = p.rect.y-ty
@ -352,7 +345,7 @@ class Level():
        ground_list = pygame.sprite.Group()
        i=0
        if lvl == 1:
            while i &lt; len(gloc):
            while i < len(gloc):
                ground = Platform(gloc[i],worldy-ty,tx,ty,'ground.png')
                ground_list.add(ground)
                i=i+1
@ -371,9 +364,9 @@ class Level():
            ploc.append((300,worldy-ty-256,3))
            ploc.append((500,worldy-ty-128,4))
            while i &lt; len(ploc):
            while i < len(ploc):
                j=0
                while j &lt;= ploc[i][2]:
                while j <= ploc[i][2]:
                    plat = Platform((ploc[i][0]+(j*tx)),ploc[i][1],tx,ty,'ground.png')
                    plat_list.add(plat)
                    j=j+1
@ -417,11 +410,11 @@ eloc = []
eloc = [200,20]
gloc = []
#gloc = [0,630,64,630,128,630,192,630,256,630,320,630,384,630]
tx = 64 # 瓷尺寸
ty = 64 # 瓷尺寸
tx = 64 # 瓷尺寸
ty = 64 # 瓷尺寸
i=0
while i &lt;= (worldx/tx)+tx:
while i <= (worldx/tx)+tx:
    gloc.append(i*tx)
    i=i+1
@ -482,9 +475,8 @@ while main == True:
* [如何在你的 Python 游戏中添加一个玩家][8]
* [用 Pygame 使你的游戏角色移动起来][9]
* [如何向你的 Python 游戏中添加一个敌人][10]
* [在你的 Python 游戏中模拟重力][2]
* [在 Pygame 游戏中放置平台][11]
* [在你的 Python 游戏中模拟引力][2]
--------------------------------------------------------------------------------
@ -493,19 +485,20 @@ via: https://opensource.com/article/19/12/jumping-python-platformer-game
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[cycoe](https://github.com/cycoe)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/arcade_game_gaming.jpg?itok=84Rjk_32 (Arcade games)
[2]: https://opensource.com/article/19/11/simulate-gravity-python
[2]: https://linux.cn/article-11780-1.html
[3]: https://opensource.com/sites/default/files/uploads/pygame-jump.jpg (Pygame platformer)
[4]: https://www.python.org/
[5]: https://www.pygame.org/
[6]: https://opensource.com/article/17/10/python-101
[7]: https://opensource.com/article/17/12/game-framework-python
[8]: https://opensource.com/article/17/12/game-python-add-a-player
[9]: https://opensource.com/article/17/12/game-python-moving-player
[10]: https://opensource.com/article/18/5/pygame-enemy
[6]: https://linux.cn/article-9071-1.html
[7]: https://linux.cn/article-10850-1.html
[8]: https://linux.cn/article-10858-1.html
[9]: https://linux.cn/article-10874-1.html
[10]: https://linux.cn/article-10883-1.html
[11]: https://linux.cn/article-10902-1.html

View File

@ -1,8 +1,8 @@
[#]: collector: (lujun9972)
[#]: translator: (chen-ni)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: reviewer: (wxy)
[#]: publisher: (wxy)
[#]: url: (https://linux.cn/article-11791-1.html)
[#]: subject: (Explained! Why Your Distribution Still Using an Outdated Linux Kernel?)
[#]: via: (https://itsfoss.com/why-distros-use-old-kernel/)
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
@ -10,7 +10,9 @@
为什么你的发行版仍然在使用“过时的”Linux 内核?
======
[检查一下你的系统所使用的 Linux 内核版本][1],你十有八九会发现,按照 Linux 内核官网提供的信息,该内核版本已经达到使用寿命终期了。
![](https://img.linux.net.cn/data/attachment/album/202001/16/225806jbqyacu3loolobae.png)
[检查一下你的系统所使用的 Linux 内核版本][1],你十有八九会发现,按照 Linux 内核官网提供的信息该内核版本已经达到使用寿命终期EOL了。
一个软件一旦达到了使用寿命终期,那么就意味着它再也不会得到 bug 修复和维护了。
@ -18,11 +20,11 @@
下面将逐一解答这些问题。
总结
上游内核维护与你的发行版的内核维护是两个不同的概念。
例如,根据 Linux 内核官网Linux 内核 4.15 版本可能已经达到使用寿命终期了,但是在 2023 年 4 月之前Ubuntu 18.04 长期维护版本将会继续使用这个版本,并通过向后移植安全补丁和修复 bug 来提供维护。
> **总结**
>
> 上游内核维护与你的发行版的内核维护是两个不同的概念。
>
> 例如,根据 Linux 内核官网Linux 内核 4.15 版本可能已经达到使用寿命终期了,但是在 2023 年 4 月之前Ubuntu 18.04 长期维护版本将会继续使用这个版本,并通过向后移植安全补丁和修复 bug 来提供维护。
### 检查 Linux 内核版本,以及是否达到使用寿命终期
@ -35,13 +37,11 @@ uname -r
我使用的是 Ubuntu 18.04,输出的 Linux 内核版本如下:
```
[email protected]:~$ uname -r
abhishek@itsfoss:~$ uname -r
5.0.0-37-generic
```
接下来,可以到 Linux 内核官网上看看哪些 Linux 内核版本仍然在维护状态。在网站主页上就可以看到相关信息。
[Linux 内核官网][2]
接下来,可以到 [Linux 内核官网][2]上看看哪些 Linux 内核版本仍然在维护状态。在网站主页上就可以看到相关信息。
你看到的内核版本状态应该类似于下图:
@ -53,7 +53,7 @@ uname -r
不幸的是Linux 内核的生命周期没有任何规律可循。不是说常规的内核稳定发布版可以得到 X 月的维护、长期维护版本LTS可以得到 Y 年的维护。没有这回事。
根据实际需求,可能会存在内核的多个 LTS 版本,其使用寿命终期各不相同。在[这个页面][5]上可以查到这些 LTS 版本的相关信息,包括推定的使用寿命终期。
根据实际需求,可能会存在内核的多个 LTS 版本,其使用寿命终期各不相同。在[这个页面][5]上可以查到这些 LTS 版本的相关信息,包括计划的使用寿命终期。
那么问题来了:既然 Linux 内核官网上明确表示 5.0 版本的内核已经达到了使用寿命终期Ubuntu 为什么还在提供这个内核版本呢?
@ -63,11 +63,11 @@ uname -r
你是否想过,为什么 Ubuntu/Debian/Fedora 等发行版被称为 Linux “发行版”?这是因为,它们“发行” Linux 内核。
这些发行版会对 Linux 内核进行不同的修改,并添加各种 GUI 元素(包括桌面环境显示服务器等)以及软件,然后再呈现给用户。
这些发行版会对 Linux 内核进行不同的修改,并添加各种 GUI 元素(包括桌面环境显示服务器等)以及软件,然后再呈现给用户。
按照通常的工作流Linux 发行版会选择一个内核,提供给其用户,然后在接下来的几个月、几年中,甚至是达到内核的使用寿命终期之后,仍然会继续使用该内核。
这样能够保障安全吗?其实是可以的,因为 _**发行版会通过向后移植全部的重要修补来维护内核**_
这样能够保障安全吗?其实是可以的,因为 **发行版会通过向后移植全部的重要修补来维护内核**。
换句话说,你的 Linux 发行版会确保 Linux 内核没有漏洞和 bug并且已经通过向后移植获得了重要的新特性。在“过时的旧版本 Linux 内核”上,其实有着数以千计的改动。
@ -83,13 +83,13 @@ uname -r
新的 Linux 内核稳定版本每隔 2 到 3 个月发布一次,有不少用户跃跃欲试。
实话说,除非有十分充分的理由,否则不应该使用最新版本的稳定内核。你使用的发行版并不会提供这个选项,你也不能指望通过在键盘上敲出“_sudo apt give-me-the-latest-stable-kernel_”解决问题。
实话说,除非有十分充分的理由,否则不应该使用最新版本的稳定内核。你使用的发行版并不会提供这个选项,你也不能指望通过在键盘上敲出 `sudo apt give-me-the-latest-stable-kernel` 解决问题。
此外,手动[安装主流 Linux 内核版本][8]本身就是一个挑战。即使安装成功,之后每次发布 bug 修复的时候,负责更新内核的就会是你了。此外,当新内核达到使用寿命终期之后,你就有责任将它升级到更新的内核版本了。和常规的[Ubuntu 更新][9]不同,内核升级无法通过 apt upgrade 完成。
此外,手动[安装主流 Linux 内核版本][8]本身就是一个挑战。即使安装成功,之后每次发布 bug 修复的时候,负责更新内核的就会是你了。此外,当新内核达到使用寿命终期之后,你就有责任将它升级到更新的内核版本了。和常规的 [Ubuntu 更新][9]不同,内核升级无法通过 `apt upgrade` 完成。
同样需要记住的是,切换到主流内核之后,可能就无法使用你的发行版提供的一些驱动程序和补丁了。
正如 [Greg Kroah-Hartman][10]所言,“_**你能使用的最好的内核,就是别人在维护的内核。**_”除了你的 Linux 发行版之外,又有谁更胜任这份工作呢!
正如 [Greg Kroah-Hartman][10]所言,“**你能使用的最好的内核,就是别人在维护的内核。**”除了你的 Linux 发行版之外,又有谁更胜任这份工作呢!
希望你对这个主题已经有了更好的理解。下回发现你的系统正在使用的内核版本已经达到使用寿命终期的时候,希望你不会感到惊慌失措。
@ -102,7 +102,7 @@ via: https://itsfoss.com/why-distros-use-old-kernel/
作者:[Abhishek Prakash][a]
选题:[lujun9972][b]
译者:[chen-ni](https://github.com/chen-ni)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -0,0 +1,174 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Insights into Why Hyperbola GNU/Linux is Turning into Hyperbola BSD)
[#]: via: (https://itsfoss.com/hyperbola-linux-bsd/)
[#]: author: (John Paul https://itsfoss.com/author/john/)
Insights into Why Hyperbola GNU/Linux is Turning into Hyperbola BSD
======
In late December 2019, [Hyperbola][1] [announced][2] that they would be making major changes to their project. They have decided to drop the Linux kernel in favor of forking the OpenBSD kernel. This announcement only came months after Project Trident [announced][3] that they were going in the opposite direction (from BSD to Linux).
Hyperbola also plans to replace all software that is not GPL v3 compliant with new versions that are.
To get more insight into the future of their new project, I interviewed **Andre, co-founder of Hyperbola**.
### Why Hyperbola GNU/Linux Turned into Hyperbola BSD
![][4]
_**Its FOSS: In your announcement, you state that the Linux kernel is “rapidly proceeding down an unstable path”. Could you explain what you mean by that?**_
**Andre:** First of all, its including the adaption of DRM features such as [HDCP][5] (High-bandwidth Digital Content Protection). Currently there is an option to disable it at build time, however there isnt a policy that guarantees us that it will be optional forever.
Historically, some features began as optional ones until they reached total functionality. Then they became forced and difficult to patch out. Even if this does not happen in the case of HDCP, we remain cautious about such implementations.
Another of the reasons is that the _**Linux kernel is no longer getting proper hardening**_. [Grsecurity][6] stopped offering public patches several years ago, and we depended on that for our systems security. Although we could use their patches still for a very expensive subscription, the subscription would be terminated if we chose to make those patches public.
Such restrictions goes against the FSDG principles that require us to provide full source code, deblobbed, and unrestricted, to our users.
KSPP is a project that was intended to upstream Grsec into the kernel, but thus far it has not come close to reaching Grsec / PaX level of kernel hardening. There also has not been many recent developments, which leads us to believe it is now an inactive project for the most part.
Lastly, the interest in [allowing Rust modules][7] into the kernel are a problem for us, due to Rust trademark restrictions which prevent us from applying patches in our distribution without express permission. We patch to remove non-free software, unlicensed files, and enhancements to user-privacy anywhere it is applicable. We also expect our users to be able to re-use our code without any additional restrictions or permission required.
This is also in part why we use UXP, a fully free browser engine and application toolkit without Rust, for our mail and browser applications.
Due to these restrictions, and the concern that it may at some point become a forced build-time dependency for the kernel we needed another option.
_**Its FOSS: You also said in the announcement that you would be forking the OpenBSD kernel. Why did you pick the OpenBSD kennel over the FreeBSD, the DragonflyBSD kernel or the MidnightBSD kernel?**_
**Andre:** [OpenBSD][8] was chosen as our base for hard-forking because its a system that has always had quality code and security in mind.
Some of their ideas which greatly interested us were new system calls, including pledge and unveil which adds additional hardening to userspace and the removal of the systrace system policy-enforcement tool.
They also are known for [Xenocara][9] and [LibreSSL][10], both of which we had already been using after porting them to [GNU/Linux-libre][11]. We found them to be well written and generally more stable than Xorg/OpenSSL respectively.
None of the other BSD implementations we are aware of have that level of security. We also were aware [LibertyBSD][12] has been working on liberating the OpenBSD kernel, which allowed us to use their patches to begin the initial development.
_**Its FOSS: Why fork the kernel in the first place? How will you keep the new kernel up-to-date with newer hardware support?**_
**Andre:** The kernel is one of the most important parts of any operating system, and we felt it is critical to start on a firm foundation moving forward.
For the first version we plan to keep in synchronization with OpenBSD where it is possible. In future versions we may adapt code from other BSDs and even the Linux kernel where needed to keep up with hardware support and features.
We are working in coordination with [Libreware Group][13] (our representative for business activities) and have plans to open our foundation soon.
This will help to sustain development, hire future developers and encourage new enthusiasts for newer hardware support and code. We know that deblobbing isnt enough because its a mitigation, not a solution for us. So, for that reason, we need to improve our structure and go to the next stage of development for our projects.
_**Its FOSS: You state that you plan to replace the parts of the OpenBSD kernel and userspace that are not GPL compatible or non-free with those that are. What percentage of the code falls into the non-GPL zone?**_
**Andre:** Its around 20% in the OpenBSD kernel and userspace.
Mostly, the non-GPL compatible licensed parts are under the Original BSD license, sometimes called the “4-clause BSD license” that contains a serious flaw: the “obnoxious BSD advertising clause”. It isnt fatal, but it does cause practical problems for us because it generates incompatibility with our code and future development under GPLv3 and LGPLv3.
The non-free files in OpenBSD include files without an appropriate license header, or without a license in the folder containing a particular component.
If those files dont contain a license to give users the four essential freedoms or if it has not been explicitly added in the public domain, it isnt free software. Some developers think that code without a license is automatically in the public domain. That isnt true under todays copyright law; rather, all copyrightable works are copyrighted by default.
The non-free firmware blobs in OpenBSD include various hardware firmwares. These firmware blobs occur in Linux kernel also and have been manually removed by the Linux-libre project for years following each new kernel release.
They are typically in the form of a hex encoded binary and are provided to kernel developers without source in order to provide support for proprietary-designed hardware. These blobs may contain vulnerabilities or backdoors in addition to violating your freedom, but no one would know since the source code is not available for them. They must be removed to respect user freedom.
_**Its FOSS: I was talking with someone about HyperbolaBSD and they mentioned [HardenedBSD][14]. Have you considered HardenedBSD?**_
**Andre:** We had looked into HardenedBSD, but it was forked from FreeBSD. FreeBSD has a much larger codebase. While HardenedBSD is likely a good project, it would require much more effort for us to deblob and verify licenses of all files.
We decided to use OpenBSD as a base to fork from instead of FreeBSD due to their past commitment to code quality, security, and minimalism.
_**Its FOSS: You mentioned UXP (or [Unified XUL Platform][15]). It appears that you are using [Moonchilds fork of the pre-Servo Mozilla codebase][16] to create a suite of applications for the web. Is that about the size of it?**_
**Andre:** Yes. Our decision to use UXP was for several reasons. We were already rebranding Firefox as Iceweasel for several years to remove DRM, disable telemetry, and apply preset privacy options. However, it became harder and harder for us to maintain when Mozilla kept adding anti-features, removing user customization, and rapidly breaking our rebranding and privacy patches.
After FF52, all XUL extensions were removed in favor of WebExt and Rust became enforced at compile time. We maintain several XUL addons to enhance user-privacy/security which would no longer work in the new engine. We also were concerned that the feature limited WebExt addons were introducing additional privacy issues. E.g. each installed WebExt addon contains a UUID which can be used to uniquely and precisely identify users (see [Bugzilla 1372288][17]).
After some research, we discovered UXP and that it was regularly keeping up with security fixes without rushing to implement new features. They had already disabled telemetry in the toolkit and remain committed to deleting all of it from the codebase.
We knew this was well-aligned with our goals, but still needed to apply a few patches to tweak privacy settings and remove DRM. Hence, we started creating our own applications on top of the toolkit.
This has allowed us to go far beyond basic rebranding/deblobbing as we were doing before and create our own fully customized XUL applications. We currently maintain [Iceweasel-UXP][18], [Icedove-UXP][19] and [Iceape-UXP][20] in addition to sharing toolkit improvements back to UXP.
_**Its FOSS: In a [forum post][21], I noticed mentions of HyperRC, HyperBLibC, and hyperman. Are these forks or rewrites of current BSD tools to be GPL compliant?**_
**Andre:** They are forks of existing projects.
Hyperman is a fork of our current package manager, pacman. As pacman does not currently work on BSD, and the minimal support it had in the past was removed in recent versions, a fork was required. Hyperman already has a working implementation using LibreSSL and BSD support.
HyperRC will be a patched version of OpenRC init. HyperBLibC will be a fork from BSD LibC.
_**Its FOSS: Since the beginning of time, Linux has championed the GPL license and BSD has championed the BSD license. Now, you are working to create a BSD that is GPL licensed. How would you respond to those in the BSD community who dont agree with this move?**_
**Andre:** We are aware that there are disagreements between the GPL and BSD world. There are even disagreements over calling our previous distribution “GNU/Linux” rather than simply “Linux”, since the latter definition ignores that the GNU userspace was created in 1984, several years prior to the Linux kernel being created by Linus Torvalds. It was the two different software combined that make a complete system.
Some of the primary differences from BSD, is that the GPL requires that our source code must be made public, including future versions, and that it can only be used in tandem with compatibly licensed files. BSD systems do not have to share their source code publicly, and may bundle themselves with various licenses and non-free software without restriction.
Since we are strong supporters of the Free Software Movement and wish that our future code remain in the public space always, we chose the GPL.
_**Its FOSS: I know at this point you are just starting the process, but do you have any idea who you might have a usable version of HyperbolaBSD available?**_
**Andre:** We expect to have an alpha release ready by 2021 (Q3) for initial testing.
_**Its FOSS: How long will you continue to support the current Linux version of Hyperbola? Will it be easy for current users to switch over to**_?
**Andre:** As per our announcement, we will continue to support Hyperbola GNU/Linux-libre until 2022 (Q4). We expect there to be some difficulty in migration due to ABI changes, but will prepare an announcement and information on our wiki once it is ready.
_**Its FOSS: If someone is interested in helping you work on HyperbolaBSD, how can they go about doing that? What kind of expertise would you be looking for?**_
**Andre:** Anyone who is interested and able to learn is welcome. We need C programmers and users who are interested in improving security and privacy in software. Developers need to follow the FSDG principles of free software development, as well as the YAGNI principle which means we will implement new features only as we need them.
Users can fork our git repository and submit patches to us for inclusion.
_**Its FOSS: Do you have any plans to support ZFS? What filesystems will you support?**_
**Andre:** [ZFS][22] support is not currently planned, because it uses the Common Development and Distribution License, version 1.0 (CDDL). This license is incompatible with all versions of the GNU General Public License (GPL).
It would be possible to write new code under GPLv3 and release it under a new name (eg. HyperZFS), however there is no official decision to include ZFS compatibility code in HyperbolaBSD at this time.
We have plans on porting BTRFS, JFS2, NetBSDs CHFS, DragonFlyBSDs HAMMER/HAMMER2 and the Linux kernels JFFS2, all of which have licenses compatible with GPLv3. Long term, we may also support Ext4, F2FS, ReiserFS and Reiser4, but they will need to be rewritten due to being licensed exclusively under GPLv2, which does not allow use with GPLv3. All of these file systems will require development and stability testing, so they will be in later HyperbolaBSD releases and not for our initial stable version(s).
* * *
I would like to thank Andre for taking the time to answer my questions and for revealing more about the future of HyperbolaBSD.
What are your thoughts on Hyperbola switching to a BSD kernel? What do you think about a BSD being released under the GPL? Please let us know in the comments below.
If you found this article interesting, please take a minute to share it on social media, Hacker News or [Reddit][23].
--------------------------------------------------------------------------------
via: https://itsfoss.com/hyperbola-linux-bsd/
作者:[John Paul][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/john/
[b]: https://github.com/lujun9972
[1]: https://www.hyperbola.info/
[2]: https://www.hyperbola.info/news/announcing-hyperbolabsd-roadmap/
[3]: https://itsfoss.com/bsd-project-trident-linux/
[4]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/01/hyperbola_linux_bsd.png?ssl=1
[5]: https://patchwork.kernel.org/patch/10084131/
[6]: https://grsecurity.net/
[7]: https://lwn.net/Articles/797828/
[8]: https://www.openbsd.org/
[9]: https://www.xenocara.org/
[10]: https://www.libressl.org/
[11]: https://en.wikipedia.org/wiki/Linux-libre
[12]: https://libertybsd.net/
[13]: https://en.libreware.info/
[14]: https://hardenedbsd.org/
[15]: http://thereisonlyxul.org/
[16]: https://github.com/MoonchildProductions/UXP
[17]: https://bugzilla.mozilla.org/show_bug.cgi?id=1372288
[18]: https://wiki.hyperbola.info/doku.php?id=en:project:iceweasel-uxp
[19]: https://wiki.hyperbola.info/doku.php?id=en:project:icedove-uxp
[20]: https://wiki.hyperbola.info/doku.php?id=en:project:iceape-uxp
[21]: https://forums.hyperbola.info/viewtopic.php?id=315
[22]: https://itsfoss.com/what-is-zfs/
[23]: https://reddit.com/r/linuxusersgroup

View File

@ -1,139 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (robsean)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How to Add Border Around Text in GIMP)
[#]: via: (https://itsfoss.com/gimp-text-outline/)
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
How to Add Border Around Text in GIMP
======
This simple tutorial explains the steps to outline text in [GIMP][1]. The text outline helps you highlight text against background of other color.
![Outlined Text created in GIMP][2]
Lets see how can you add a border around your text.
### Adding text outline in GIMP
The entire procedure can be described in these easy steps:
* Create your text and copy its outlined path
* Add a new transparent layer and add the outlined path to this layer
* Change the size of the outline, add a different color to it
Thats all. Dont worry, I am going to show each steps in detail with proper screenshots. By following this tutorial, you should be able to add outline to text even if you never used GIMP before.
Just make sure that you have [GIMP installed on Linux][3] or whatever operating system you are using.
This tutorial has been performed with GIMP 2.10 version.
#### Step 1: Create your primary text and copy its outline
Open GIMP and create a new file by going to the top menu-&gt;File-&gt;New. You can also use Ctrl+N keyboard shortcut.
![Create New File][4]
You can select the size of your canvas here. You may also choose if you want white background or a transparent background. It is under the Advanced Options-&gt;Color profile.
I have chosen the default white background. It can be changed later.
Now select the Text tool from the toolbox in the left sidebar.
![Adding text in GIMP][5]
Write the text you want. You can change the font, size and alignment of the text as per your choice. I have kept the default left alignment of the text for this article.
I have deliberately chose a light color for the text so that it is difficult to read. Ill add a darker outline to this light text in this tutorial.
![Text added in GIMP][6]
When you are done writing your text, right click the text box and select **Path from Text**.
![Right click on the text box and select Path from Text][7]
#### Step 2: Add a transparent layer with the text outline
Now, go to the top menu, go to Layer and add a new layer.
![Use Shift+Ctrl+N to add a new layer][8]
Make sure to add the new layer as transparent. You can give it a suitable name like outline for text. Click OK to add this transparent layer.
![Add a transparent layer][9]
Go to the menu again and this time go to **Select** and click **From path**. Youll see that your text has been highlighted.
![Go to Select and choose From Path][10]
Basically, you just created a transparent layer that has the same text (but transparent) as your original text. What you need to do now is to increase the size of the text on this layer.
#### Step 3: Adding the text outline by increasing its size and changing its color
To do that, go to Select in menu once again and this time choose Grow. This will allow you to grow the size of the text on the transparent layer.
![Grow the selection on the additional layer][11]
Grow it by 5 or 10 pixel or whatever you prefer.
![Grow it by 5 or 10 pixel][12]
What you need to do now is to fill this enlarged selection with a choice of your color. Since my original text is of light color, I am going to use back color for the outline here.
**Select your main image layer** if its not already selected. The layers are visible at the right sidebar. Then go to the toolbox and select the bucket fill tool. Select the desired color you want for the outline.
Now use the tool to fill black color to your selection. Mind that you fill the outer outline of the text, not the text itself.
![Fill the outline of the text with a different color][13]
You are pretty much done here. Use Ctrl+Shift+A to de-select your current selection.
![Outline added to the text][14]
So now you have successfully added outline to your text in GIMP. It is on white background and if you want a transparent background, just delete the background layer from the layer menu in the right sidebar.
![Remove the white background layer if you want a transparent background][15]
If you are happy with the result, save the file as PNG file (to keep transparent background) or whichever file format you prefer.
**Did you make it work?**
Thats it. Thats all you need to do to add a text outline in GIMP.
I hope you find this GIMP tutorial helpful. You may want to check out another [simple tutorial about adding a watermark in GIMP][16].
If you have questions or suggestions, please feel free to leave a comment below.
--------------------------------------------------------------------------------
via: https://itsfoss.com/gimp-text-outline/
作者:[Abhishek Prakash][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/abhishek/
[b]: https://github.com/lujun9972
[1]: https://www.gimp.org/
[2]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2019/12/outlined_text_GIMP.png?ssl=1
[3]: https://itsfoss.com/gimp-2-10-release/
[4]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2019/12/create_outline_text_gimp_1.jpeg?ssl=1
[5]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2019/12/outline_text_gimp_2.jpg?ssl=1
[6]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2019/12/outline_text_gimp-3.jpg?ssl=1
[7]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2019/12/outline_text_gimp_4.jpg?ssl=1
[8]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2019/12/outline_text_gimp_5.jpg?ssl=1
[9]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2019/12/outline_text_gimp_6.jpg?ssl=1
[10]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2019/12/outline_text_gimp_7.jpg?ssl=1
[11]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2019/12/outline_text_gimp_8.jpg?ssl=1
[12]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2019/12/outline_text_gimp_9.jpg?ssl=1
[13]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2019/12/outline_text_gimp_10.jpg?ssl=1
[14]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2019/12/outline_text_gimp_11.jpg?ssl=1
[15]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2019/12/outline_text_gimp_12.jpg?ssl=1
[16]: https://itsfoss.com/add-watermark-gimp-linux/

View File

@ -1,79 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Keep your email in sync with OfflineIMAP)
[#]: via: (https://opensource.com/article/20/1/sync-email-offlineimap)
[#]: author: (Kevin Sonney https://opensource.com/users/ksonney)
Keep your email in sync with OfflineIMAP
======
Mirroring your email to a local folder is the first step in taming your
message pileup. Learn how in the third article in our series on 20 ways
to be more productive with open source in 2020.
![email or newsletters via inbox and browser][1]
Last year, I brought you 19 days of new (to you) productivity tools for 2019. This year, I'm taking a different approach: building an environment that will allow you to be more productive in the new year, using tools you may or may not already be using.
### Sync your email locally with OfflineIMAP
I have a love/hate relationship with email. I love the way it allows me to communicate with people all over the world. But, like many of you, I get a lot of mail, much of it from lists as well as spammers, advertisers, and the like. And it builds up.
![The OfflineIMAP "blinkenlights" UI][2]
Almost all the tools I've tried (outside of the big mail providers) that work really well with large amounts of mail have one thing in common: they all rely on a local copy of your mail stored in [Maildir][3] format. And the most useful tool for that is [OfflineIMAP][4]. OfflineIMAP is a Python script that mirrors IMAP mailboxes to a local Maildir folder tree. I use it to create a local copy of my mail and keep it in sync. Most Linux distributions include it, and it is available via Python's pip package manager.
The sample minimal configuration file is a good template to start with; begin by copying it to **~/.offlineimaprc**. Mine looks something like this:
```
[general]
accounts = LocalSync
ui=Quiet
autorefresh=30
[Account LocalSync]
localrepository = LocalMail
remoterepository = MirrorIMAP
[Repository MirrorIMAP]
type = IMAP
remotehost = my.mail.server
remoteuser = myusername
remotepass = mypassword
auth_mechanisms = LOGIN
createfolder = true
ssl = yes
sslcacertfile = OS-DEFAULT
[Repository LocalMail]
type = Maildir
localfolders = ~/Maildir
sep = .
createfolder = true
```
What my configuration does is define two repositories: the remote IMAP server and the local Maildir folder. There is also the **Account** that tells OfflineIMAP what to sync when it runs. You can define multiple accounts linked to different repositories. This allows you to copy from one IMAP server to another as a backup, in addition to making a copy locally.
The first run of OfflineIMAP will take a while if you have a lot of mail. But once it is done, future runs take a _lot_ less time. You can also run OfflineIMAP as a cron job (my preference) or as a daemon constantly syncing between repositories. The documentation covers all of this, as well as advanced configuration options for things like Gmail.
Now that my mail is copied locally, there is a whole range of tools I can work with to speed up searching, filing, and managing mail. And I'll talk about that tomorrow.
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/1/sync-email-offlineimap
作者:[Kevin Sonney][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/ksonney
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/newsletter_email_mail_web_browser.jpg?itok=Lo91H9UH (email or newsletters via inbox and browser)
[2]: https://opensource.com/sites/default/files/uploads/productivity_3-1.png (The OfflineIMAP "blinkenlights" UI)
[3]: https://en.wikipedia.org/wiki/Maildir
[4]: http://www.offlineimap.org/

View File

@ -1,5 +1,5 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )

View File

@ -0,0 +1,145 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (3 open source tools to manage your contacts)
[#]: via: (https://opensource.com/article/20/1/sync-contacts-locally)
[#]: author: (Kevin Sonney https://opensource.com/users/ksonney)
3 open source tools to manage your contacts
======
Access your contacts more quickly by syncing them locally. Learn how in
the sixth in our series on 20 ways to be more productive with open
source in 2020.
![Team communication, chat][1]
Last year, I brought you 19 days of new (to you) productivity tools for 2019. This year, I'm taking a different approach: building an environment that will allow you to be more productive in the new year, using tools you may or may not already be using.
### Open source tools for contact management
In previous articles in this series, I explained how to synchronize your [mail][2] and [calendars][3] locally. Hopefully, that has sped up accessing your mail and calendar. Now I'll talk about contacts, which you can use to send mail and calendar invites.
![abook][4]
I have collected a lot of email addresses over the course of my, well, life so far. And managing all that data can be a bit of a pain. There are web-based services, but they aren't as fast as a local copy.
A few days ago, I talked about [vdirsyncer][5] for managing calendars. Vdirsyncer also handles contacts using the CardDAV protocol. Vdirsyncer supports **google_contacts** and **carddav** to do contact synchronizations in addition to the **filesystem** store it uses for calendars, but the **fileext** setting will change, so you won't be trying to store contacts in calendar files.
I added a configuration block to the config file and mirrored my contacts from Google. Extra steps are required to set it up. Once the Google setup is complete, the configuration is pretty simple:
```
[pair address_sync]
a = "googlecard"
b = "localcard"
collections = ["from a", "from b"]
conflict_resolution = "a wins"
[storage googlecard]
type = "google_contacts"
token_file = "~/.vdirsyncer/google_token"
client_id = "my_client_id"
client_secret = "my_client_secret"
[storage localcard]
type = "filesystem"
path = "~/.calendars/Addresses/"
fileext = ".vcf"
```
Now when I run **vdirsyncer discover**, it finds my Google contacts, and **vdirsyncer sync** copies them to my local machine. But again, that's only half the story. Now I want to read and use the contacts. Enter [khard][6] and [abook][7].
![khard search][8]
Why two applications? Each has its own use case, and in this case, more is better. Khard does for addresses what [khal][9] does for calendar entries. You'll probably want to install the latest release via pip if your distribution ships an older version. Once khard is installed, you need to create **~/.config/khard/khard.conf** because khard doesn't have a nifty configuration wizard the way khal does. Mine looks like this:
```
[addressbooks]
[[addresses]]
path = ~/.calendars/Addresses/default/
[general]
debug = no
default_action = list
editor = vim, -i, NONE
merge_editor = vimdiff
[contact table]
display = first_name
group_by_addressbook = no
reverse = no
show_nicknames = yes
show_uids = no
sort = last_name
localize_dates = yes
[vcard]
preferred_version = 3.0
search_in_source_files = yes
skip_unparsable = no
```
This defines the source address book (and gives it a friendly name), as well as what to display and what do use to edit contacts. Running **khard list** will list all the entries, and **khard list &lt;[some@email.adr][10]&gt;** will search for a specific entry. If you want to add or edit an entry, the **add** and **edit** commands launch the configured editor with the same basic template, the only difference being that the **add** template will be blank.
![editing in khard][11]
Abook requires you to import and export VCF files but offers some nice features for lookups. To convert your files to the abook format, first install abook and create the **~/.abook** default directory. Now tell abook to parse all the files and put them into the **~/.abook/addresses** file:
```
apt install abook
ls ~/.calendars/Addresses/default/* | xargs cat | abook --convert --informat vcard --outformat abook &gt; ~/.abook/addresses
```
Now run **abook**, and you'll have a very nice UI to browse, search, and edit the entries. Exporting them back to individual entries is a bit of a pain, so I do most of my edits with khard and have a cron job to import them into abook.
Abook can also search on the command line and has a lot of documentation about integrating it with mail clients. For example, you can use abook for lookups in the [Notmuch][12] email client [alot][13] by adding some information to the **.config/alot/config** file:
```
[accounts]
  [[Personal]]
     realname = Kevin Sonney
     address = [kevin@sonney.com][14]
     alias_regexp = kevin\[+.+@sonney.com][15]
     gpg_key = 7BB612C9
     sendmail_command = msmtp --account=Personal -t
     # ~ expansion works
     sent_box = maildir://~/Maildir/Sent
     draft_box = maildir://~/Maildir/Drafts
    [[[abook]]]
        type = abook
```
And there you have it: fast lookup of your contacts to go with your mail and calendars!
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/1/sync-contacts-locally
作者:[Kevin Sonney][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/ksonney
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/talk_chat_team_mobile_desktop.png?itok=d7sRtKfQ (Team communication, chat)
[2]: https://opensource.com/article/20/1/sync-email-offlineimap
[3]: https://opensource.com/article/20/1/open-source-calendar
[4]: https://opensource.com/sites/default/files/uploads/productivity_6-1.png (abook)
[5]: https://github.com/pimutils/vdirsyncer
[6]: https://github.com/scheibler/khard
[7]: http://abook.sourceforge.net/
[8]: https://opensource.com/sites/default/files/uploads/productivity_6-2.png (khard search)
[9]: https://khal.readthedocs.io/en/v0.9.2/index.html
[10]: mailto:some@email.adr
[11]: https://opensource.com/sites/default/files/uploads/productivity_6-3.png (editing in khard)
[12]: https://opensource.com/article/20/1/organize-email-notmuch
[13]: https://github.com/pazz/alot
[14]: mailto:kevin@sonney.com
[15]: mailto:+.+@sonney.com

View File

@ -0,0 +1,139 @@
[#]: collector: (lujun9972)
[#]: translator: (robsean)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How to Add Border Around Text in GIMP)
[#]: via: (https://itsfoss.com/gimp-text-outline/)
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
在 GIMP 中如何在文本周围添加边框
======
这个简单的教程阐明了在 [GIMP][1] 中显示文本的轮廓的步骤。文本轮廓帮助你在其它颜色下高亮显示文本。
![Outlined Text created in GIMP][2]
让我们看看如何在你的文本周围添加一个边框。
### 在 GIMP 中添加文本轮廓
整个过程可以用这些简单的步骤描述:
* 创建文本,并复制它的轮廓路径
* 添加一层新的透明层,并添加轮廓路径到透明层中
* 更改轮廓的大小,给它添加一种不同的颜色
这就是全部的东西。不用担心,我将使用适当地截图详细的展示每个步骤。按照这个教程,你应该能够为文本添加轮廓,即使你在此之前从未使用过 GIMP 。
仅需要确保你已经 [在 Linux 上安装 GIMP][3] 或者你正在使用的任何操作。
这篇教程在 GIMP 2.10 版本下演示。
#### 步骤 1: 创建你的主要文本,并复制它的轮廓
打开 GIMP ,并通过转到 菜单 -> 文件 -> 新建 来创建一个新的文件。你应该可以使用 Ctrl+N 键盘快捷键。
![Create New File][4]
你可以在这里选择画布的大小。你也可以选择要白色背景或一种透明背景。它在 高级选项 -> 颜色 配置文件下。
我选择默认的白色背景。它在以后能够更改。
现在从左边栏的工具箱中选择文本工具。
![Adding text in GIMP][5]
写你想的文本。你可以根据你的选择以更改文本的字体,大小和对齐方式。我保持这篇文章的文本的默认左对齐。
我故意为文本选择一种浅色,以便难于阅读。在这篇教程中我将添加一个深色轮廓到这个浅色的文本。
![Text added in GIMP][6]
当你写完文本后,右键文本框并选择 **文本的路径**
![Right click on the text box and select Path from Text][7]
#### 步骤 2: 添加一个带有文本轮廓的透明层
现在,转到顶部菜单,转到 层 ,并添加一个新层。
![Use Shift+Ctrl+N to add a new layer][8]
确保添加新层为透明的。你可以给它一个合适的名称,像 ‘文本大纲’。单击确定来添加这个透明层。
![Add a transparent layer][9]
再次转到菜单,这次转到 **选择** ,并单击 **来自路径** 。你将看到你的文本应该被高亮显示。
![Go to Select and choose From Path][10]
总的来说,你只创建一个透明层,它有像你的原文一样相同的文本(但是透明)。现在你需要做的是在这个层上增加文本的大小。
#### 步骤· 3: 通过增加它的大小和更改它的颜色来添加文本轮廓
为此,再次在菜单中转到 选择 ,这次选择 增加。这将允许增大透明层上的文本的大小。
![Grow the selection on the additional layer][11]
以 5 或 10 像素增加,或者你喜欢的任意像素。
![Grow it by 5 or 10 pixel][12]
你选择需要做是使用一种你选择的颜色来填充这个扩大的选择区。因为我的原文是浅色,在这里我将为轮廓使用背景色。
如果尚未选择的话,先 **选择你的主图像层** 。这些层在右侧栏中可视。然后转到工具箱并选择油漆桶工具。为你的轮廓选择想要的颜色。
选择使用该工具来填充黑色到你的选择区。记住。你填充文本外部的轮廓,而不是文本本身。
![Fill the outline of the text with a different color][13]
在这里你完成了很多。使用 Ctrl+Shift+A 来取消你当前的选择区。
![Outline added to the text][14]
如此,你现在已经在 GIMP 中成功地添加轮廓到你的文本。它是在白色背景中,如果你想要一个透明背景,只需要在右侧栏的图层菜单中删除背景层。
![Remove the white background layer if you want a transparent background][15]
如果你对结果感到满意,保存文件未 PNG 文件(来保留透明背景),或你喜欢的任何文件格式。
**你使它工作了吗?**
就这样。这就是你在 GIMP 中为添加一个文本轮廓而需要做的全部工作。
我希望你发现这个 GIMP 教程有帮助。你可能想查看另一个 [关于在 GIMP 中添加一个水印的简单教程][16]。
如果你有问题或建议,请在下面自由留言。
--------------------------------------------------------------------------------
via: https://itsfoss.com/gimp-text-outline/
作者:[Abhishek Prakash][a]
选题:[lujun9972][b]
译者:[robsean](https://github.com/robsean)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/abhishek/
[b]: https://github.com/lujun9972
[1]: https://www.gimp.org/
[2]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2019/12/outlined_text_GIMP.png?ssl=1
[3]: https://itsfoss.com/gimp-2-10-release/
[4]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2019/12/create_outline_text_gimp_1.jpeg?ssl=1
[5]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2019/12/outline_text_gimp_2.jpg?ssl=1
[6]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2019/12/outline_text_gimp-3.jpg?ssl=1
[7]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2019/12/outline_text_gimp_4.jpg?ssl=1
[8]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2019/12/outline_text_gimp_5.jpg?ssl=1
[9]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2019/12/outline_text_gimp_6.jpg?ssl=1
[10]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2019/12/outline_text_gimp_7.jpg?ssl=1
[11]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2019/12/outline_text_gimp_8.jpg?ssl=1
[12]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2019/12/outline_text_gimp_9.jpg?ssl=1
[13]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2019/12/outline_text_gimp_10.jpg?ssl=1
[14]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2019/12/outline_text_gimp_11.jpg?ssl=1
[15]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2019/12/outline_text_gimp_12.jpg?ssl=1
[16]: https://itsfoss.com/add-watermark-gimp-linux/

View File

@ -0,0 +1,77 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Keep your email in sync with OfflineIMAP)
[#]: via: (https://opensource.com/article/20/1/sync-email-offlineimap)
[#]: author: (Kevin Sonney https://opensource.com/users/ksonney)
使用 OfflineIMAP 同步邮件
======
将邮件镜像保存到本地是整理消息的第一步。在我们的 20 个使用开源提升生产力的系列的第三篇文章中了解该如何做。
![email or newsletters via inbox and browser][1]
去年,我在 19 天里给你介绍了 19 个新(对你而言)的生产力工具。今年,我换了一种方式:使用你在使用或者还没使用的工具,构建一个使你可以在新一年更加高效的环境。
### 使用 OfflineIMAP 在本地同步你的邮件
我与邮件之间存在爱恨交织的关系。我喜欢它让我与世界各地的人交流的方式。但是,像你们中的许多人一样,我收到过很多邮件,许多是来自列表中的人,但也有很多垃圾邮件、广告等。这些积累了很多。
![The OfflineIMAP "blinkenlights" UI][2]
我尝试过的大多数工具(除了大型提供商外)都可以很好地处理大量邮件,它们都有一个共同点:它们都依赖于以 [Maildir][3] 格式存储的本地邮件副本。这其中最有用的是 [OfflineIMAP][4]。OfflineIMAP 是将 IMAP 邮箱镜像到本地 Maildir 文件夹树的 Python 脚本。我用它来创建邮件的本地副本并使其保持同步。大多数 Linux 发行版都包含它,并且可以通过 Python 的 pip 包管理器获得。
示例的最小配置文件是一个很好的模板。首先将其复制到 **~/.offlineimaprc**。我的看起来像这样:
```
[general]
accounts = LocalSync
ui=Quiet
autorefresh=30
[Account LocalSync]
localrepository = LocalMail
remoterepository = MirrorIMAP
[Repository MirrorIMAP]
type = IMAP
remotehost = my.mail.server
remoteuser = myusername
remotepass = mypassword
auth_mechanisms = LOGIN
createfolder = true
ssl = yes
sslcacertfile = OS-DEFAULT
[Repository LocalMail]
type = Maildir
localfolders = ~/Maildir
sep = .
createfolder = true
```
我的配置要做的是定义两个仓库:远程 IMAP 服务器和本地 Maildir 文件夹。还有一个**帐户**,告诉 OfflineIMAP 运行时要同步什么。你可以定义链接到不同仓库的多个帐户。除了本地复制外,这还允许你从一台 IMAP 服务器复制到另一台作为备份。
如果你有很多邮件,那么首次运行 OfflineIMAP 将花费一些时间。但是完成后下次会花_少得多_的时间。你也可以将 CoffeeIMAP 作为 cron 任务(我的偏好)或作为守护程序在仓库之间不断进行同步。文档涵盖了所有这些内容以及 Gmail 等高级配置选项。
现在,我的邮件已在本地复制,并有多种工具用来加快搜索、归档和管理邮件的速度。我明天再说。
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/1/sync-email-offlineimap
作者:[Kevin Sonney][a]
选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/ksonney
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/newsletter_email_mail_web_browser.jpg?itok=Lo91H9UH (email or newsletters via inbox and browser)
[2]: https://opensource.com/sites/default/files/uploads/productivity_3-1.png (The OfflineIMAP "blinkenlights" UI)
[3]: https://en.wikipedia.org/wiki/Maildir
[4]: http://www.offlineimap.org/